Home > Software design >  Calculating the intersection point of a 3D line single Axis
Calculating the intersection point of a 3D line single Axis

Time:01-25

Im trying to work out how to calculate where a 3D line(Two 3D points) and a Axis meets.

In my case im trying to calculate the intersection of a 3D Point to the Z Axis.

Lets say i give the line the coords of

Point1.X = 0
Point1.Y = 0
Point1.Z = 0

Point2.X = 50
Point2.Y = 50
Point2.Z = 50

And i want to calculate the intersect at Z 15, how would i accomplish this?

I've thought about using interpolation, but it seems really inefficient here, i've looked at another posts and mathematical equations, but i dont really understand them enough to implement them into usable code.

CodePudding user response:

lambda = ( Point1.Z - Z ) / ( Point1.Z - Point2.Z )
Point3.X = Point1.X   lambda * (Point2.X - Point1.X)
Point3.Y = Point1.Y   lambda * (Point2.Y - Point1.Y)
Point3.Z = Z

CodePudding user response:

Suppose you have vector A (like your point1) and B, then a straight line L through both points can be defined by

L(k) = A   k(B - A) 

such that L(0) = A and L(1) = B. Suppose you want to find where

L(k).z = z_0

then you need to solve

A.z   k(B.z - A.z) = z_0 

so the line L intersects the plane z = z_0 at

k = (z_0 - A.z) / (B.z - A.z)

If (B.z - A.z) is zero, either it does not intersect the plane z = z_0 anywhere, or it is in the plane everywhere.

  • Related