Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

130
Views
¿Cómo rotar un triángulo sobre su centro?
 document.onkeydown = function (event) { switch (event.keyCode) { case 74: //player presses "j" px = player.calculateCentreX(); py = player.calculateCentreY(); x1 = rotateX(player.x1,player.y1,35,px,py); x2 = rotateX(player.x2,player.y2,35,px,py); x3 = rotateX(player.x3,player.y3,35,px,py); y1 = rotateY(player.x1,player.y1,35,px,py); y2 = rotateY(player.x2,player.y2,35,px,py); y3 = rotateY(player.x3,player.y3,35,px,py); player.setPoints(x1,y1,x2,y2,x3,y3); break; default: break; } }; function rotateX(cx,cy,angle,px,py) { x = Math.cos(angle)*(px-cx) - Math.sin(angle)*(py-cy) + cx return x } function rotateY(cx,cy,angle,px,py) { y = Math.sin(angle)*(px-cx) + Math.cos(angle)*(py-cy) + cy return y }

Estoy usando lo anterior para tratar de rotar un triángulo (el jugador) sobre su centro cada vez que el usuario presiona "J". El método setPoints simplemente establece los valores de los triángulos x1,y1,x2,y2,x3,y3 en los puntos actualizados. Cada vez que el usuario presiona J, el triángulo gira pero crece en tamaño. ¿Alguien puede señalar qué está mal aquí?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Parece que está utilizando un orden de argumento incorrecto: la función se define con center, angle, point

 cx,cy, angle, px,py ^ ^ center point

pero lo llamas con point, angle, center

 px = player.calculateCentreX(); py = player.calculateCentreY(); x1 = rotateX(player.x1,player.y1, 35, px,py); !!!!! ^ ^ point center calculated above

Como resultado, el centro anterior gira alrededor de los vértices.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!