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

172
Views
¿Cómo convierto coordenadas cartesianas en coordenadas esféricas y luego giro alrededor de un punto?

Estoy creando un programa en javascript que representa un mundo 3D en la pantalla 2D desde cero. Creé una función para calcular el valor x en la pantalla en la que se mostrará un punto 3d. También debe tener en cuenta el ángulo de la horizontal alrededor del cual se deben rotar los puntos. Para hacer esto, intenté convertir a coordenadas esféricas y luego agregar el ángulo x del espectador a uno de los valores. Por alguna razón distorsiona todo cuando no estás mirando a cero grados. Aquí está el código y aquí está el resultado de todo el programa: https://3d.napoleon1027.repl.co/ (En este momento está configurado para girar lentamente cada tres segundos, y puede moverse con las teclas de flecha/WSAD)

 function fx(x,y,z){ //calculates the x, y, and z values relative to your position z-=pz x-=px y-=py //converts the cartesian coordinates to spherical var r=Math.sqrt(x**2+y**2+z**2) var t=Math.acos(z/r) var f=Math.atan(y/x) if(x<0){ f+=Math.PI } //adds your angle to the angle of theta t+=xangle //converts the spherical coordinates back to cartesian x=r*Math.cos(f)*Math.sin(t) y=r*Math.sin(f)*Math.sin(t) z=r*Math.cos(t) //adds the player coordinates back z+=pz x+=px y+=py //returns the x value that this point should be drawn onto the screen at return (x-px)/(z-pz); }
about 4 years ago · Juan Pablo Isaza
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!