# DeformableBodies

## Model

`DeformableBodies.Model`

— Type`Model`

**Fields**

`bodyframe`

– Function representing trajectory on reference frame rotating with the body.`timespan`

– Tuple containing starting and ending time of motion.`q_0`

– Quaternion representing initial rotation.`L_cm`

– Vector of angular momentum in relation to center of mass.

Only Initialized after solve:

`inertialframe`

– Function representing trajectory on inertial reference frame.`rotation`

– Rotations that exchange between`bodyframe`

and`inertialframe`

.`momentum`

– Internal angular momentum.

Store the data of a deformable body problem before and after solving.

`DeformableBodies.solve!`

— Function`solve!(m::Model; reltol=1e-8, abstol=1e-8, solver=Tsit5())`

Receive a `Model`

, calculate the trajectory of the body on an inertial frame and store it in the variable `m.inertialframe`

.

## Operators from mechanics

`DeformableBodies.PointMass`

— Type`PointMass(m, x)`

Wrapper over a mass and a position on $R^3$.

This type overloads `Quaternions.rotate`

to rotate only its position.

```
julia> a = PointMass(10, [1., 0, 0])
PointMass{Float64}(10.0, [1.0, 0.0, 0.0])
julia> rotate(a; axis=[0., 0., 1.], angle=π/2)
PointMass{Float64}(10.0, [2.220446049250313e-16, 1.0, 0.0])
```

`DeformableBodies.pos`

— Function`pos(p::PointMass)`

Return position of a `PointMass`

.

`DeformableBodies.mass`

— Function`mass(p::PointMass)`

Return mass of a `PointMass`

.

`DeformableBodies.center_of_mass`

— Function`center_of_mass(xs)`

Receive a system of `PointMass`

es and return their center of mass through formula

`DeformableBodies.inertia_tensor`

— Function`inertia_tensor(xs)`

Receive a system of `PointMass`

es and return their inertia tensor through formula

`DeformableBodies.angular_momentum`

— Function`angular_momentum(xs, vs)`

Receive a system of `PointMass`

es and their velocities, and return their angular momentum vector through formula

`DeformableBodies.centralize`

— Function`centralize(xs)`

Receive a system of `PointMass`

es and translate it such that the center of mass is fixed on the origin.

`DeformableBodies.velocity`

— Function`velocity(xs, t; δ=1e-6)`

Numerically approximate the velocity for a set `xs`

of trajectories at time `t`

. The variable `δ`

denotes the step for the finite differences interval.

## Plotting a model

`DeformableBodies.plotmodel`

— Method`plotmodel(model, SoR; kw...)`

Receive a `Model`

and return a `Plots.Animation`

from its data.

**Arguments**

`SoR`

: means "system of reference" and accepts one of the following symbols:`:bodyframe`

,`:inertialframe`

,`:both`

.`fps`

: frames per second. Default is`24`

.`duration`

: length of animation in seconds. Default is the total timespan stored in`m`

.`saveas`

: filename to save animation, supported extensions are gif, mp4 or mov. If left blank, file is not saved.`bodylines`

: Array of points pairs. Stores the data who says which points should be linked. Default is empty.`markersize_is_mass`

: Says if attribute`markersize`

should be weighted by the mass of each particle. Default is`true`

.

Additionally, any keyword argument supported by `Plots.plot`

is accepted and will be repassed to the plot.

**Examples**

`julia> plotmodel(m, :both, fps=15, saveas="example.gif", color=:green,viewangle=(30,60))`

`DeformableBodies.saveanimation`

— Method`saveanimation(anime, saveas; fps=30)`

Receive an `Plots.Animation`

and save it as a file.

Supported formats are 'gif', 'mp4' and 'mov'. The extension is automatically detected from `saveas`

and, in case of ambiguity, defaults to '.gif'.