Skip to content

Commit

Permalink
Merge pull request #607 from JuliaRobotics/tk/faster-transform-inertia
Browse files Browse the repository at this point in the history
Better way to transform spatial inertias
  • Loading branch information
tkoolen authored Feb 3, 2021
2 parents 19a512c + 9700a87 commit 870bea6
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/spatial/motion_force_interaction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,19 @@ Transform the `SpatialInertia` to a different frame.
@inline function transform(inertia::SpatialInertia, t::Transform3D)
@framecheck(t.from, inertia.frame)
J = inertia.moment
mc = inertia.cross_part
m = inertia.mass
c = inertia.cross_part
R = rotation(t)
p = translation(t)
cnew = R * c
Jnew = hat_squared(cnew)
cnew += m * p
Jnew -= hat_squared(cnew)
minv = m > 0 ? inv(m) : zero(m)
Jnew *= minv
Jnew += R * J * R'
SpatialInertia(t.to, Jnew, cnew, convert(eltype(Jnew), m))

Rmc = R * mc
mp = m * p
mcnew = Rmc + mp
X = Rmc * transpose(p)
Y = X + transpose(X) + mp * transpose(p)
Jnew = R * J * transpose(R) - Y + tr(Y) * I

SpatialInertia(t.to, Jnew, mcnew, m)
end

function Random.rand(::Type{<:SpatialInertia{T}}, frame::CartesianFrame3D) where {T}
Expand Down

0 comments on commit 870bea6

Please sign in to comment.