0

The line is:

Ax + By + Cz = D

Ex + Fy + Gz = H

I want any point (x,y,z) that satisfies those equations.

I've tried by choosing one coordinate to set to zero, then solving for the other two. This works correctly except:

1) I'm not sure of a reliable way to choose which coordinate to zero without causing numerical instability when some coefficients are zero or near zero.

2) It involves a lot of if statements which makes the code messy and hard to test all combinations of conditions.

Edit: I don't care which point it finds. It doesn't have to allow all of them to be found.

user1318499
  • 1,327
  • 11
  • 33

2 Answers2

3

i would like to complement jh314's solution:

you can also obtain a point by solving a more complex problem like:

Ax + By + Cz = D 
Ex + Fy + Gz = H 
(BG-CF)x+(-AG+CE)y+(AF-BE)z = 0

i think that would be numerically more stable

Zoltán Haindrich
  • 1,788
  • 11
  • 20
2

You have two planes, and the intersection is a line. A line is defined by a point and a vector.

To get the vector, you can do the cross product of the normal vectors of the plane.

Ax + By + Cz = D has normal vector <A,B,C>
Ex + Fy + Gz = H has normal vector <E,F,G>

The cross product is

<BG-CF,-AG+CE, AF-BE>

If cross product is <0,0,0>, the planes are parallel, and no line exists.

Then find a point (a,b,c) in the intersection (by solving your original two equations):

Ax + By + Cz = D
Ex + Fy + Gz = H

To do so, you can suppose that z is zero. Then check if (A*F-E*B) != 0. If this is true, then evaluate x,y:

x = (D*F-B*H)/(A*F-E*B)
y = (E*D-A*H)/(E*B-A*F)

Otherwise, check if (A*G-E*C) != 0. If so, then you know

x = (D*G-C*H)/(A*G-E*C)
z = (E*D-A*H)/(E*C-A*G)

Otherwise, check if (B*G-C*F) != 0. If so, then you know

y = (D*G-C*H)/(B*G-C*F)
z = (B*H-D*F)/(B*G-C*F)

Then you have a line!

x = a + (BG-CF)t
y = b + (CE-AG)t
z = c + (AF-BE)t

where t is your parameter. For any t you pick, (x,y,z) will be a point on your desired line.

jh314
  • 27,144
  • 16
  • 62
  • 82
  • Your original two equations. I'll mention that. – jh314 Jul 13 '13 at 03:11
  • This comes back to my original solution. It's not easy to solve those while guaranteeing numerical stability because there are more unknowns than equations. – user1318499 Jul 13 '13 at 03:15
  • Supposing z=0 won't always work. For example, when A=B=E=G=0. You could solve this with a lot of conditional statements but that's the solution I already have and I feel it's too ugly and hard to be confident in its reliability. – user1318499 Jul 13 '13 at 03:31
  • There are 3 cases. Either x can be 0, y can be 0, or z can be 0. One of them has to be true. – jh314 Jul 13 '13 at 03:33
  • I can't use != because they're floating point numbers. Instead I would find the maximum of (AF-EB), (AG-EC) and (BG-CF) to decide which coordinate to zero. That test in itself is pretty messy to implement. You can see that this code is growing very complicated which is what I was hoping to avoid. – user1318499 Jul 13 '13 at 04:00