22# ## 2D Coordinate systems ###
33# ############################
44"""
5- `Polar{T,A}(r::T, θ::A)` - 2D polar coordinates
5+ Polar{T,A}(r::T, θ::A)
6+
7+ 2D polar coordinates
68"""
79struct Polar{T,A}
810 r:: T
@@ -18,7 +20,9 @@ function Polar(r, θ)
1820end
1921
2022"""
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
2226"""
2327function Polar (x:: AbstractVector )
2428 return PolarFromCartesian ()(x)
2731Base. show (io:: IO , x:: Polar ) = print (io, " Polar(r=$(x. r) , θ=$(x. θ) rad)" )
2832Base. isapprox (p1:: Polar , p2:: Polar ; kwargs... ) = isapprox (p1. r, p2. r; kwargs... ) && isapprox (p1. θ, p2. θ; kwargs... )
2933
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+ """
3139struct 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+ """
3345struct CartesianFromPolar <: Transformation ; end
3446
3547Base. show (io:: IO , trans:: PolarFromCartesian ) = print (io, " PolarFromCartesian()" )
@@ -79,10 +91,13 @@ Base.convert(::Type{Polar}, v::AbstractVector) = PolarFromCartesian()(v)
7991# ## 3D Coordinate Systems ###
8092# ############################
8193"""
82- Spherical(r, θ, ϕ) - 3D spherical coordinates
94+ Spherical(r, θ, ϕ)
95+
96+ 3D spherical coordinates
8397
8498There 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.
86101
87102* `r` is the radius. It is given by `norm(v, 2)`.
88103* `θ` is the azimuth. It is the angle from the x-axis to `v_xy`
@@ -95,10 +110,11 @@ julia> v = randn(3);
95110
96111julia> sph = SphericalFromCartesian()(v);
97112
98- julia> r = sph.r; θ= sph.θ; ϕ= sph.ϕ;
113+ julia> r = sph.r; θ = sph.θ; ϕ = sph.ϕ;
99114
100- julia> v ≈ [r * cos(θ) * cos(ϕ), r * sin(θ) * cos(ϕ), r* sin(ϕ)]
115+ julia> v ≈ [r * cos(θ) * cos(ϕ), r * sin(θ) * cos(ϕ), r * sin(ϕ)]
101116true
117+ ```
102118"""
103119struct Spherical{T,A}
104120 r:: T
@@ -118,7 +134,9 @@ Base.show(io::IO, x::Spherical) = print(io, "Spherical(r=$(x.r), θ=$(x.θ) rad,
118134Base. isapprox (p1:: Spherical , p2:: Spherical ; kwargs... ) = isapprox (p1. r, p2. r; kwargs... ) && isapprox (p1. θ, p2. θ; kwargs... ) && isapprox (p1. ϕ, p2. ϕ; kwargs... )
119135
120136"""
121- Cylindrical(r, θ, z) - 3D cylindrical coordinates
137+ Cylindrical(r, θ, z)
138+
139+ 3D cylindrical coordinates
122140"""
123141struct Cylindrical{T,A}
124142 r:: T
@@ -137,17 +155,41 @@ end
137155Base. show (io:: IO , x:: Cylindrical ) = print (io, " Cylindrical(r=$(x. r) , θ=$(x. θ) rad, z=$(x. z) )" )
138156Base. isapprox (p1:: Cylindrical , p2:: Cylindrical ; kwargs... ) = isapprox (p1. r, p2. r; kwargs... ) && isapprox (p1. θ, p2. θ; kwargs... ) && isapprox (p1. z, p2. z; kwargs... )
139157
140- " `SphericalFromCartesian()` - transformation from 3D point to `Spherical` type"
158+ """
159+ SphericalFromCartesian()
160+
161+ Transformation from 3D point to `Spherical` type
162+ """
141163struct 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+ """
143169struct 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+ """
145175struct 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+ """
147181struct 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+ """
149187struct 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+ """
151193struct SphericalFromCylindrical <: Transformation ; end
152194
153195Base. show (io:: IO , trans:: SphericalFromCartesian ) = print (io, " SphericalFromCartesian()" )
0 commit comments