1

I've been wondering for a long time and I can't find, where is my fault.

I write simple program to compute line of two planes intersection.

function getIntersectOf2Planes ( $P1 , $P2 )
{
      /*  Line equation in parametric form:
                x = x0 + t*a
                y = y0 + t*b
                z = z0 + t*c
            */
        $x0 = ( $P1->B * $P2->D - $P2->B * $P1->D ) / ( $P1->A * $P2->B - $P2->A * $P1->B ) ;
        $a = ( $P1->B * $P2->C - $P2->B * $P1->C );
        $y0 = ( $P2->A * $P1->D - $P1->A * $P2->D ) / ( $P1->A * $P2->B - $P2->A * $P1->B ) ;
        $b = ( $P2->A * $P1->C - $P1->A * $P2->C );
        $z0 = 0;
        $c = 1;
}

I found this formula on site: http://www.ambrsoft.com/TrigoCalc/Plan3D/Plane3D_.htm

But when i run my program for planes: Plane1: -25x -10y +4z +125 = 0 Plane2: 2x +21y -8z -12 =0

I have a result:

x0 = 4.960396039604
y0 = 0.099009900990099
z0 = 0
a  = -4
b  = -192
c  = 1

What means:

x = 4.96 -4t (rounded)
y = 0.1 -192t
z = t

But the online calculators, give me:

x = 4.96 − 4t
y = 0.1 − 192t
z = − 505t

As you can see, the 'c' parametr is a problem.

How to fix it?

//EDIT: Looking on:

$a = ( $P1->B * $P2->C - $P2->B * $P1->C );
$b = ( $P2->A * $P1->C - $P1->A * $P2->C );

I tried:

$c = (  $P1->A * $P2->B - $P2->A * $P1->B );

and it's working. But why? Why on this site above is:

z = t
  • I suggest that you read the plane intersection example farther down the web page that you’ve cited. It explains that the direction vector of the line is the cross product of the two plane normals, so $z=t$ in the formula is obviously incorrect, since the $z$-component of this cross product isn’t always going to equal $1$. – amd May 04 '18 at 20:22

1 Answers1

0

Yes indeed the formula given is uncorrect, we need

$$z=t(A_1B_2-B_1A_2)$$

indeed the direction vector for the parametric line intersection is obtained by the cross product of the two normal vectors of the planes.

user
  • 154,566
  • I`m just tried it and edit my post at the same time, when you give this answer :) But this answer is very useful, because my solution was "random" and this is mathematical :D Thanks ;) – Przemysław Niemiec May 04 '18 at 16:19
  • 1
    @PrzemysławNiemiec You are welcome! Please do not hesitate to ask if you need some more detail about the derivation for the direction vector by the cross product of the two normal vectors? Is it clear to you? – user May 04 '18 at 16:21
  • not exactly. Its because I do not full understeand what means A, B, C, D in a plane equation. For example in line (2D) equation: y=a*x+b, 'a' is an angle (tanges of angle) and 'b' is a shift. But I don't understand it in plane equation. – Przemysław Niemiec May 04 '18 at 16:27
  • But I understand how cross product looks in geometry (vector perpendicular to two another vectors) if you ask for it. – Przemysław Niemiec May 04 '18 at 16:30
  • 1
    @PrzemysławNiemiec the coefficient $A,B,C$ represent the coordinates of a normal vector $n=(A,B,C)$ to the plane whereas $|D|$ is a mesure of the distance of the plane from the origin (indeed for $D=0$ the plane is through the origin). When the vector $n$ is normalized $|D|$ represents exactly the distance of the plane from the origin. – user May 04 '18 at 16:34
  • Thanks you again. My next problem may be because my low english level, but what means 'origin'? I can't translate it using Internet with any sense? Is it (0,0,0) point? – Przemysław Niemiec May 04 '18 at 16:36
  • 1
    @PrzemysławNiemiec Yes exactly O=(0,0,0)! – user May 04 '18 at 16:37
  • Hi, I have another problem: What if the expression "( $P1->A * $P2->B - $P2->A * $P1->B )" is equal to zero? Then I can't compute it, besause of "divide by zero" error. For example it will happen, when the first plane is pararell to X and Y axies. (A=0, B=0, C=100, D=0). When i tried to compute intersection line with a plane (A=50, B=0, C=0, D=-250) i get this error, but as you can see, the planes aren't pararell, so the equation of line should exists. – Przemysław Niemiec May 10 '18 at 16:06
  • 1
    I suggest to follow the general procedure, given the planes $A_1x+B_1y+C_1z+D_1=0$ and $A_2x+B_2y+C_2z+D_2=0$ find tha normal vector by cross product $n=(A_1,B_1,C_1)\times(A_2,B_2,C_2)$ and then find a point $P_0(x_0,y_0,z_0)$ which satisfy the system of the two equations. Then the line equation is $P_0+t\cdot n$. – user May 10 '18 at 16:25