views:

494

answers:

3

hello, i have two points in 3D space which have X-coordinates with different signum. so one of them lies definitely on one side of the X-plane and one on the other.

now i want to find the intersection of this plane and the line made up by the two points in the most simple and optimized way.

i know how to do general line plane intersection, but since in this case the plane is just the x-plane, i think there should be some shortcuts i can take.

thanks!

+5  A: 

Connect the two points and get the equation of line using two-point form (the 3D generalization is simple).

Then solve the equation for x = 0.

After you've got the solutions, translate them into your programming language.

KennyTM
+1  A: 

Try this I am still calculating :) improving... Let me know if it works.

A = (x1,y1,z1)
B = (x2,y2,z2)
C = (x,y,z)

C will divide line joining A and B in ratio x1/x2.

So by similarity (y,z) will also divide line joining (y1,z1) and (y2,z2) in the same ratio.

As the point C lies in Y-Z plane

x = 0 

by Section Formula

y = (r*y2 + y1) / (r+1)

z = (r*z2 + z1) / (r+1)

where r = |x1| / |x2|

Simple example:

Let A = (1,2,2) and B = (-2,2,2) then C should clearly be (0,2,2).

x = 0
r = 1 / 2 = 0.5
y = (0.5*2 + 2)/(0.5+1) = 2
z = (0.5*2 + 2)/(0.5+1) = 2

CODE C#:

 public class Point
    {
        public double x { get; set; }
        public double y { get; set; }
        public double z { get; set; }

        public Point(double X, double Y, double Z)
        {
            x = X;
            y = Y;
            z = Z;
        }

        public override string ToString()
        {
            return string.Format("({0},{1},{2})",x,y,z);
        }
    }

    public class Program
    {
        public static void Main()
        {
            Point a = new Point(-10, 0, 10);
            Point b = new Point(10, 0, 0);

            Console.WriteLine(GetIntersectionWithYZ(a,b));
        }

        public static Point GetIntersectionWithYZ(Point A, Point B)
        {
            double r = - A.x / B.x;

            double y = (r * B.y + A.y) / (r + 1);
            double z = (r * B.z + A.z) / (r + 1);

            return new Point(0, y, z);
        }
    }
TheMachineCharmer
Any comments friends!! :p
TheMachineCharmer
+2  A: 
P1 = (x1,y1,z1)
P2 = (x2,y2,z2)

k1 = -x2/(x1-x2)
k2 = 1-k1

Intersection = k1*P1 + k2*P2    or:
Ix = 0              - we know this one
Iy = k1*y1 + k2*y2
Iz = k1*z1 + k2*z2

I'm assuming P1 is to the right and P2 to the left. It may work with them reversed.

phkahler