3D line plane intersection, with simple plane

纵然是瞬间 提交于 2019-12-01 08:48:16

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.

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.

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);
        }
    }

This question is old but since there is such a much more convenient solution I figured it might help someone.

The general case is very nearly exactly as fast in practice if correctly implemented.

Plane and line intersections are quite elegant when expressed in homogeneous coordinates but lets assume you just want the solution:

There is a vector 4x1 p which describes the plane such that p^Tx =0 for any homogeneous point on the plane. Next compute the plucker coordinates for the line L=ab^T - ba^T where a = {point_1; 1}, b={point_2;1}, both 4x1 on the line compute: x=Lp = {x0,x1,x2,x3} x_intersect=({x0,x1,x2}/x3)

For higher performance use of expressions templates will allow the compiler to collapse the solution to the minimal case.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!