Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » 3D Rotation Script
- Hypnotron
-
Scratcher
100+ posts
3D Rotation Script
I'm working on a 3D wire-frame project, but I'm not sure how to represent 3D rotation.
NOTE: This post is just for X-ROTATION. If I can figure X, then Y and Z will be no problem.
If the 3D object rotates about the origin (0,0,0), then we can transform the origin into a “y-pole” about which the points will rotate (0, All Real Numbers, 0). Using sine, cosine, and tangent, we can rotate the points in a circle based on their neutral position.
For example, if a point is located at (1,0,0), during X-Rotation (where Y stays the same), the point at 90 degrees from its neutral position will be (0,0,1). 180 degrees gives you (-1,0,0), and 270 gives you (0,0,-1).
However, my problem is, how do you calculate rotation if the point of rotation is not (0, 0, 0), without moving the object to the origin, calculating, and moving it back?
That method would be very slow and tedious, and users with not-so-fast computers will keep seeing flashes as the points move back and forth. If possible, is there a formula to calculate counter-clockwise X-Rotation of point (A,B,C) about point (X,Y,Z)?
NOTE: This post is just for X-ROTATION. If I can figure X, then Y and Z will be no problem.
If the 3D object rotates about the origin (0,0,0), then we can transform the origin into a “y-pole” about which the points will rotate (0, All Real Numbers, 0). Using sine, cosine, and tangent, we can rotate the points in a circle based on their neutral position.
For example, if a point is located at (1,0,0), during X-Rotation (where Y stays the same), the point at 90 degrees from its neutral position will be (0,0,1). 180 degrees gives you (-1,0,0), and 270 gives you (0,0,-1).
However, my problem is, how do you calculate rotation if the point of rotation is not (0, 0, 0), without moving the object to the origin, calculating, and moving it back?
That method would be very slow and tedious, and users with not-so-fast computers will keep seeing flashes as the points move back and forth. If possible, is there a formula to calculate counter-clockwise X-Rotation of point (A,B,C) about point (X,Y,Z)?
- -stache-
-
Scratcher
500+ posts
3D Rotation Script
https://scratch.mit.edu/projects/134287095/
should help you
should help you
- gdpr533f604550b2f20900645890
-
Scratcher
1000+ posts
3D Rotation Script
Hi! 3D rotation is represented by a 3D rotation around each axis. You mentioned rotating around the “y pole,” but what do you mean by “X-rotation?” A rotation around the y-axis would affect both the x and z values. However, your rotation example is correct (and both x and z are changed).
The rotation matrices rotate around (0, 0, 0). However, you aren't supposed to literally move and render your points. Instead, the point's position is described in relation to its model, the world, then the camera. The point's original coordinates are relative to the model's center. Then, you apply the model's scale, rotation and translation to get its coordinates on the map. Next, you apply the opposite of the camera's translation, rotation, and scale to get the point's position relative to the viewer. Finally, you project the points onto the screen.
The rotation matrices rotate around (0, 0, 0). However, you aren't supposed to literally move and render your points. Instead, the point's position is described in relation to its model, the world, then the camera. The point's original coordinates are relative to the model's center. Then, you apply the model's scale, rotation and translation to get its coordinates on the map. Next, you apply the opposite of the camera's translation, rotation, and scale to get the point's position relative to the viewer. Finally, you project the points onto the screen.
- gtoal
-
Scratcher
1000+ posts
3D Rotation Script
I'm working on a 3D wire-frame project, but I'm not sure how to represent 3D rotation.
NOTE: This post is just for X-ROTATION. If I can figure X, then Y and Z will be no problem.
Wait till you come across “gimbal lock”… :-)
- gdpr533f604550b2f20900645890
-
Scratcher
1000+ posts
3D Rotation Script
I tried reading about quaternions, but didn't understand them.I'm working on a 3D wire-frame project, but I'm not sure how to represent 3D rotation.
NOTE: This post is just for X-ROTATION. If I can figure X, then Y and Z will be no problem.
Wait till you come across “gimbal lock”… :-)
- Discussion Forums
- » Advanced Topics
-
» 3D Rotation Script