2
2
# ## 2D Coordinate systems ###
3
3
# ############################
4
4
"""
5
- `Polar{T,A}(r::T, θ::A)` - 2D polar coordinates
5
+ Polar{T,A}(r::T, θ::A)
6
+
7
+ 2D polar coordinates
6
8
"""
7
9
struct Polar{T,A}
8
10
r:: T
@@ -18,7 +20,9 @@ function Polar(r, θ)
18
20
end
19
21
20
22
"""
21
- `Polar{T,T}(x::AbstractVector)` - 2D polar coordinates from an AbstractVector of length 2
23
+ Polar{T,T}(x::AbstractVector)
24
+
25
+ 2D polar coordinates from an AbstractVector of length 2
22
26
"""
23
27
function Polar (x:: AbstractVector )
24
28
return PolarFromCartesian ()(x)
27
31
Base. show (io:: IO , x:: Polar ) = print (io, " Polar(r=$(x. r) , θ=$(x. θ) rad)" )
28
32
Base. isapprox (p1:: Polar , p2:: Polar ; kwargs... ) = isapprox (p1. r, p2. r; kwargs... ) && isapprox (p1. θ, p2. θ; kwargs... )
29
33
30
- " `PolarFromCartesian()` - transformation from `AbstractVector` of length 2 to `Polar` type"
34
+ """
35
+ PolarFromCartesian()
36
+
37
+ Transformation from `AbstractVector` of length 2 to `Polar` type
38
+ """
31
39
struct PolarFromCartesian <: Transformation ; end
32
- " `CartesianFromPolar()` - transformation from `Polar` type to `SVector{2}` type"
40
+ """
41
+ CartesianFromPolar()
42
+
43
+ Transformation from `Polar` type to `SVector{2}` type
44
+ """
33
45
struct CartesianFromPolar <: Transformation ; end
34
46
35
47
Base. show (io:: IO , trans:: PolarFromCartesian ) = print (io, " PolarFromCartesian()" )
@@ -79,10 +91,13 @@ Base.convert(::Type{Polar}, v::AbstractVector) = PolarFromCartesian()(v)
79
91
# ## 3D Coordinate Systems ###
80
92
# ############################
81
93
"""
82
- Spherical(r, θ, ϕ) - 3D spherical coordinates
94
+ Spherical(r, θ, ϕ)
95
+
96
+ 3D spherical coordinates
83
97
84
98
There are many Spherical coordinate conventions and this library uses a somewhat exotic one.
85
- Given a vector `v` with Cartesian coordinates `xyz`, let `v_xy = [x,y,0]` be the orthogonal projection of `v` on the `xy` plane.
99
+ Given a vector `v` with Cartesian coordinates `xyz`, let `v_xy = [x,y,0]` be the
100
+ orthogonal projection of `v` on the `xy` plane.
86
101
87
102
* `r` is the radius. It is given by `norm(v, 2)`.
88
103
* `θ` is the azimuth. It is the angle from the x-axis to `v_xy`
@@ -95,10 +110,11 @@ julia> v = randn(3);
95
110
96
111
julia> sph = SphericalFromCartesian()(v);
97
112
98
- julia> r = sph.r; θ= sph.θ; ϕ= sph.ϕ;
113
+ julia> r = sph.r; θ = sph.θ; ϕ = sph.ϕ;
99
114
100
- julia> v ≈ [r * cos(θ) * cos(ϕ), r * sin(θ) * cos(ϕ), r* sin(ϕ)]
115
+ julia> v ≈ [r * cos(θ) * cos(ϕ), r * sin(θ) * cos(ϕ), r * sin(ϕ)]
101
116
true
117
+ ```
102
118
"""
103
119
struct Spherical{T,A}
104
120
r:: T
@@ -118,7 +134,9 @@ Base.show(io::IO, x::Spherical) = print(io, "Spherical(r=$(x.r), θ=$(x.θ) rad,
118
134
Base. isapprox (p1:: Spherical , p2:: Spherical ; kwargs... ) = isapprox (p1. r, p2. r; kwargs... ) && isapprox (p1. θ, p2. θ; kwargs... ) && isapprox (p1. ϕ, p2. ϕ; kwargs... )
119
135
120
136
"""
121
- Cylindrical(r, θ, z) - 3D cylindrical coordinates
137
+ Cylindrical(r, θ, z)
138
+
139
+ 3D cylindrical coordinates
122
140
"""
123
141
struct Cylindrical{T,A}
124
142
r:: T
@@ -137,17 +155,41 @@ end
137
155
Base. show (io:: IO , x:: Cylindrical ) = print (io, " Cylindrical(r=$(x. r) , θ=$(x. θ) rad, z=$(x. z) )" )
138
156
Base. isapprox (p1:: Cylindrical , p2:: Cylindrical ; kwargs... ) = isapprox (p1. r, p2. r; kwargs... ) && isapprox (p1. θ, p2. θ; kwargs... ) && isapprox (p1. z, p2. z; kwargs... )
139
157
140
- " `SphericalFromCartesian()` - transformation from 3D point to `Spherical` type"
158
+ """
159
+ SphericalFromCartesian()
160
+
161
+ Transformation from 3D point to `Spherical` type
162
+ """
141
163
struct SphericalFromCartesian <: Transformation ; end
142
- " `CartesianFromSpherical()` - transformation from `Spherical` type to `SVector{3}` type"
164
+ """
165
+ CartesianFromSpherical()
166
+
167
+ Transformation from `Spherical` type to `SVector{3}` type
168
+ """
143
169
struct CartesianFromSpherical <: Transformation ; end
144
- " `CylindricalFromCartesian()` - transformation from 3D point to `Cylindrical` type"
170
+ """
171
+ CylindricalFromCartesian()
172
+
173
+ Transformation from 3D point to `Cylindrical` type
174
+ """
145
175
struct CylindricalFromCartesian <: Transformation ; end
146
- " `CartesianFromCylindrical()` - transformation from `Cylindrical` type to `SVector{3}` type"
176
+ """
177
+ CartesianFromCylindrical()
178
+
179
+ Transformation from `Cylindrical` type to `SVector{3}` type
180
+ """
147
181
struct CartesianFromCylindrical <: Transformation ; end
148
- " `CylindricalFromSpherical()` - transformation from `Spherical` type to `Cylindrical` type"
182
+ """
183
+ CylindricalFromSpherical()
184
+
185
+ Transformation from `Spherical` type to `Cylindrical` type
186
+ """
149
187
struct CylindricalFromSpherical <: Transformation ; end
150
- " `SphericalFromCylindrical()` - transformation from `Cylindrical` type to `Spherical` type"
188
+ """
189
+ SphericalFromCylindrical()
190
+
191
+ Transformation from `Cylindrical` type to `Spherical` type
192
+ """
151
193
struct SphericalFromCylindrical <: Transformation ; end
152
194
153
195
Base. show (io:: IO , trans:: SphericalFromCartesian ) = print (io, " SphericalFromCartesian()" )
0 commit comments