Skip to content

Instantly share code, notes, and snippets.

@horstjens
Created February 18, 2021 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save horstjens/a83e492cb3247c36d82065eb809801bb to your computer and use it in GitHub Desktop.
Save horstjens/a83e492cb3247c36d82065eb809801bb to your computer and use it in GitHub Desktop.
Vektorprojektion auf anderen Vektor
import vpython as v
scene1 = v.canvas(title="auftrieb",
width=800,
height=600,
center=v.vector(0, 0, 0),
background=v.vector(0.4, .4, 0.4),
)
scene1.autoscale = False
ground = v.box(pos = v.vector(0,0,0), size=v.vector(10,0,10), color=v.vector(0.1,0.1,0.9), opacity=0.2)
a = v.arrow(pos=v.vector(0,0,0), axis=v.vector(1,0,0), color=v.color.blue, shaftwidth=0.2)
b = v.arrow(pos=v.vector(0,0,0), axis=v.vector(2,0.4,0.4), color=v.color.yellow)
#c = v.box(pos=b.axis, color = v.color.red, size=v.vector(2,0,2), axis=v.dot(a.axis,b.axis))
#dab = v.arrow(pos=v.vector(0,0,0), size=v.vector(1,1,1), color = v.color.red, axis =v.vector(1,0,1))
cab = v.arrow(pos=v.vector(0,0,0), size=v.vector(1,1,1), color = v.color.red, axis =v.cross(a.axis, b.axis))
cab2 = v.arrow(pos=v.vector(0,0,0), size=v.vector(1,1,1), color = v.color.green, axis =v.cross(a.axis, cab.axis))
#r = v.ring(pos=b.length * b.axis.norm() , radipos=b.length * b.axis.norm()us=1, axis = a.axis)
c = v.box(pos=b.length * b.axis.norm(), size=v.vector(0.01,5,5), axis=a.axis)
#x = v.box(pos=v.vector(0,3,0), size=v.vector(0.1,2,2), axis=v.vector(0,1,0), color=v.color.green)
#v.dist()
print("a", a.axis, "b", b.axis)
print("diff_angle", v.degrees(v.diff_angle(a.axis,b.axis)))
print("dot", v.dot(a.axis, b.axis))
print("cross", v.cross(a.axis, b.axis))
print("proj b a", v.proj(b.axis, a.axis))
print("comp a.b", a.axis.comp(b.axis))
print("comp b.a", b.axis.comp(a.axis))
p = v.arrow(pos=v.vector(0,0,0), axis=v.proj(b.axis, a.axis), shaftwidth =0.1, color=v.vector(0.5,0,0.5))
print("a len, p len, ma -mp", v.mag(a.axis), v.mag(p.axis), v.mag(a.axis)-v.mag(p.axis) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment