concept cross product in category python

appears as: cross product, The cross product, cross products
Math for Programmers: 3D graphics, machine learning, and simulations with Python

This is an excerpt from Manning's book Math for Programmers: 3D graphics, machine learning, and simulations with Python.

This is called the right-hand rule, and if it agrees with your axes, then you are (correctly!) using the right-handed orientation. Orientation matters! If you are writing a program to steer a drone or control a laparoscopic surgery robot, you need to keep your ups, downs, lefts, rights, forwards, and backwards consistent. The cross product is an oriented machine, so it can help us keep track of orientation throughout all of our computations.

3.4.2                   Finding the direction of the cross product

Again, before I tell you how to compute the cross product, I want to show you what it looks like. Given two input vectors, the cross product outputs a result that is perpendicular to both. For instance, if u = (1,0,0) and v = (0,1,0), then it happens that the cross product u × v is (0, 0, 1) as shown in figure 3.33.

Figure 3.33: The cross product of u = (1, 0, 0) and v = (0, 1, 0)

In fact, as figure 3.34 shows, any two vectors in the x,y plane have a cross product that lies along the z-axis.

Figure 3.34: The cross product of any two vectors in the x,y plane lies on the z-axis.

This makes it clear why the cross product doesn’t work in 2D: it returns a vector that lies outside of the plane containing the two input vectors. We can see the output of the cross product is perpendicular to both inputs even if they don’t lie in the x,y plane (figure 3.35).

Figure 3.35: The cross product always returns a vector that is perpendicular to both inputs.

But there are two possible perpendicular directions, and the cross product selects only one. For instance, the result of (1, 0, 0) × (0, 1, 0) happens to be (0, 0, 1), pointing in the positive z direction. Any vector on the z-axis, positive or negative, would be perpendicular to both of these inputs. Why does the result point in the positive direction?

Here’s where orientation comes in: the cross product obeys the right-hand rule as well. Once you’ve found the direction perpendicular to two input vectors u and v, the cross product u × v lies in a direction that puts the three vectors u, v, and u × v in a right-handed configuration. That is, we can point our right index finger in the direction of u, curl our other fingers toward v, and our thumb points in the direction of u × v (figure 3.36).

Figure 3.36: The right-hand rule tells us which perpendicular direction the cross product points toward.

When input vectors lie on two coordinate axes, it’s not too hard to find the exact direction their cross product will point: it’s one of the two directions along the remaining axis. In general, it’s hard to describe a direction perpendicular to two vectors without computing their cross product. This is one of the features that make it so useful once we see how to compute it. But a vector doesn’t just specify a direction; it also specifies a length. The length of the cross product encodes useful information as well.