How can I rotate Normals to 90 degrees?

   10396   7   1
User Avatar
Member
407 posts
Joined: Aug. 2015
Offline
Hi;

Is there any SOP to rotate point Normals of a line (or surface) to 90 degrees?



Thanks for helping.

Attachments:
Normal rotation.jpg (151.7 KB)
Normal rotation.hip (80.1 KB)

Masoud Saadatmand (MSDVFX)
User Avatar
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:
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]
User Avatar
Member
8568 posts
Joined: July 2007
Offline
not sure what the purpose is, but you can also use Orientation Along Curve SOP, output X axis as N and play with Roll
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
555 posts
Joined: Feb. 2017
Offline
can i sheepishly ask why not blow away the polyframe

and wrangle @N = {1,0,0}; ?

I know it's a silly question to ask but couldn't resist.
(yes I know it won't work for a slanted line…but…just looking at this straight up line)
Edited by vusta - April 3, 2020 20:24:37
User Avatar
Member
555 posts
Joined: Feb. 2017
Offline
or whatabout this wrangle after the polyframe

vector up = {1,0,0};
@N = cross(@N,up);

this will work for some slanted line.
Edited by vusta - April 3, 2020 20:37:48
User Avatar
Member
407 posts
Joined: Aug. 2015
Offline
Hi “toadstorm”;

I tried your code, but it doesn't work!
Masoud Saadatmand (MSDVFX)
User Avatar
Member
407 posts
Joined: Aug. 2015
Offline
tamte
not sure what the purpose is, but you can also use Orientation Along Curve SOP, output X axis as N and play with Roll
Thank you, very useful SOP.
Masoud Saadatmand (MSDVFX)
User Avatar
Member
407 posts
Joined: Aug. 2015
Offline
vusta
or whatabout this wrangle after the polyframe

vector up = {1,0,0};
@N = cross(@N,up);

this will work for some slanted line.

Thank you. It works fine.
Masoud Saadatmand (MSDVFX)
  • Quick Links