Skip to content

Commit 225ae81

Browse files
committed
Update test examples and Readme.md
1 parent 4926007 commit 225ae81

File tree

3 files changed

+192
-120
lines changed

3 files changed

+192
-120
lines changed

Readme.md

Lines changed: 21 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,15 @@
11
# Class for calculating Instantaneous Axis of Rotation
22

3-
The instantaneous axis of rotation between two bodies is a useful concept in
4-
biomechanics. In this post, we will dig into how to calculate the instantaneous
5-
axis of rotation and show off an AnyScript `class_template` to do this
6-
calculation and plot the axis between any two reference frames in the AnyBody
7-
Modeling System.
8-
9-
The are several papers that discusses the
10-
importance of the instantaneous axis of rotation in biomechanics. See for
11-
example XX and XX. But first, let us look briefly at the math behind.
12-
13-
## 3D Rotations
14-
15-
We can view any displacement of a body in a three-dimensional space as rotation
16-
around a single axis and a translation along that axis. This gives rise to the
17-
idea of a screw motion in 3D along what is also called the helical axis. If we
18-
spit the movement up into infinitesimally small movements each of these will
19-
have an rotation axis and a linear velocity along that axis. This is the
20-
instantaneous axis of rotation, and as the name indicate will change direction
21-
and location as the object moves.
22-
23-
If we know the angular and linear velocity of any point on a rigid body, we can
24-
calculate the properties of the screw motion and the instantaneous axis of
25-
rotation.
26-
27-
From a mathematical point of view the rate of change of a 3x3 rotation matrix
28-
$R$ is:
29-
30-
$$ \frac{{\mathrm d}}{{\mathrm d}t}R = \vec{\omega} \times R$$
31-
32-
where $\vec{\omega}$ is called the angular velocity vector. This angular
33-
velocity is quantity shared by all points on the rigid body (including those on
34-
the rotation axis). Using $\vec{\omega}$ we can write the linear velocity
35-
$\vec{v}$ of any point at some distance $\vec{r} from the instantaneous axis of
36-
rotation as:
37-
38-
$$\vec{v} = \vec{\omega} \times \vec{r}$$ (1)
39-
40-
Similarly we can also calculate backwards and find the intantanous axis of
41-
rotation at some distance $-\vec{r}$ from any point if we know the linear
42-
velocity of the point and the angular velocity:
43-
44-
This is given by:
45-
46-
$$
47-
-\vec{r}= \frac{\vec{\omega} \times \vec{v} }{ \vec{\omega}\cdot\vec{\omega} }
48-
$$
49-
50-
Here is short proof. Skip it if you like:
51-
52-
>Start with $\vec{\omega} \times \vec{v}$, insert (1) and use the tripple product to expand it:
53-
>$$
54-
>\vec{\omega} \times \vec{v} = \vec{\omega} \times (\vec{\omega} \times \vec{r})=\vec{\omega}(\vec{\omega}\cdot\vec{r})-\vec{r}(\vec{\omega}\cdot\vec>{\omega})
55-
>$$
56-
>
57-
>The shortest vector $\vec{r}$ from the rotation axis to any point is by defintion perpendicular to angular velocity $\vec{\omega}$, hence:
58-
>
59-
>$$
60-
>\require{cancel}\vec{\omega} \times \vec{v} =\vec{\omega}(\cancel{\vec{\omega}\cdot\vec{r}})-\vec{r}(\vec{\omega}\cdot\vec{\omega})=-r(\vec{\omega}>\cdot\vec{\omega})
61-
>$$
62-
63-
64-
65-
Thus if know the position of a point $\vec{r}_P$ we can find closest point
66-
$\vec{r}_C$ on the rotation axis as:
67-
68-
$$\vec{r}_C = \vec{r}_P - \vec{r} = \vec{r}_P + \frac{\vec{\omega}\times\vec{v}_P}{\vec{\omega}\cdot\vec{\omega}}$$
69-
70-
71-
72-
## Properties
73-
74-
If for example we have a rigid body with angular velocity $\vec{\omega}$ and
75-
some point $P$ with position $\vec{r}_P$ and velocity $\vec{v}_p$ then we can
76-
define the different properties:
77-
78-
1. The magintude of agular rotation:
79-
$$ \omega = \|\vec{\omega}\|$$
80-
81-
2. The direction of the intantanous axis of rotation:
82-
83-
$$ \vec{v}_{IOAR} = \frac{\vec{\omega}}{\omega}$$
84-
85-
3. The point C on the intantanous axis of rotation:
86-
87-
$$\vec{r}_C = \vec{r}_P + \frac{\vec{\omega}\times\vec{v}_P}{\vec{\omega}\cdot\vec{\omega}}$$
88-
89-
4. Ratio of angular to linear angular velocity:
90-
91-
$$ h = \frac{\vec{\omega} \cdot \vec{v}_P}{\vec{\omega}\cdot\vec{\omega}}$$
92-
93-
5. The linear velocity at point $C$ along the screw axis is then given by
94-
95-
$$\vec{v}_C = h\,\vec{\omega}$$
96-
97-
98-
All we need to know is the rotation velocity of a body and the velocity of any point to find the instantaneous axis of rotation.
99-
100-
## AnyScript implementation
101-
102-
In AnyScript we can easily find the angular velocity between two reference frames using the class `AnyKinRotational` and the linear velocity using the class `AnyKinLinear`.
103-
1043
We have created a custom class_template that makes it easy to add all this code to a model and display the instantaneous axis of rotation. Here is a short example on how to use the class.
1054

