Jump to content
Wooshum

Vector Intersection in VEX

Recommended Posts

I have been losing my mind a little on this one:

I am wanting to find the intersection point of two vectors in VEX (i.e. a version of the simplified Curvesect SOP). The goal is to implement this through and Attrib Wrangle node. At this stage I have tried implementing the solutions to the problem presented on the following forums but they are suited to 2D:

http://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect

http://math.stackexchange.com/questions/406864/intersection-of-two-lines-in-vector-form

This should be a trivial solution but I have been way off the mark with my attempts.

Any help is much appreciated!

vector_intersection.hip

Share this post


Link to post
Share on other sites

I used those resources to create something similar as well, so it is possible.
While I can't give you my code, I saw some stuff in this topic which is basically that:

 

Share this post


Link to post
Share on other sites

Thanks for the tip @acey195 and @petz thanks for the solution. Here is the quick VEX snippet that I tested, works a treat!

// Get Lines
vector A = point(0, "P", 0);
vector B = point(0, "P", 1);
vector C = point(1, "P", 0);
vector D = point(1, "P", 1);

// Calculate Line Vectors
vector AB = B-A;
vector CD = D-C;

// Calculate To Vector
vector toVec = A - C;

// Calculate Intersection
vector vecx = cross(AB, CD);
float val1 = dot(vecx, cross(CD, toVec));
float val2 = dot(vecx, vecx);
vector pos = A + (val1 / val2) * AB;

addpoint(0, pos);

 

  • Like 8

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×