Solving system of equations with three unknowns

47 Views Asked by At

I need to solve an equation of a line using three known coordinate pairs (x0, y0), (x1, y1), and (x2, y2).

The equation of the plane is, of course, ax + by + c = 0.

I'm writing a little piece of code to calculate the position of a point w.r.t a line as it changes, so I just want to reduce the math as much as possible for efficiency, which means pre-solving this in terms of the x and y coordinates.

I can derive the equations to solve for a, b and c by hand in advance and write the code that way, but it ends up an ugly mess of substitutions to do it.

Is there a more straightforward approach that, giving my coordinates, I can solve for the constants quickly, without having to rely on matrix math or pulling in a math library?

1

There are 1 best solutions below

0
On BEST ANSWER

A line by two points is

$$\begin{vmatrix}x&y&1\\x_0&y_0&1\\x_1&y_1&1\end{vmatrix}= \begin{vmatrix}y_0&1\\y_1&1\end{vmatrix}x- \begin{vmatrix}x_0&1\\x_1&1\end{vmatrix}y+ \begin{vmatrix}x_0&y_0\\x_1&y_1\end{vmatrix}=0.$$

A plane by three points is

$$\begin{vmatrix}x&y&z&1\\x_0&y_0&z_0&1\\x_1&y_1&z_1&1\\x_2&y_2&z_2&1\end{vmatrix} =\begin{vmatrix}y_0&z_0&1\\y_1&z_1&1\\y_2&z_2&1\end{vmatrix}x-\begin{vmatrix}x_0&z_0&1\\x_1&z_1&1\\x_2&z_2&1\end{vmatrix}y+\begin{vmatrix}x_0&y_0&1\\x_1&y_1&1\\x_2&y_2&1\end{vmatrix}z-\begin{vmatrix}x_0&y_0&z_0\\x_1&y_1&z_1\\x_2&y_2&z_2\end{vmatrix} =\begin{vmatrix}y_{10}&z_{10}\\y_2&z_{20}\end{vmatrix}x-\begin{vmatrix}x_{10}&z_{10}\\x_{20}&z_{20}\end{vmatrix}y+\begin{vmatrix}x_{10}&y_{10}\\x_{20}&y_{20}\end{vmatrix}z-\begin{vmatrix}x_0&y_0&z_0\\x_{10}&y_{10}&z_{10}\\x_{20}&y_{20}&z_{20}\end{vmatrix} =0$$

where $a_{ij}:=a_j-a_i$.