5+
First add the following to the top of your main file.
1066

107-
The class template is called `InstantaneousAxisOfRotation`. does exactly this, and then calculate the properties listed above.
108-
109-
110-
111-
112-
------------------
113-
114-
115-
116-
117-
7+
```c++
8+
#include "<ANYBODY_PATH_TOOLBOX>/Rotations/InstantaneousAxisOfRotation.any"
9+
```
11810

11+
Then add the `InstantaneousAxisOfRotation` class in one of your studies.
11912

120-
EXAMPLE:
12113
```c++
12214
#include "<ANYBODY_PATH_TOOLBOX>/Rotations/InstantaneousAxisOfRotation.any"
12315

@@ -127,7 +19,7 @@ Main = {
12719
// This is a simple example of using the InstantaneousAxisOfRotation class
12820
// to the calculate and vizualize the instantaneous axis of rotation
12921
// between Body1 and Body2
130-
InstantaneousAxisOfRotation IAOR (AnyRefFrame& Body1, AnyRefFrame& Body2 ) =
22+
InstantaneousAxisOfRotation IAOR (AnyRefFrame& Body1, AnyRefFrame& Body2) =
13123
{
13224
// The sphere drawn at the mid point of the vizualized axis.
13325
#var AnyVar SphereSize=0.02;
@@ -141,11 +33,20 @@ Main = {
14133
};
14234
```
14335
36+
## Output
37+
14438
The object will IAOR object will plot the axis, and provide the following outputs:
14539
146-
|---------------------|--------------|------------------------------------------------|
147-
| Output variable | Type | Desciption |
148-
|---------------------|--------------|------------------------------------------------|
149-
| MidPoint | AnyVec3 | The mid point on axis in global coordinates |
150-
| Direction | AnyVec3 | The direction of the axis in global coordinates|
151-
|---------------------|--------------|------------------------------------------------|
40+
|-----------------------|--------------|------------------------------------------------|
41+
| Output variable | Type | Desciption |
42+
|:----------------------|--------------|:-----------------------------------------------|
43+
| RotationAxisDirections| AnyVec3 | The mid point on axis in Body1 coordinates |
44+
| RotationMagnitude | AnyVec3 | The direction of the axis in Body1 coordinates |
45+
| rc_2 | AnyVec3 | Point on axis closest to Body2 |
46+
| rc_1 | AnyVec3 | Point on axis closest to Body1 |
47+
| MotionPitch | AnyVar | The ratio of linear motion to angular motion |
48+
| rc_dot | AnyVec3 | The linear velocity along the axis of rotation |
49+
| omega | AnyVec3 | Anuglar velocity vector of Body2 wrt. Body1 |
50+
| r | AnyVec3 | Position of Body2 wrt. Body1 |
51+
| r_dot | AnyVec3 | Linear velocity of Body2 wrt. Body1 |
52+
|-----------------------|--------------|------------------------------------------------|

