Skip to content

Commit

Permalink
Add Rotation exp/log aliases (fixes #90)
Browse files Browse the repository at this point in the history
I intend for the geometry classes to have sound foundations while
also being easy to use in the common setting of building trajectories.
Most users won't be invoking methods directly on the geometry classes,
so I took the liberty of keeping technical Lie theory names.

I still like that decision overall, though I'm happy to enhance usability
by providing aliases. In this case, I settled on `fromDouble()` and
`toDouble()` for the `Rotation2d` `exp()`/`log()` functions.
  • Loading branch information
rbrott committed Nov 21, 2023
1 parent 9c2a628 commit 31cae32
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/src/main/kotlin/com/acmerobotics/roadrunner/Geometry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ data class Rotation2d(@JvmField val real: Double, @JvmField val imag: Double) {
*/
@JvmStatic
fun exp(theta: Double) = Rotation2d(cos(theta), sin(theta))

/**
* Alias for [exp].
*/
@JvmStatic
fun fromDouble(theta: Double) = exp(theta)
}

operator fun plus(x: Double) = this * exp(x)
Expand All @@ -97,6 +103,11 @@ data class Rotation2d(@JvmField val real: Double, @JvmField val imag: Double) {
* Get the rotation as a normalized [Double].
*/
fun log() = atan2(imag, real)

/**
* Alias for [log].
*/
fun toDouble() = log()
}

/**
Expand Down

0 comments on commit 31cae32

Please sign in to comment.