Created by Ryo Kurashina
Email: rk2014@ic.ac.uk
HTML Version (This will be a link)
Notice that this is just the height of the parallelogram multiplied by its width. The term above is also exactly equal to the absolute value of the cross product of $\vec{u}$ and $\vec{v}$ (this is an alternative way to represent the cross product instead of the regular determinant definition).
$$ V =\, \mid\vec{u}\times\vec{v}\mid \cdot \mid\mid\vec{w}\mid\mid\,\mid\cos\theta\mid \,=\, \mid\vec{w}\cdot(\vec{u}\times\vec{v})\,\mid$$
This is the triple scalar product and we find that the volume of a parallelepiped is exactly equal to the absolute value of the triple scalar product.
If the three vectors we choose are coplanar (i.e. they all lie on the same plane) it is easy to see that the volume of the parallelepiped becomes zero. Mathematically, we would get that the cross product of two of the vectors would be exactly perpendicular to the remaining vector which would give a zero dot product.
Python
The next section relies on knowledge about Classes
in Python
. If you're not familiar with classes then this is a good introduction.
In [ ]:
# Import packages and modules to be used
import numpy as np
from plotly.offline import download_plotlyjs,init_notebook_mode,plot,iplot
import plotly.graph_objs as go
init_notebook_mode(connected=True)
In [ ]:
class Parallelepiped(object):
# Initialize a parallelepiped object by giving it 3 vector arguments
def __init__(self,u,v,w):
self.u = np.array(u)
self.v = np.array(v)
self.w = np.array(w)
# Calculates the volume of a parallelepiped
def volume(self):
crossp = np.cross(self.v,self.w)
tp = np.dot(self.u,crossp)
return abs(tp)
def gopped(self):
x = [0,self.u[0],self.u[0]+self.v[0],self.v[0],self.w[0],self.w[0]+self.u[0],self.w[0]+self.u[0]+self.v[0],\
self.v[0]+self.w[0]]
y = [0,self.u[1],self.u[1]+self.v[1],self.v[1],self.w[1],self.w[1]+self.u[1],self.w[1]+self.u[1]+self.v[1],\
self.v[1]+self.w[1]]
z = [0,self.u[2],self.u[2]+self.v[2],self.v[2],self.w[2],self.w[2]+self.u[2],self.w[2]+self.u[2]+self.v[2],\
self.v[2]+self.w[2]]
pped = go.Data([go.Mesh3d(x=x,y=y,z=z,
i = [0, 0, 3, 4, 4, 4, 4, 4, 5, 6, 6, 7],
j = [2, 3, 4, 3, 6, 7, 1, 5, 2, 2, 7, 3],
k = [1, 2, 0, 7, 5, 6, 0, 1, 1, 5, 2, 2],opacity = 0.6)
])
return pped
# Method which finds a suitable layout for the pped when plotted
def lytpped(self):
if self.volume()==0:
return ValueError("Vectors must not be coplanar")
else:
ubx = sum([abs(self.u[0]),abs(self.v[0]),abs(self.w[0])])
uby = sum([abs(self.u[1]),abs(self.v[1]),abs(self.w[1])])
ubz = sum([abs(self.u[2]),abs(self.v[2]),abs(self.w[2])])
layout = go.Layout(
title = "Plot of Parallelepiped",
scene = dict(xaxis=dict(
title='x', range=[-ubx,ubx]
),
yaxis=dict(
title='y',range=[-uby,uby]
),
zaxis = dict(
title='z',range=[-ubz,ubz])
)
)
return layout
Now we give an example of how to use the Parallelepiped object.
In [ ]:
# Initialize the object with 3 vectors
my_pped = Parallelepiped([4.,0.,6.],[2.,-1.,1.],[4.,2.,3.])
# Find the volume by calling the .volume() method on it
print(my_pped.volume())
# Find the Mesh3d data for the plot of the pped
data = my_pped.gopped()
# Find the Mesh3d layour for the plot of the pped
layout = my_pped.lytpped()
# Plot
fig = go.Figure(data=data, layout=layout)
iplot(fig, filename='parallelepiped')