Hi;
Is there any SOP to rotate point Normals of a line (or surface) to 90 degrees?
Thanks for helping.
How can I rotate Normals to 90 degrees?
10396 7 1- Masoud
- Member
- 407 posts
- Joined: Aug. 2015
- Offline
- toadstorm
- Member
- 359 posts
- Joined: April 2017
- Offline
Yeah, you just need to define what axis you want to rotate 90 degrees around.
In this case, it looks like you want to rotate around an imaginary axis that's orthogonal to both the current normal itself, and the axis of the line. To get that orthogonal axis, you can take the cross product of N and the axis that defines the line: this would be normalize(P2-P1).
Then you'd create a matrix or quaternion to rotate the vector with. Quaternions have an easy constructor that take in an axis and angle to define the rotation, which is perfect. You'd convert 90 degrees to radians, then make a vector4 out of that angle/axis pair:
Finally, you'd rotate N by that quaternion and then bind the result to v@N:
So, the complete code:
In this case, it looks like you want to rotate around an imaginary axis that's orthogonal to both the current normal itself, and the axis of the line. To get that orthogonal axis, you can take the cross product of N and the axis that defines the line: this would be normalize(P2-P1).
Then you'd create a matrix or quaternion to rotate the vector with. Quaternions have an easy constructor that take in an axis and angle to define the rotation, which is perfect. You'd convert 90 degrees to radians, then make a vector4 out of that angle/axis pair:
vector4 q = quaternion(radians(90), axis);
Finally, you'd rotate N by that quaternion and then bind the result to v@N:
v@N = qrotate(q, v@N);
So, the complete code:
vector P2 = point(0, "P", @ptnum+1); vector axis = normalize(P2-@P); // look backwards if we're on the last point if(@ptnum == @numpt-1) { P2 = point(0, "P", @ptnum-1); axis = normalize(@P-P2); } // cross the axis with N to get the final axis. axis = cross(v@N, axis); vector4 q = quaternion(radians(90), axis); v@N = normalize(qrotate(q, v@N));
MOPs (Motion Operators for Houdini): http://www.motionoperators.com [www.motionoperators.com]
- tamte
- Member
- 8568 posts
- Joined: July 2007
- Offline
- vusta
- Member
- 555 posts
- Joined: Feb. 2017
- Offline
- vusta
- Member
- 555 posts
- Joined: Feb. 2017
- Offline
- Masoud
- Member
- 407 posts
- Joined: Aug. 2015
- Offline
- Masoud
- Member
- 407 posts
- Joined: Aug. 2015
- Offline
- Masoud
- Member
- 407 posts
- Joined: Aug. 2015
- Offline
-
- Quick Links