# Vector question

This topic is 4735 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, I would like to know if a function exist, before I made one for myself. I got a line, defined by 2 vectors (Start and End are the names for this example). Direction is determined by End - Start. Now I want to know the X and Y value when I give the Z value. Is there a function that does this? The function doesn't have to check if the Start.z and End.z are different to each other.

##### Share on other sites
linear interpolation (slerp).

basically, Xmiddle = (Xend - Xstart) * (Zmiddle - Zstart) / (Zend - Zstart)

##### Share on other sites
So you want:
d = e - sfor some alpha and given d and z:αd = (αdx, αdy, αdz) = (x,y,z)αdz = zα = z/dzx = αdx = zdx/dzy = αdy = zdy/dz

##### Share on other sites
This might not be the best way but it should work

float z = 10;float t = (z - Start.z ) / (End.z - Start.z);if ( t < 0.0f || t > 1.0f ){  // not a valid z value}x = Start.x + t * (End.x - Start.x);y = Start.y + t * (End.y - Start.y);

I just wrote this and it's untested.
hope that helps

Thank you all

##### Share on other sites
you realy should check if End.z = Start.z
If they are the same then you will get a division by zero (which is bad)
( if you use my code sample that is )

##### Share on other sites
Quote:
 Original post by glSmurfyou realy should check if End.z = Start.zIf they are the same then you will get a division by zero (which is bad)( if you use my code sample that is )

Yes I thought of that, but thanks for the reminder.

• 9
• 13
• 41
• 15
• 12