Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Rotation Matrix
- ilikescratchprojects
- Scratcher
54 posts
Rotation Matrix
I recently was browsing through @theChAoTiC's code, and I keep finding this “translate” function. I know this is the rotation matrix, but could somebody explain to me how this function works and how to apply it? I know basic trigonometry and I understand sin, cos, and tan.
Last edited by ilikescratchprojects (Nov. 5, 2021 00:58:02)
- MathPuppy314
- Scratcher
500+ posts
Rotation Matrix
I don't know why they add 90 at the beginning, and I don't know why they choose to make both y values negative instead of just changing the sign, but the program works. It simply rotates a point around the origin. When the +90 is removed from the beginning, it is equivalent to this:
If you are familiar with the unit circle, this is just translating a point around it.
If you don't know what the unit circle is, here's a short explanation: If you drew a circle with radius 1 centered at the origin, you could find each point on that circle by using trig functions on its angle. The x value of that point would be cos(α) and the y value would be sin(α), where α is the angle.
The rotated x value is calculated by taking the cos of the angle multiplied by the magnitude of the x value, added to the sin of the angle multiplied by the y magnitude. Basically, the x location is calculated by using the cos of α with the x point and the sin of α with the y point.
The rotated y value is calculated the same way, but everything is opposite. To calculate the y value, you simply are using the inverse function of the x value. Imagine just swapping the x and y axis.
This method is a little bit counter-intuitive. It is the faster way rather than the easy-to-understand way.
The easy-to-understand method involves just taking a point, translating its (x, y) location to (r, θ), rotating it by changing θ, then translating back.
r means radius. r can be found using the Pythagorean Theorem with x and y in the place of a and b.
θ means angle. It can be found by using tan(y/x). It represents the same thing as α (just with a different term because math is hard).
Then translating (r, θ) back to (x,y), x=r*cos(θ) and y=r*sin(θ).
Hopefully this helped at least a little bit and made sense. If you need more help understanding something, I can try to elaborate more, because this is a somewhat abstract concept.
If you are familiar with the unit circle, this is just translating a point around it.
If you don't know what the unit circle is, here's a short explanation: If you drew a circle with radius 1 centered at the origin, you could find each point on that circle by using trig functions on its angle. The x value of that point would be cos(α) and the y value would be sin(α), where α is the angle.
The rotated x value is calculated by taking the cos of the angle multiplied by the magnitude of the x value, added to the sin of the angle multiplied by the y magnitude. Basically, the x location is calculated by using the cos of α with the x point and the sin of α with the y point.
The rotated y value is calculated the same way, but everything is opposite. To calculate the y value, you simply are using the inverse function of the x value. Imagine just swapping the x and y axis.
This method is a little bit counter-intuitive. It is the faster way rather than the easy-to-understand way.
The easy-to-understand method involves just taking a point, translating its (x, y) location to (r, θ), rotating it by changing θ, then translating back.
r means radius. r can be found using the Pythagorean Theorem with x and y in the place of a and b.
θ means angle. It can be found by using tan(y/x). It represents the same thing as α (just with a different term because math is hard).
Then translating (r, θ) back to (x,y), x=r*cos(θ) and y=r*sin(θ).
Hopefully this helped at least a little bit and made sense. If you need more help understanding something, I can try to elaborate more, because this is a somewhat abstract concept.
If only I were a kumquat…
- Discussion Forums
- » Help with Scripts
- » Rotation Matrix