# Vector Product Examples¶

```
from numpy import *
```

## Dot Product Example¶

A bead at $C$ can move along the straight rod $AB$. An elastic cord $CD$ is under tension and is attached to the bead. The distance from $B$ to $C$ is 11 cm.

Due to the cord force only, will be tend to slide toward A or B?

We want to find the dot product $\vec{r}_{CB} \cdot \vec{r}_{CD}$. If this is positive, then the angle $BCD < 90^\circ$, and bead will be pulled up the bar toward $B$. If the dot product is negative, the bead will be pulled toward $A$.

To get the vectors $\vec{r}_{CB}$ and $\vec{r}_{CD}$, start with the vectors we do know: $\vec{r}_{AB}$ and $\vec{r}_{BD}$.

```
rAB = array(( -18, 4, -16+4 )) # cm
rBD = array(( 15, 17-4, -4 )) # cm
```

Vector $\vec{r}_{CB}$ must have a magnitude of 11cm, and points in the direction of the unit vector $\hat{u}_{AB}$.

Find the unit vector $\hat{u}_{AB}$ and use it to define $\vec{r}_{CB}$.

```
rABmag = sqrt(sum(rAB**2))
uAB = rAB / rABmag
rCB = 11*uAB
rCD = rBD + rCB
```

Compute the dot product $\vec{r}_{AB} \cdot \vec{r}_{CD}$.

```
dot(rAB,rCD)
```

72.0

The positive dot product tells us $\vec{r}_{AB}$ and $\vec{r}_{CD}$ are more parallel than they are anti-parallel. That is, the angle between these vectors is less than $90^{\circ}$. We don't really care what the magnitude of the dot product is. This means the bead will slide in the $\vec{r}_{AB}$ direction, toward $B$.

## Cross Product Example¶

A contractor is required to prepare a surface so that it is nearly perfectly horizontal. The contract specifies that the normal to the surface must be within 0.5°.

The elevation of points $A$ and $B$, relative to the elevation at point $C$ are -3.3 ft and -4.3 ft, respectively. Determine the angle between the surface's normal direction and the vertical. Is it sufficiently level?

```
rCA = array(( 410., 0., -3.3 )) # ft
rCB = array(( 0., 507., -4.3 )) # ft
```

```
rN = cross(rCA,rCB) # vector normal to surface (upward)
uN = rN / sqrt(sum(rN**2)) # unit normal
print ('normal vector is',uN)
```

normal vector is [0.00804823 0.00848068 0.99993165]

We need to find the angle between this unit normal vector ($\hat{n}$) and $\hat{k}$. We'll use a dot product for that:

$$\hat{n} \cdot \hat{k} = \cos \theta$$

$$\theta = \cos^{-1} \left (\hat{n} \cdot \hat{k} \right )$$

```
dtr = pi/180 # factor for degree-to-radian conversion
khat = array((0,0,1))
angle = arccos( dot(uN,khat) )
print ('angle of normal from vertical is ', angle/dtr, 'degrees')
```

angle of normal from vertical is 0.669900672969825 degrees

### Solution:¶

The angle is $0.67^\circ$. The surface is *not* sufficiently level.