Skip to content

Commit

Permalink
add power methods
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrodium committed Sep 20, 2023
1 parent daa50b1 commit 71ebd5f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
5 changes: 0 additions & 5 deletions src/angleaxis_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ end
@inline Base.:*(aa1::AngleAxis, aa2::AngleAxis) = QuatRotation(aa1) * QuatRotation(aa2)

@inline Base.inv(aa::AngleAxis) = AngleAxis(-aa.theta, aa.axis_x, aa.axis_y, aa.axis_z)
@inline Base.:^(aa::AngleAxis, t::Real) = AngleAxis(aa.theta*t, aa.axis_x, aa.axis_y, aa.axis_z)
@inline Base.:^(aa::AngleAxis, t::Integer) = AngleAxis(aa.theta*t, aa.axis_x, aa.axis_y, aa.axis_z) # to avoid ambiguity


# define identity rotations for convenience
@inline Base.one(::Type{AngleAxis}) = AngleAxis(0.0, 1.0, 0.0, 0.0)
Expand Down Expand Up @@ -204,8 +201,6 @@ end
@inline Base.:*(rv1::RotationVec, rv2::RotationVec) = QuatRotation(rv1) * QuatRotation(rv2)

@inline Base.inv(rv::RotationVec) = RotationVec(-rv.sx, -rv.sy, -rv.sz)
@inline Base.:^(rv::RotationVec, t::Real) = RotationVec(rv.sx*t, rv.sy*t, rv.sz*t)
@inline Base.:^(rv::RotationVec, t::Integer) = RotationVec(rv.sx*t, rv.sy*t, rv.sz*t) # to avoid ambiguity

# rotation properties
@inline rotation_angle(rv::RotationVec) = sqrt(rv.sx * rv.sx + rv.sy * rv.sy + rv.sz * rv.sz)
Expand Down
2 changes: 0 additions & 2 deletions src/core_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ end
end

Base.:*(r1::Angle2d, r2::Angle2d) = Angle2d(r1.theta + r2.theta)
Base.:^(r::Angle2d, t::Real) = Angle2d(r.theta*t)
Base.:^(r::Angle2d, t::Integer) = Angle2d(r.theta*t)
Base.inv(r::Angle2d) = Angle2d(-r.theta)

@inline function Base.getindex(r::Angle2d, i::Int)
Expand Down
33 changes: 33 additions & 0 deletions src/elementary_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,36 @@ Base.cbrt(r::Rotation{3}) = cbrt(QuatRotation(r))

# General dimensions
Base.cbrt(r::Rotation{N}) where N = exp(log(r)/3)

Check warning on line 82 in src/elementary_functions.jl

View check run for this annotation

Codecov / codecov/patch

src/elementary_functions.jl#L82

Added line #L82 was not covered by tests

## power
# 2d
Base.:^(r::Angle2d, p::Real) = Angle2d(r.theta*p)
Base.:^(r::Angle2d, p::Integer) = Angle2d(r.theta*p)
Base.:^(r::RotMatrix{2}, p::Real) = RotMatrix(Angle2d(r)^p)
Base.:^(r::RotMatrix{2}, p::Integer) = RotMatrix(Angle2d(r)^p)

Check warning on line 89 in src/elementary_functions.jl

View check run for this annotation

Codecov / codecov/patch

src/elementary_functions.jl#L88-L89

Added lines #L88 - L89 were not covered by tests

# 3d
Base.:^(r::RotX, p::Real) = RotX(r.theta*p)
Base.:^(r::RotX, p::Integer) = RotX(r.theta*p)
Base.:^(r::RotY, p::Real) = RotY(r.theta*p)
Base.:^(r::RotY, p::Integer) = RotY(r.theta*p)
Base.:^(r::RotZ, p::Real) = RotZ(r.theta*p)
Base.:^(r::RotZ, p::Integer) = RotZ(r.theta*p)
Base.:^(r::AngleAxis, p::Real) = AngleAxis(r.theta*p, r.axis_x, r.axis_y, r.axis_z)
Base.:^(r::AngleAxis, p::Integer) = AngleAxis(r.theta*p, r.axis_x, r.axis_y, r.axis_z)
Base.:^(r::RotationVec, p::Real) = RotaitonVec(r.sx*p, r.sy*p, r.sz*p)
Base.:^(r::RotationVec, p::Integer) = RotaitonVec(r.sx*p, r.sy*p, r.sz*p)
Base.:^(r::QuatRotation, p::Real) = QuatRotation((r.q)^p)
Base.:^(r::QuatRotation, p::Integer) = QuatRotation((r.q)^p)
Base.:^(r::RotMatrix{3}, p::Real) = RotMatrix{3}(QuatRotation(r)^p)
Base.:^(r::RotMatrix{3}, p::Integer) = RotMatrix{3}(QuatRotation(r)^p)
Base.:^(r::RodriguesParam, p::Real) = RodriguesParam(QuatRotation(r)^p)
Base.:^(r::RodriguesParam, p::Integer) = RodriguesParam(QuatRotation(r)^p)
Base.:^(r::MRP, p::Real) = MRP(QuatRotation(r)^p)
Base.:^(r::MRP, p::Integer) = MRP(QuatRotation(r)^p)
Base.:^(r::Rotation{3}, p::Real) = QuatRotation(r)^p
Base.:^(r::Rotation{3}, p::Integer) = QuatRotation(r)^p

Check warning on line 111 in src/elementary_functions.jl

View check run for this annotation

Codecov / codecov/patch

src/elementary_functions.jl#L92-L111

Added lines #L92 - L111 were not covered by tests

# General dimensions
Base.:^(r::Rotation{N}, p::Real) where N = exp(log(r)*p)
Base.:^(r::Rotation{N}, p::Integer) where N = Rotation{N}(r^p)

Check warning on line 115 in src/elementary_functions.jl

View check run for this annotation

Codecov / codecov/patch

src/elementary_functions.jl#L114-L115

Added lines #L114 - L115 were not covered by tests

0 comments on commit 71ebd5f

Please sign in to comment.