-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from davibarreira/arc-primitive
Ellipse primitive
- Loading branch information
Showing
8 changed files
with
181 additions
and
12 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
struct Ellipse <: GeometricPrimitive | ||
rx::Real # Semi-major axis | ||
ry::Real # Semi-minor axis | ||
c::Vector # Center of the ellipse | ||
ang::Real | ||
end | ||
|
||
# Constructor for Ellipse with default values | ||
Ellipse(; rx=2, ry=1, c=[0, 0], ang=0) = Ellipse(rx, ry, c, ang) | ||
|
||
# Covariant representation of an Ellipse (CovEllipse) | ||
# <rx_vec, ry_vec> = 0 (inner product is zero, both vectors are perpendicular) | ||
struct CovEllipse | ||
_1::Vector # rx_vec | ||
_2::Vector # ry_vec | ||
_3::Vector # center | ||
end | ||
|
||
# Action of a transformation group on CovEllipse | ||
act(g::G, x::CovEllipse) = CovEllipse(g(x._1), g(x._2), g(x._3)) | ||
|
||
# Mapping from CovEllipse to Ellipse | ||
ψ(p::CovEllipse) = Ellipse(norm(p._1 - p._3), norm(p._2 - p._3), p._3, atan2pi(p._1 - p._3)) | ||
|
||
# Mapping from Ellipse to CovEllipse | ||
function ϕ(p::Ellipse) | ||
return CovEllipse( | ||
rotatevec([p.rx, 0], p.ang) + p.c, rotatevec([0, p.ry], p.ang) + p.c, p.c | ||
) | ||
end | ||
|
||
# """ | ||
# coordinates(p::Ellipse) | ||
# Generate points in the ellipse. | ||
# """ | ||
# function coordinates(p::Ellipse) | ||
# a = p.rx | ||
# b = p.ry | ||
# c = p.c | ||
# ang = p.ang | ||
# return pts = [R(ang)([a * cos(θ), b * sin(θ)]) + c for θ in 0:(2π / 100):(2π)] | ||
# end |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import Vizagrams: CovEllipse, ϕ, ψ, coordinates | ||
|
||
# Test default constructor | ||
@testset "Ellipse Default Constructor" begin | ||
e = Ellipse() | ||
@test e.rx == 2 | ||
@test e.ry == 1 | ||
@test e.c == [0, 0] | ||
@test e.ang == 0 | ||
end | ||
|
||
# Test custom constructor | ||
@testset "Ellipse Custom Constructor" begin | ||
e = Ellipse(rx=3, ry=4, c=[1, 2], ang=π/4) | ||
@test e.rx == 3 | ||
@test e.ry == 4 | ||
@test e.c == [1, 2] | ||
@test e.ang == π/4 | ||
end | ||
|
||
# Test CovEllipse to Ellipse mapping | ||
@testset "CovEllipse to Ellipse Mapping" begin | ||
cov_e = CovEllipse([3, 0], [0, 4], [1, 2]) | ||
e = ψ(cov_e) | ||
@test e.rx ≈ 3 | ||
@test e.ry ≈ 4 | ||
@test e.c == [1, 2] | ||
@test e.ang ≈ 0 | ||
end | ||
|
||
# Test Ellipse to CovEllipse mapping | ||
@testset "Ellipse to CovEllipse Mapping" begin | ||
e = Ellipse(rx=3, ry=4, c=[1, 2], ang=π/4) | ||
cov_e = ϕ(e) | ||
@test cov_e._1 ≈ rotatevec([3, 0], π/4) + [1, 2] | ||
@test cov_e._2 ≈ rotatevec([0, 4], π/4) + [1, 2] | ||
@test cov_e._3 == [1, 2] | ||
end |
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