Created
July 10, 2016 04:59
-
-
Save JoshCheek/f436a9293184dd33bb8c9d93e7e636fd to your computer and use it in GitHub Desktop.
Started trying to explain complex numbers, but realized that I might not be right.
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
class Float | |
# simplify distractingly large numbers that occur from floating point imprecision | |
def inspect | |
round(8).to_s | |
end | |
end | |
include Math | |
# Quantity of a degree in radians, b/c sin and cos expect radians | |
degree = PI*1r/180 | |
# Complex numbers have a "real" component and an "imaginary" component, ie (2+3i) | |
# the real component is 2, the imaginary component is 3 | |
# | |
# The real component is a number like all the ones you've ever used, | |
# you can think of it as "whenever I said 2+2=4 I was saying (2+0i) + (2+0i) = (4+0i)" | |
# | |
# The imaginary component is multiplied by the unit "i". | |
# i is usually described as "the square root of -1", | |
# but makes more sense to me as "rotate 90º". | |
# Thus 1i = "rotate 90º", and 0.5i = "rotate half of 90º" = "rotate 45º" | |
# uhhhhh.... I'm not sure this is valid anymore, I stopped writing this so I could | |
# think about that, but never got back to it, so just going to post this in a gist | |
# so that I can find it again later if I want | |
rotation = cos(degree) + sin(degree)*1i | |
point = 1 + 0i | |
# 30º = π/6 | |
30.times { point *= rotation } | |
sqrt(3)/2 # => 0.8660254 | |
point.real # => 0.8660254 | |
point.imag # => 0.5 | |
# 45º = π/4 | |
15.times { point *= rotation } | |
sqrt(2)/2 # => 0.70710678 | |
point.real # => 0.70710678 | |
point.imag # => 0.70710678 | |
# 60º = π/3 | |
15.times { point *= rotation } | |
point.real # => 0.5 | |
point.imag # => 0.8660254 | |
sqrt(3)/2 # => 0.8660254 | |
# 90º = π/2 | |
30.times { point *= rotation } | |
point.real # => 0.0 | |
point.imag # => 1.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment