You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: exercises/concept/tracking-turntable/.docs/instructions.md
+33-4Lines changed: 33 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -14,15 +14,44 @@ Turndit needs to know how to find the new `(x, y)` coordinates to which the need
14
14
15
15
These operations can be done through trigonometric functions and/or rotation matrices, but they can be made simpler (and more fun, I assure you!) with the use of complex numbers via rotations and radial displacements.
16
16
17
-
This ease results from Euler's elegant formula, `ℯ^(iθ) = cos(θ) + isin(θ) = x + iy`, where `i = √-1` is the imaginary unit.
17
+
This ease results from Euler's elegant formula, `ℯ^(iθ) = cos(θ) + isin(θ) = x + iy`, where `i = √-1` is the imaginary unit and `|x + iy| = 1`.
18
+
With `r = |x + iy|`, we have the more general polar form of `r * ℯ^(iθ) = r * (cos(θ) + isin(θ)) = x + iy`.
19
+
18
20
19
21
For rotations, the complex number `z = x + iy`, can be rotated an angle `θ` about the origin with a simple multiplication: `z * ℯ^(iθ)`.
20
22
Note that the `x` and `y` here are just the usual coordinates on the real 2D Cartesian plane, and a positive angle results in a *counterclockwise* rotation, while a negative angle results in a *clockwise* one.
21
23
22
24
Likewise simply, a radial displacement `Δr` can be made by adding it to the magnitude `r` of a complex number in the polar form (eg. `z = r * ℯ^(iθ)` -> `z' = (r + Δr) * ℯ^(iθ)`).
23
25
Note how the angular part stays the same and only the magnitude, `r`, is varied, as expected.
24
26
25
-
## 1. Perform a 2D vector rotation
27
+
## 1. Construct a complex number from Cartesian coordinates
28
+
29
+
Implement the `z(x, y)` function which takes an `x` coordinate, a `y` coordinate from the complex plane and returns the equivalent complex number.
30
+
31
+
```julia-repl
32
+
julia> z(1, 1)
33
+
1.0 + 1.0im
34
+
35
+
julia> z(4.5, -7.3)
36
+
4.5 - 7.3im
37
+
```
38
+
39
+
## 2. Construct a complex number from Polar coordinates
40
+
41
+
Implement the `euler(r, θ)` function, which takes a radial coordinate `r`, an angle `θ` (in radians) and returns the equivalent complex number in rectangular form.
Implement the `rotate(x, y, θ)` function which takes an `x` coordinate, a `y` coordinate and an angle `θ` (in radians).
28
57
The function should rotate the point about the origin by the given angle `θ` and return the new coordinates as a tuple.
@@ -34,7 +63,7 @@ julia> rotate(0, 1, π)
34
63
julia> rotate(1, 1, -π/2)
35
64
(1, -1)
36
65
```
37
-
## 2. Perform a radial displacement
66
+
## 4. Perform a radial displacement
38
67
39
68
Implement the function `rdisplace(x, y, r)` which takes an `x` coordinate, a `y` coordinate and a radial displacement `r`.
40
69
The function should displace the point along the radius by the amount `r` and return the new coordinates as a tuple.
@@ -46,7 +75,7 @@ julia> rdisplace(0, 1, 1)
46
75
julia> rdisplace(1, 1, √2)
47
76
(2, 2)
48
77
```
49
-
## 3. Find desired song
78
+
## 5. Find the desired song
50
79
51
80
Implement a function `findsong(x, y, r, θ)` which takes the x and y coordinates of the needle as well as the radial and angular displacement between the needle and the beginning of the desired song. The new coordinates should be returned as a tuple.
0 commit comments