How to use and rotate polar coordinates along the z-axis? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How to use and rotate polar coordinates along the z-axis?

I'm learning trigonometry in code. I know the rotate around a point, for the x-axis you use cos, for the y-axis you use sin. What about the z-axis? What if I wanted to rotate on both the z and x axis? Or y and z axis? How? x-axis = radius * cos(angle) y-axis = radius * sin(angle) z-axis = ?

23rd Jul 2020, 3:29 PM
Clueless Coder
Clueless Coder - avatar
6 Answers
+ 3
The simplest way to rotate points in 3D is to use the same math you do in 2D but apply them to different 2 dimensions. For example, you could rotate around the x-axis by rotating the y and z coordinates like you've learned to do with x and y in 2D. To rotate around the y axis, use the same math but with the 3D point's x and z coordinates. You could rotate around 1 axis and then by another. It can be helpful to represent your rotations as matrices. A matrix can represent multiple rotate operations, rotations around an arbitrary axis, and many other kinds of transformations. There is more detail on rotation matrices at: https://en.wikipedia.org/wiki/Rotation_matrix You commented on the 2D polar coordinate system so I wanted to point out a couple related 3D coordinate systems. The cylindrical coordinate system is basically a mixture of Cartesian in 1 dimension and polar in the other 2 dimensions. More detail at: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system The spherical coordinate system is basically the most complete 3D analogue of the 2D polar coordinates. It is a 3D direction similar to GPS coordinates on Earth with a radius. More detail at: https://en.wikipedia.org/wiki/Spherical_coordinate_system
23rd Jul 2020, 7:54 PM
Josh Greig
Josh Greig - avatar
+ 1
What would you implement? The golden ratio is a number like PI. The golden ratio is roughly 1.61803399 but the digits continue infinitely like PI. This is what my Windows calculator gets: 1.6180339887498948482045868343656 Are you asking how to calculate it? In JavaScript, you could calculate like this: (1 + Math.sqrt(5)) / 2 If you just want to save it somewhere in JavaScript, just copy it to a const and make it anywhere you want to use it.
24th Jul 2020, 12:26 PM
Josh Greig
Josh Greig - avatar
+ 1
Josh Greig Thanks. On the spherical coordinate system (I think it was that link) the formulas involved the phi symbol
24th Jul 2020, 12:27 PM
Clueless Coder
Clueless Coder - avatar
0
Josh Greig Thanks so much for the detailed response! I'll check them links in the morning.
23rd Jul 2020, 7:55 PM
Clueless Coder
Clueless Coder - avatar
0
Josh Greig A question, how do you implement the golden ratio? I did some research and it isn't in the Math object
24th Jul 2020, 8:29 AM
Clueless Coder
Clueless Coder - avatar
0
Mirielle Thanks for the example!
27th Jul 2020, 7:42 AM
Clueless Coder
Clueless Coder - avatar