Created
April 28, 2017 06:56
-
-
Save peroon/fb4b2dff7e6c5d1293f52b8cf3cdb0e8 to your computer and use it in GitHub Desktop.
Use complex instead of Vector2D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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