Skip to content

Instantly share code, notes, and snippets.

@mik30s
Created September 5, 2018 04:31
Show Gist options
  • Save mik30s/9da7ef771f2988fcfb656839e5b4f520 to your computer and use it in GitHub Desktop.
Save mik30s/9da7ef771f2988fcfb656839e5b4f520 to your computer and use it in GitHub Desktop.
Lab 1 part b - vectors
GlowScript 2.7 VPython
baseball = sphere (pos=vector(0,0,0), radius=0.2, color=color.white)
A = arrow(pos=vector(3,-2,4), axis=vector(1,-4,2), shaftsize = 0.1, color=color.cyan)
B = arrow(pos=vector(-5,3,4), axis=vector(-7,1,2), shaftsize = 0.1, color=color.cyan)
C `= arrow(pos=vector(-1,-6,2), axis=vector(-3,-8,0), shaftsize = 0.1, color=color.cyan)
print("Magnitude of A = ", sqrt(A.pos.x**2 + A.pos.y**2 + A.pos.z**2))
print("A - 3B + 2C = ", A.pos - 3*B.pos + 2*C.pos)
print("C . B", C.pos.x * B.pos.x + C.pos.y * B.pos.y + C.pos.z * B.pos.z)
D = vector(
A.pos.y*B.pos.z - A.pos.z*B.pos.y,
A.pos.z*B.pos.x - A.pos.x*B.pos.z,
A.pos.x*B.pos.y - A.pos.y*B.pos.x,
)
D_magnitude = sqrt(D.x**2 +D.y**2 +D.z**2)
print("A x B = ", D)
print("D =", D/D_magnitude)
arrow(pos=D, axis=D-vector(2,2,2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment