Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation website and docstrings #93

Merged
merged 3 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@

*Manifest.toml
*.swp

/docs/build
2 changes: 2 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
10 changes: 10 additions & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Documenter
using CoordinateTransformations

makedocs(
sitename = "CoordinateTransformations.jl",
pages = [
"Introduction" => "index.md",
"API" => "api.md",
],
)
7 changes: 7 additions & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# CoordinateTransformations.jl documentation

## API Reference

```@autodocs
Modules = [CoordinateTransformations]
```
1 change: 1 addition & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# CoordinateTransformations.jl
8 changes: 4 additions & 4 deletions src/affine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ abstract type AbstractAffineMap <: Transformation end

"""
Translation(v) <: AbstractAffineMap
Translation(dx, dy) (2D)
Translation(dx, dy, dz) (3D)
Translation(dx, dy) # 2D
Translation(dx, dy, dz) # 3D

Construct the `Translation` transformation for translating Cartesian points by
an offset `v = (dx, dy, ...)`
Expand Down Expand Up @@ -215,8 +215,8 @@ transform_deriv(trans::AffineMap, x) = trans.linear

Create an Affine transformation that approximately maps the `from` points to the `to` points.
At least `n+1` non-degenerate points are required to map an `n`-dimensional space.
If there are more points than this, the transformation will be over-determined and a least-squares
solution will be computed.
If there are more points than this, the transformation will be over-determined
and a least-squares solution will be computed.
"""
function AffineMap((from_points,to_points)::Pair)
M = column_matrix(to_points) * pinv(column_matrix(from_points, 1))
Expand Down
72 changes: 57 additions & 15 deletions src/coordinatesystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
### 2D Coordinate systems ###
#############################
"""
`Polar{T,A}(r::T, θ::A)` - 2D polar coordinates
Polar{T,A}(r::T, θ::A)

2D polar coordinates
"""
struct Polar{T,A}
r::T
Expand All @@ -18,7 +20,9 @@ function Polar(r, θ)
end

"""
`Polar{T,T}(x::AbstractVector)` - 2D polar coordinates from an AbstractVector of length 2
Polar{T,T}(x::AbstractVector)

2D polar coordinates from an AbstractVector of length 2
"""
function Polar(x::AbstractVector)
return PolarFromCartesian()(x)
Expand All @@ -27,9 +31,17 @@ end
Base.show(io::IO, x::Polar) = print(io, "Polar(r=$(x.r), θ=$(x.θ) rad)")
Base.isapprox(p1::Polar, p2::Polar; kwargs...) = isapprox(p1.r, p2.r; kwargs...) && isapprox(p1.θ, p2.θ; kwargs...)

"`PolarFromCartesian()` - transformation from `AbstractVector` of length 2 to `Polar` type"
"""
PolarFromCartesian()

Transformation from `AbstractVector` of length 2 to `Polar` type
"""
struct PolarFromCartesian <: Transformation; end
"`CartesianFromPolar()` - transformation from `Polar` type to `SVector{2}` type"
"""
CartesianFromPolar()

Transformation from `Polar` type to `SVector{2}` type
"""
struct CartesianFromPolar <: Transformation; end

Base.show(io::IO, trans::PolarFromCartesian) = print(io, "PolarFromCartesian()")
Expand Down Expand Up @@ -79,10 +91,13 @@ Base.convert(::Type{Polar}, v::AbstractVector) = PolarFromCartesian()(v)
### 3D Coordinate Systems ###
#############################
"""
Spherical(r, θ, ϕ) - 3D spherical coordinates
Spherical(r, θ, ϕ)

3D spherical coordinates

There are many Spherical coordinate conventions and this library uses a somewhat exotic one.
Given a vector `v` with Cartesian coordinates `xyz`, let `v_xy = [x,y,0]` be the orthogonal projection of `v` on the `xy` plane.
Given a vector `v` with Cartesian coordinates `xyz`, let `v_xy = [x,y,0]` be the
orthogonal projection of `v` on the `xy` plane.

* `r` is the radius. It is given by `norm(v, 2)`.
* `θ` is the azimuth. It is the angle from the x-axis to `v_xy`
Expand All @@ -95,10 +110,11 @@ julia> v = randn(3);

julia> sph = SphericalFromCartesian()(v);

julia> r = sph.r; θ=sph.θ; ϕ=sph.ϕ;
julia> r = sph.r; θ = sph.θ; ϕ = sph.ϕ;

julia> v ≈ [r * cos(θ) * cos(ϕ), r * sin(θ) * cos(ϕ), r*sin(ϕ)]
julia> v ≈ [r * cos(θ) * cos(ϕ), r * sin(θ) * cos(ϕ), r * sin(ϕ)]
true
```
"""
struct Spherical{T,A}
r::T
Expand All @@ -118,7 +134,9 @@ Base.show(io::IO, x::Spherical) = print(io, "Spherical(r=$(x.r), θ=$(x.θ) rad,
Base.isapprox(p1::Spherical, p2::Spherical; kwargs...) = isapprox(p1.r, p2.r; kwargs...) && isapprox(p1.θ, p2.θ; kwargs...) && isapprox(p1.ϕ, p2.ϕ; kwargs...)

"""
Cylindrical(r, θ, z) - 3D cylindrical coordinates
Cylindrical(r, θ, z)

3D cylindrical coordinates
"""
struct Cylindrical{T,A}
r::T
Expand All @@ -137,17 +155,41 @@ end
Base.show(io::IO, x::Cylindrical) = print(io, "Cylindrical(r=$(x.r), θ=$(x.θ) rad, z=$(x.z))")
Base.isapprox(p1::Cylindrical, p2::Cylindrical; kwargs...) = isapprox(p1.r, p2.r; kwargs...) && isapprox(p1.θ, p2.θ; kwargs...) && isapprox(p1.z, p2.z; kwargs...)

"`SphericalFromCartesian()` - transformation from 3D point to `Spherical` type"
"""
SphericalFromCartesian()

Transformation from 3D point to `Spherical` type
"""
struct SphericalFromCartesian <: Transformation; end
"`CartesianFromSpherical()` - transformation from `Spherical` type to `SVector{3}` type"
"""
CartesianFromSpherical()

Transformation from `Spherical` type to `SVector{3}` type
"""
struct CartesianFromSpherical <: Transformation; end
"`CylindricalFromCartesian()` - transformation from 3D point to `Cylindrical` type"
"""
CylindricalFromCartesian()

Transformation from 3D point to `Cylindrical` type
"""
struct CylindricalFromCartesian <: Transformation; end
"`CartesianFromCylindrical()` - transformation from `Cylindrical` type to `SVector{3}` type"
"""
CartesianFromCylindrical()

Transformation from `Cylindrical` type to `SVector{3}` type
"""
struct CartesianFromCylindrical <: Transformation; end
"`CylindricalFromSpherical()` - transformation from `Spherical` type to `Cylindrical` type"
"""
CylindricalFromSpherical()

Transformation from `Spherical` type to `Cylindrical` type
"""
struct CylindricalFromSpherical <: Transformation; end
"`SphericalFromCylindrical()` - transformation from `Cylindrical` type to `Spherical` type"
"""
SphericalFromCylindrical()

Transformation from `Cylindrical` type to `Spherical` type
"""
struct SphericalFromCylindrical <: Transformation; end

Base.show(io::IO, trans::SphericalFromCartesian) = print(io, "SphericalFromCartesian()")
Expand Down
11 changes: 6 additions & 5 deletions src/perspective.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ This transformation is designed to be used in composition with other coordinate
transformations, defining e.g. the position and orientation of the camera. For
example:

cam_transform = PerspectiveMap() ∘ inv(AffineMap(cam_rotation, cam_position))
screen_points = map(cam_transform, points)
```julia
cam_transform = PerspectiveMap() ∘ inv(AffineMap(cam_rotation, cam_position))
screen_points = map(cam_transform, points)
```

(see also `cameramap`)
(see also [`cameramap`](@ref))
"""
struct PerspectiveMap <: Transformation
end
Expand Down Expand Up @@ -55,7 +57,7 @@ plane. For instance, you may wish to have the point (0,0) represent the top-left
corner of your imaging sensor. This measurement is in the units after applying
`scale` (e.g. pixels).

(see also `PerspectiveMap`)
(see also [`PerspectiveMap`](@ref))
"""
cameramap() = PerspectiveMap()
cameramap(scale::Number) =
Expand All @@ -66,4 +68,3 @@ cameramap(scale::Number, offset::Tuple{Number,Number}) =
AffineMap(UniformScaling(scale), SVector(-offset[1], -offset[2])) ∘ PerspectiveMap()
cameramap(scale::Tuple{Number, Number}, offset::Tuple{Number,Number}) =
AffineMap(@SMatrix([scale[1] 0; 0 scale[2]]), SVector(-offset[1], -offset[2])) ∘ PerspectiveMap()

Loading