# Intersection with primitive along vector

## Recommended Posts

I have two points and I am trying to figure out if there is a primitive "between" them (just if a straight line from A to B will intersect with it) but I am slightly stuck. I attempted this by calculating the distance between them and the distance along vector AB to the intersection and comparing the two values. But I can't seem to calculate the second. I have been using xyzdist() but I am not sure about how to approach the "along the vector" side of this as (as far as I understood it), xyzdist() just gives me the closest intersection without regarding a direction vector? Is there any function I could use for this?

I would appreciate any help

Thank you!

##### Share on other sites

you should be able to repro this easily..I just whacked the nodes in no mods necessary....(except for the non-straight line)

##### Share on other sites
7 hours ago, Noobini said:

you should be able to repro this easily..I just whacked the nodes in no mods necessary....(except for the non-straight line)

Hello Thank you very much! That is cool but I need to figure out how to do this in VEX as well as I need it further down the line in my code. Would you know how to approach this?

##### Share on other sites

Oh wait, my brain just didn't function for a second there. I realised I could just use intersect() to get the point.. Sorry about this

##### Share on other sites

Hey

I think the intersect_all function in Vex is what you are looking for.

##### Share on other sites
2 hours ago, Maurits said:

Hey

I think the intersect_all function in Vex is what you are looking for.

Yeah, I used intersect() and it works fine but, I assumed that &p:

int  intersect(<geometry>geometry, vector orig, vector dir, vector &p, float &u, float &v)

would write out the point of intersection between the ray and geometry. For me, it just copies @P (orig vector) giving me the points position as the intersection point which clearly doesn't make sense. Did I understand it wrong?

edit: I changed the orig vector to something else and &p gives me the orig vector every time? The dir vector is (goal - orig)

Edited by SquirkyTurtle

##### Share on other sites
21 minutes ago, SquirkyTurtle said:

Yeah, I used intersect() and it works fine but, I assumed that &p:

int  intersect(<geometry>geometry, vector orig, vector dir, vector &p, float &u, float &v)

would write out the point of intersection between the ray and geometry. For me, it just copies @P (orig vector) giving me the points position as the intersection point which clearly doesn't make sense. Did I understand it wrong?

edit: I changed the orig vector to something else and &p gives me the orig vector every time? The dir vector is (goal - orig)

Okay, I figured it out. It was because for some calculations the point was past the point of the dir vector, so it just returned 0 because I assume it wasn't 'long' enough. I multiplied it by 10 and it works fine now

##### Share on other sites
5 hours ago, SquirkyTurtle said:

Hello Thank you very much! That is cool but I need to figure out how to do this in VEX as well as I need it further down the line in my code. Would you know how to approach this?

yeah sorry it wasn't a direct answer coz I'm not a VEX expert myself...but I was hoping that would provide you with a spark with the thought process, it did !!!

## Create an account

Register a new account