Reputation: 28742
I really suck at math. No, better explanation: I don't know how to interpret mathematical notation. My brain just cant interpret it. That's why I come to the programming community for help "translating" math into a language I do understand.
I have two sets of coordinates in 3d space representing the line of sight.
Vector1(eyes) x=10 y=10 z=4
Vector2(lookingat) x=10 y=8 z=4.785
How do I calculate a point with these double values beyond the looking at value? for example, what lies 2 points beyond the line we are looking it? what location in space would that be?
In short:
How do I extrapolate a given point beyond the line made up by two vectors with given double value along the line.
a known
\
\
\
b known
?
? + 3
?
c what is this value...
Edit
With the help of the answer of @Thrustmaster I came up with this wonderfull solution. Thanks a lot :D
private Vec3 calculateLine(Vec3 x1, Vec3 x2, double distance) {
double length = Math.sqrt(multiply(x2.xCoord - x1.xCoord) + multiply((x2.yCoord - x1.yCoord)) + multiply((x2.zCoord - x1.zCoord)));
double unitSlopeX = (x2.xCoord-x1.xCoord) / length;
double unitSlopeY = (x2.yCoord-x1.yCoord) / length;
double unitSlopeZ = (x2.zCoord-x1.zCoord) / length;
double x = x1.xCoord + unitSlopeX * distance;
double y = x1.yCoord + unitSlopeY * distance;
double z = x1.zCoord + unitSlopeZ * distance;
return Vec3.createVectorHelper(x, y, x);
}
private double multiply(double one) {
return one * one;
}
Upvotes: 1
Views: 2283
Reputation: 44454
You need to start looking to basic 3D coordinate geometry.
In 3D, the equation can be written as:
x = x1 + unitSlopeX * distance
y = y1 + unitSlopeY * distance
z = z1 + unitSlopeZ * distance
.. where (x1,y1,z1) can be any point on the line; in this case (10,10,4).
Next set of unknowns is all 3 unitSlopes. To calculate it, simply subtract the two points (this will ive you a vector), and divide by the length of the vector.
length = sqrt((x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2)
unitSlopeX = (x2-x1) / length
unitSlopeY = (y2-y1) / length
unitSlopeZ = (z2-z1) / length
Now, to finally, get your third coordinate, simply plug in distance (any value) into the three equations at the beginning of this post.
In vector notation:
V = V1 + t * (V2 - V1) / | V2 - V1 |
.. where t
is any real number.
Upvotes: 7