We want to determine which side point \(P=(x,y)\) lies with respect to the line that passes through points \(A=(x_1, y_1)\) and \(B=(x_2,y_2)\)
Calculate:
\[d=(x−x_1)(y_2−y_1)−(y−y_1)(x_2−x_1)\]
If d>0 then it lies on the "positive side" of the line (ie in the direction that n is pointing)
\[d=(x−x_1)(y_2−y_1)−(y−y_1)(x_2−x_1)\]
If d>0 then it lies on the "positive side" of the line (ie in the direction that n is pointing)
If d<0 then the point lies on the other side of the line,
If d=0 then the point lies exactly on the line.
Line AB can be defined as:
If d=0 then the point lies exactly on the line.
Geometric interpretation
Line AB can be defined as:
\[(x_2,y_2)−(x_1,y_1)=(x_2−x_1,y_2−y_1)\]
The orthogonal (perpendicular) direction to that line will be (flip the x and y and negate one component i.e (y, -x)):
The orthogonal (perpendicular) direction to that line will be (flip the x and y and negate one component i.e (y, -x)):
\[\mathbf n= ((y_2−y_1),−(x_2−x_1))\]
One possible vector going from the line to the Point \(P\) is:
\[D=P−A=(x−x_1, y−y_1)\]
Dot product between n and D
The expression for d above is actually the dot product between \(\mathbf n\) and \(D\).
We know that for the dot product between 2 vectors:
- If angle between the 2 vectors is less than 90 degrees, value of dot product is positive.
- If angle between the 2 vectors more than 90 degrees, negative.
- If the vectors are perpendicular to each other, dot product is zero.
Which explains the solution above
Cross or Perp-Dot product between lines AB and AP
Another interpretation is to express the problem as a perp-dot product, ie calculating the signed area of the parallelogram formed by vectors AB and AP.
Perp-dot-product between two vectors \(a\) and \(b\) is defined as:
\[\mathbf a\perp \mathbf b=\mathbf a^\perp\cdot \mathbf b=a_xb_y-a_yb_x=\begin{vmatrix} a_x &a_y \\ b_x &b_y \end{vmatrix}\]
Referring to the diagram above, we are interested in the perp-dot product between \(\vec {AB}\) and \(\vec {AP}\).
\[\begin{align} d&=\vec {AB}\perp \vec {AP}=\vec {AB}^\perp\cdot \vec {AP}\\ &= (x_2-x_1,y_2-y_1)^\perp\cdot (x-x_1,y-y_1)\\ &=(y_2-y_1, x_1-x_2)\cdot (x-x_1,y-y_1)\\ &=(y_2-y_1)(x-x_1)+(x_1-x_2)(y-y_1)\\ &=(x-x_1)(y_2-y_1)-(y-y_1)(x_2-x_1) \end{align}\]
\[\mathbf a\perp \mathbf b=\mathbf a^\perp\cdot \mathbf b=a_xb_y-a_yb_x=\begin{vmatrix} a_x &a_y \\ b_x &b_y \end{vmatrix}\]
Referring to the diagram above, we are interested in the perp-dot product between \(\vec {AB}\) and \(\vec {AP}\).
\[\begin{align} d&=\vec {AB}\perp \vec {AP}=\vec {AB}^\perp\cdot \vec {AP}\\ &= (x_2-x_1,y_2-y_1)^\perp\cdot (x-x_1,y-y_1)\\ &=(y_2-y_1, x_1-x_2)\cdot (x-x_1,y-y_1)\\ &=(y_2-y_1)(x-x_1)+(x_1-x_2)(y-y_1)\\ &=(x-x_1)(y_2-y_1)-(y-y_1)(x_2-x_1) \end{align}\]
hence same as the above.
Closest Point on Plane to Point
Referring back to the original diagram, the blue line can be interpreted as a plane, defined by the normal \(\mathbf n\) and either of the points \(A\) or \(B\), ie all points \(X\) on the plane satisfy the equation \(\mathbf n\cdot (X-A)=0\) (or \(\mathbf n\cdot (X-B)=0\)).
Let closest point R on the plane to P be the orthogonal projection of P onto the plane, obtained by moving P perpendicularly (with repsect to \(\mathbf n\)) towards the plane. That is, \(R=P-t\mathbf n\) for some value of t. Inserting this expression for R into the plane equation and solving for t gives:
\[\begin{aligned} &\mathbf n\cdot((P-t\mathbf n)-A)=0\\ &\mathbf n\cdot P-t(\mathbf n\cdot \mathbf n)-\mathbf n\cdot A=0\\ &\mathbf n\cdot(P-A)=t(\mathbf n\cdot \mathbf n)\\ &t=\mathbf n\cdot(P-A)/(\mathbf n\cdot \mathbf n)\\ &t=\mathbf n\cdot D/(\mathbf n\cdot \mathbf n) \end{aligned}\]
(Notice that the numerator of the last expression is the same as the original solution!)
Taking this expression further, substituting this expression for \(t\) in \(R=P-t\mathbf n\) gives the projection point \(R\) as simply:
\[R=P-(\mathbf n\cdot(P-A)/(\mathbf n\cdot \mathbf n) )\mathbf n\]
Hence it is clear that \(t=\mathbf n\cdot(P-A)\) correspods to the signed distance of \(P\) from the plane in units of the length of \(\mathbf n\).
If \(t\) is positive, \(P\) is 'in front' of the plane, and if negative \(P\) is 'behind' the plane.

0 件のコメント:
コメントを投稿