Test_rolling_without_slipping.any

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// Todo: Write a small description of your model here
2+
3+
#include "InstantaneousAxisOfRotation.any"
4+
5+
Main = {
6+
7+
// The actual body model goes in this folder
8+
AnyFolder MyModel = {
9+
10+
// Global Reference Frame
11+
AnyFixedRefFrame GlobalRef = {
12+
13+
AnyDrawRefFrame drw={};
14+
15+
}; // Global reference frame
16+
17+
18+
AnyFolder Segments = {
19+
20+
21+
22+
23+
24+
AnySeg Ground = {
25+
26+
Mass = 0;
27+
Jii = {0, 0, 0};
28+
29+
AnyRefNode jnt ={ARel = RotMat(0.3*pi,y)*RotMat(0.3*pi,x);};
30+
31+
AnyDrawRefFrame drw1 ={ RGB={0,0,1};};
32+
};
33+
34+
35+
AnySeg Ball = {
36+
37+
Mass = 0;
38+
Jii = {0, 0, 0};
39+
AnyDrawRefFrame drw1 ={ RGB={0,0,1};};
40+
AnyDrawSphere drw2={ScaleXYZ={1,1,1}*0.5;};
41+
42+
};
43+
44+
};
45+
46+
47+
48+
49+
AnyFolder Joints = {
50+
51+
52+
AnyKinLinear Lin1 ={
53+
54+
AnyRefFrame &ref1=..GlobalRef;
55+
AnyRefFrame &ref2=..Segments.Ground;
56+
57+
58+
};
59+
60+
AnyKinRotational Rot1 ={
61+
62+
AnyRefFrame &ref1=..GlobalRef;
63+
AnyRefFrame &ref2=..Segments.Ground;
64+
Type=RotAxesAngles;
65+
};
66+
67+
68+
AnyKinEqSimpleDriver drv1={
69+
AnyKinMeasure &ref1=.Lin1;
70+
AnyKinMeasure &ref2=.Rot1;
71+
DriverPos ={0,0,0,0,0.25*pi,0};
72+
DriverVel ={0,0,0,0,0,0};
73+
74+
};
75+
76+
AnyKinLinear Lin2 ={
77+
Ref=0;
78+
AnyRefFrame &ref1=..Segments.Ground.jnt;
79+
AnyRefFrame &ref2=..Segments.Ball;
80+
};
81+
82+
AnyKinRotational Rot2 ={
83+
84+
AnyRefFrame &ref1=..Segments.Ground.jnt;
85+
AnyRefFrame &ref2=..Segments.Ball;
86+
Type=RotAxesAngles;
87+
};
88+
89+
90+
AnyKinEqSimpleDriver drv2={
91+
AnyKinMeasure &ref1=.Lin2;
92+
AnyKinMeasure &ref2=.Rot2;
93+
AnyVar Radius =0.5;
94+
DriverPos ={0,0.5,0,0,0,0};
95+
DriverVel ={2*pi*Radius,0,0,-2*pi,0,0};
96+
97+
};
98+
99+
};
100+
101+
102+
// AnyFolder InstantenousAxisCal ={
103+
InstantaneousAxisOfRotation IAOR (Body1=.Segments.Ground, Body2=.Segments.Ball) =
104+
{
105+
AxisThickness = 0.05;
106+
107+
};
108+
}; // MyModel
109+
110+
// The study: Operations to be performed on the model
111+
AnyBodyStudy MyStudy = {
112+
AnyFolder &Model = .MyModel;
113+
Gravity = {0.0, -9.81, 0.0};
114+
nStep = 200;
115+
tStart = 0;
116+
tEnd = 2;
117+
};
118+
119+
};
120+

Test_two_reference_frames.any

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include "InstantaneousAxisOfRotation.any"
2+
3+
Main = {
4+
5+
AnyFolder Model ={
6+
AnyFixedRefFrame Frame ={ AnyDrawRefFrame drw={}; };
7+
8+
AnySeg Object1 ={ Mass=1; Jii={0,0,0}; };
9+
10+
AnyStdJoint StdJoint = {
11+
AnyFixedRefFrame &ref1=.Frame;
12+
AnySeg &ref2=.Object1;
13+
};
14+
15+
AnySeg Object2 ={ Mass=1; Jii={0,0,0}; AnyDrawRefFrame drw={}; };
16+
17+
AnyKinLinear lin ={
18+
AnyFixedRefFrame &ref1=.Frame;
19+
AnySeg &ref2=.Object2;
20+
};
21+
22+
AnyKinRotational rot ={
23+
AnyFixedRefFrame &ref1=.Frame;
24+
AnySeg &ref2=.Object2;
25+
Type =RotAxesAngles;
26+
};
27+
28+
AnyKinEqInterPolDriver Lindrv ={
29+
Type =Bspline;
30+
AnyKinLinear &ref=.lin;
31+
T={0,0.25,0.5,1};
32+
Data={1*{0,0.5,0.75,1},1*{0,0.5,0.75,1},1*{0,0.5,0.75,1}};
33+
};
34+
35+
AnyKinEqInterPolDriver rotdrv ={
36+
AnyKinRotational &ref=.rot;
37+
Type =Bspline;
38+
T={0,0.25,0.5,1};
39+
Data=1*{0*{0,0.5,0.75,1},2*{0,0.5,0.75,1},10*{0,0.5,0.75,1}};
40+
//Data=1*{0*{0,0.5,0.75,1},0*{0,0.5,0.75,1},10*{0,0.5,0.75,1}};
41+
};
42+
43+
InstantaneousAxisOfRotation IAOR (Body1=.Object1, Body2=.Object2) ={};
44+
};
45+
46+
AnyBodyStudy study ={
47+
AnyFolder &ref=.Model;
48+
Gravity ={0,0,-9.81};
49+
tEnd=0.99;
50+
};
51+
};

0 commit comments

Comments
 (0)