Skip to content

Instantly share code, notes, and snippets.

@peroon
Created April 28, 2017 06:56
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 peroon/fb4b2dff7e6c5d1293f52b8cf3cdb0e8 to your computer and use it in GitHub Desktop.
Save peroon/fb4b2dff7e6c5d1293f52b8cf3cdb0e8 to your computer and use it in GitHub Desktop.
Use complex instead of Vector2D
# add
A = 2 + 3j
B = 4 + 5j
print(A + B)
# sub
A = 2 + 3j
B = 4 + 5j
print(A - B)
# dot
A = 1 + 0j
B = 0 + 1j
dot = (A.conjugate() * B).real
print(dot)
# dot 2
A = 2 + 3j
B = 4 + 5j
dot = (A.conjugate() * B).real
print(dot)
# length
A = 2 + 3j
B = 4 + 5j
print(abs(A))
print(abs(B))
# cross
A = 2 + 3j
B = 4 + 5j
cross = A.real * B.imag - A.imag * B.real
print(cross)
# declaration
x = 2
y = 3
A = complex(x, y)
print(A)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment