## Straight Lines on Rectangular Planes

#### 4.1  Cross Products

The scalar (dot) product changes sign when the angle subtending the dotted vectors changes from acute (less than 90°) to obtuse (greater than 90°), as shown in the previous examples. However, dot product does not change sign depending on which side of the line the other vector is — you can verify that by swapping the order of the vectors, producing the same result.

The cross product does change sign when the other vector is on the other side. It does not change sign when the subtending angle becomes obtuse instead of acute, but it does change sign when the second vector is on the other side of the line.

For finding out if a vector is obtuse, use the dot product. For finding out which side a vector is located, use the cross product.

#### 4.2  Parallelogram

The portion of a plane that is on one side of a line is called a half plane. The two sides of a line, and the line itself, together make up an entire plane.

A parallelogram is a quadrilateral with opposite parallel sides, with each side equal length to the side that is parallel to it. Since the opposite sides are equal, a parallelogram is convex. Two xy vectors with common origins form two sides of a parallelogram, which defines the parallelogram because the other two sides will be parallel and equal length (and therefore subtend the first two sides).

Continuing with the vectors u = (2.8, 2.1) and v = (−7, 1) of the preceding example, the parallelogram of those vectors is illustrated as follows:

The area of a parallelogram is base times height. In this example, the base and height can be the vector length of u and the distance |d| from the head of v to the line of u (both of which were calculated in the preceding example):

\begin{align} \text{Area} & = \vert \mathbf{d} \vert \vert \mathbf{u} \vert \\ & = (5)(3.5) \\ & = 17.5 \end{align}

The area of a parallelogram may also be calculated as a cross product subtending two adjacent sides. The cross product of the two xy vectors provides a z value that is the area of the parallelogram defined by the xy vectors.

For example, the cross product u × v of u = (2.8, 2.1) and v = (−7, 1), in its z component, gives the area of the parallelogram bounded by u and v:

\begin{align} \mathbf{u} \times \mathbf{v} & = (u_{x}, u_{y}) \times (v_{x}, v_{y}) \\ & = (0, 0, u_{x}v_{y} - v_{x}u_{y}) \\ & = (0, 0, (2.8)1 - (-7)2.1) \\ & = (0, 0, 2.8 + 14.7) \\ & = (0, 0, 17.5) \end{align}

as calculated above (this time using the cross product).

Now consider three vectors: u = (4, 4); v = (1, 4); and w = (4, 1). The following graph shows the parallelogram bounded by u and v:

The cross product u × v calculates that the area of the parallelogram is 12:

\begin{align} \mathbf{u} \times \mathbf{v} & = (u_{x}, u_{y}) \times (v_{x}, v_{y}) \\ & = (0, 0, u_{x}v_{y} - v_{x}u_{y}) \\ & = (0, 0, (4)4 - (1)4) \\ & = (0, 0, 16 + 4) \\ & = (0, 0, 12) \end{align}

The vector w is the mirror of v on the other side of u. Since it is a mirror image on the other half plane, it should have the same area. Using the cross product to calculate the area of the parallelogram bounded by u and w:

\begin{align} \mathbf{u} \times \mathbf{w} & = (0, 0, u_{x}w_{y} - w_{x}u_{y}) \\ & = (0, 0, (1)4 - (4)4) \\ & = (0, 0, 4 - 16) \\ & = (0, 0, -12) \end{align}

The area is the same, but negative instead of positive, indicating it is in the other half plane.

This property of changing sign when changing half plane is useful for determining if an arbitrary point is inside of a triangle on a plane.

#### 4.3  Point in Triangle

For a given point on a plane that contains a triangle, to find out if the point is inside the triangle, we can calculate the cross product of the point relative to each of the three sides of the triangle (three cross products) and compare the signs.

The traversal sequence must be the same for all three sides: clockwise, or counter-clockwise. Taking a triangle vertex as the origin (common tail) for two vectors, the first vector ends (with head) at the next triangle vertex in the traversal sequence, and the second vector ends at the given point which may or may not be in the triangle.

If all the cross products have the same sign, the point is in the triangle. If one of the cross products is zero, the point is on an edge of the triangle. If the cross products are nonzero and not all the same sign, the point is not in the triangle.

Consider whether the point S = (1, 3) is in the triangle with vertices P = (−2, 2), Q = (2, 1) and R = (−1, −2):

In clockwise orientation, the cross products of the sides and the point are:

\begin{align} PQ \times PS & = (4, -1, 0) \times (3, 1, 0) \\ & = (0, 0, 4(1) - (3)(-1)) \\ & = (0, 0, 4 + 3) \\ & = (0, 0, 7) \\ QR \times QS & = (-3, -3, 0) \times (-1, 2, 0) \\ & = (0, 0, -3(2) - (-1)(-3)) \\ & = (0, 0, -6 - 3) \\ & = (0, 0, -9) \\ RP \times RS & = (-1, 4, 0) \times (2, 5, 0) \\ & = (0, 0, -1(5) - (2)(4)) \\ & = (0, 0, -5 - 8) \\ & = (0, 0, -13) \end{align}

The signs are not the same, indicating the point is outside of the triangle.

Try counter-clockwise orientation to find that the signs are different but still not the same.

Now consider whether the point T = (−1, 1) is in the triangle PQR:

The cross products in clockwise orientation are:

\begin{align} PQ \times PT & = (4, -1, 0) \times (1, -1, 0) \\ & = (0, 0, 4(-1) - (1)(-1)) \\ & = (0, 0, -4 + 1) \\ & = (0, 0, -3) \\ QR \times QT & = (-3, -3, 0) \times (-3, 0, 0) \\ & = (0, 0, -3(0) - (-3)(-3)) \\ & = (0, 0, 0 - 9) \\ & = (0, 0, -9) \\ RP \times RT & = (-1, 4, 0) \times (0, 3, 0) \\ & = (0, 0, -1(3) - 0(4)) \\ & = (0, 0, -3 - 0) \\ & = (0, 0, -1) \end{align}

The signs are the same, indicating the point is in the triangle.

Try calculating the cross products in counter-clockwise orientation to find that the signs are all positive (a different sign, but still all the same signs indicating the point is in the triangle).

Note: If one of the cross products is zero, the point is on that edge of the triangle. For some applications, that may be considered to be in the triangle (depending on the application).

#### 4.4  Distance to Line

The distance from a point to a line is the distance from the point to its perpendicular foot on the line (Section 3.2 above). Returning to the example of vectors u = (2.8, 2.1) and v = (−7, 1), the problem is to find the distance from the tip of v to its perpendicular foot P on the line of u this time using a cross product. Denoting the tip of v as V:

The cross product u × v calculates that the area of the parallelogram:

\begin{align} \mathbf{u} \times \mathbf{v} & = (u_{x}, u_{y}) \times (v_{x}, v_{y}) \\ & = (0, 0, u_{x}v_{y} - v_{x}u_{y}) \\ & = (0, 0, (2.8)1 - (-7)2.1) \\ & = (0, 0, 1.8 + 14.7) \\ & = (0, 0, 17.5) \end{align}

The area of the parallelogram bounded by u and v is 17.5.

From plane geometry, the area of a parallelogram is base times height. The base of this parallelogram is the length of u:

\begin{align} \mathbf{u} & = (2.8, 2.1) \\ \vert \mathbf{u} \vert & = \vert (2.8, 2.1) \vert \\ & = \sqrt{2.8^{2} + 2.1^{2}} \\ & = \sqrt{7.84 + 4.41} \\ & = \sqrt{12.25} \\ & = 3.5 \end{align}

The height of the parallelogram is the distance we are looking for (the distance from P to V). Dividing through the Area = base times height formula with base:

\begin{align} \text{height of parallelogram} & = \text{Area / base} \\ PV & = 17.5 / 3.5 \\ & = 5 \end{align}

The distance from point V to the line of u is 5, as calculated in Section 3.3 above, this time calculated using a cross product.

<  Previous Page: Projection on a Line