PDA

View Full Version : Point3 along a ray ?


EricDLegare
05-21-2007, 03:43 PM
Hi All !

My question is, can we get a point3 value along a ray ?

I'll explain myself :

I have NODEA that shoots a ray to NODEB , The ray have a lenght, but can I get a position based on a given lenght ?



r = ray NODEA.pos NODEB.pos
at lenght 10 on ray r get position
:D

I just started to play with rays today, and I don't have Bobo's DVDs at home yet ( I had it at work but I changed studios so I don't have acces to it anymore :D )




I'm trying to make a POINT follow another POINT at a given distance:scream:

djlane
05-25-2007, 11:02 AM
Probably do it with vectors like so:


magnatude = 35
nodea = $Point01

nodeB = $Point02

nodeC = $Point03 ; nodeC.wirecolor = red

NormalizedVector = normalize(nodeB.pos - nodeA.pos)

NewVector = (NormalizedVector * magnatude) + nodeA.pos

nodeC.pos = NewVector



Cheers

Dan

Bobo
05-25-2007, 02:34 PM
You misunderstood the Ray value. A RAY contains a start position AND DIRECTION. You cannot construct a ray from two positions - the second argument to the constructor is the direction vector.

If you have two positions, you don't even need a Ray to find the length along the direction they define.

If A is the starting point and B is the end point, then the vector defined by the two is
theVector = B-A

This vector will have a length equal to the distance between them and direction pointing from A to B.

So if you want to find a point at a given distance along the line connecting A to B, you just need a normalized vector (also called unit vector) which has the same direction and a length of 1.0.

theUnitVector = normalize theVector

You can multiply a vector by a scalar (integer or float value) to get a new vector with the desired length. Thus,

theNewVector = theUnitVector * 10

This is a vector that starts at 0,0,0 and has a length of 10 and is parallel to the direction defined by A->B. In order to find the position of 10 units along the line from A to B, just add theNewVector to the position A:

theNewPos = A + theNewVector

In short,

theNewPos = A + (normalize (B-A)) * 10

This is exactly what djlane wrote, but with some more theory to explain it.

If you want more, see my signature :)

EricDLegare
05-27-2007, 06:32 PM
This is exactly what djlane wrote, but with some more theory to explain it.
Well thanks a lot :D

If you want more, see my signature :)
You can count on me for this :D Thanks again !

CGTalk Moderation
05-27-2007, 06:32 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.