Jump to content

VEX rotation


BcM

Recommended Posts

Hello,

I just started with Houdini, and tried to make a sweep kinda thingy with VEX (part of a larger plan). I cannot seem to figure out how to get around this problem. When I scatter points around my existing point, they are not rotated, I assume because the points I drew have no normal whatsoever. I want them like the red lines in the attachment.

I tried to do a lookat from one point to the next, but I cannot figure out what to do next.

//define variables
float twopi = 3.14159 * 2;

float theta = 0;
float step_angle = twopi / (float)85;

float x, z;
vector pos;
matrix n;

// define line rotation

// add points
while(theta < twopi)
{
    x = @P.x + cos(theta) * .05;
    z = @P.z + sin(theta) * .05;
    
    pos = set(x, @P.y, z);

    addpoint(0,pos);
    
    theta += step_angle;
}

 

Any help would be appreciated.

 

 

 

 

Question.jpg

Link to comment
Share on other sites

Do you want it to be perpendicular to the plane created by two edges with angle? For any non-corner case you can compute rotation matrix:

// Point wrangle.

// Compute matrix aligned with plane created by two edges.
vector e0 = point(0, "P", @ptnum-1) - @P;
vector e1 = point(0, "P", @ptnum+1) - @P;

vector y = normalize(e0 + e1);
vector z = normalize(cross(e0, e1));
vector x = normalize(cross(z, y));
3@r = set(x, y, z);

After that, you may use it in your point creation loop like this:

// Create position on circle centered at the origin.
// Scale it by radius. Rotate it by rotation matrix.
// Translate it to desired location.
set(cos(theta), sin(theta), 0) * radius * r + pivot

It's an example expression, not a final code. From your code, value .05 can be used as a radius, @P can be a pivot and r is a matrix computed by the snippet above. There are common cases where it will not work. You should decide which orientation to prefer from infinite possible variants:

  1. End points.
  2. One or both edges has zero length.
  3. Angle between edges is 0 or PI

 

align_circles_to_curve.hipnc

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...