-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathInstantaneousAxisOfRotation.any
More file actions
192 lines (152 loc) · 5.71 KB
/
InstantaneousAxisOfRotation.any
File metadata and controls
192 lines (152 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
HOW TO USE:
Add
`#include "<ANYBODY_PATH_TOOLBOX>/Rotations/InstantaneousAxisOfRotation.any"`
at the top of your main file.
Then add the `InstantaneousAxisOfRotation` class in one of your studies.
EXAMPLE:
```
#include "<ANYBODY_PATH_TOOLBOX>/Rotations/InstantaneousAxisOfRotation.any"
Main = {
// This is a simple example of using the InstantaneousAxisOfRotation class
// to the calculate and vizualize the instantaneous axis of rotation
// between Body1 and Body2
InstantaneousAxisOfRotation IAOR (AnyRefFrame& Body1, AnyRefFrame& Body2) =
{
// The sphere drawn at the mid point of the vizualized axis.
#var AnyVar SphereSize=0.02;
// The length of the vizualized axis
#var AnyVar AxisLength=2;
// The line thickness of the vizualized axis.
#var AnyVar LineThickness = 0.005;
};
```
The object will IAOR object will plot the axis, and provide the following outputs:
|-----------------------|--------------|------------------------------------------------|
| Output variable | Type | Desciption |
|-----------------------|--------------|------------------------------------------------|
| RotationAxisDirections| AnyVec3 | The mid point on axis in Body1 coordinates |
| RotationMagnitude | AnyVec3 | The direction of the axis in Body1 coordinates |
| rc_2 | AnyVec3 | Point on axis closest to Body2 |
| rc_1 | AnyVec3 | Point on axis closest to Body1 |
| MotionPitch | AnyVar | The ratio of linear motion to angular motion |
| rc_dot | AnyVec3 | The linear velocity along the axis of rotation |
| omega | AnyVec3 | Anuglar velocity vector of Body2 wrt. Body1 |
| r | AnyVec3 | Position of Body2 wrt. Body1 |
| r_dot | AnyVec3 | Linear velocity of Body2 wrt. Body1 |
|-----------------------|--------------|------------------------------------------------|
*/
#class_template InstantaneousAxisOfRotation (
AnyRefFrame& Body1,
AnyRefFrame& Body2,
SHOW_LINEAR_VELOCITY = "On",
AXIS_LOCATION = "MIDPOINT",
SHOW_SHORTEST_DIST = "On")
{
AnyKinLinear Linear ={
Ref=0;
AnyRefFrame &Body1= .Body1;
AnyRefFrame &Body2= .Body2;
};
AnyKinRotational Rotational ={
Type = RotVector;
AngVelOnOff = On;
AnyRefFrame &Body1= .Body1;
AnyRefFrame &Body2= .Body2;
};
/// Size of the drawn spheres
#var AnyVar SphereSize=0.02;
/// Length of the axis drawn
#var AnyVar AxisLength=2;
/// Thickness of the axis drawn
#var AnyVar AxisThickness = 0.01;
/// Rotational Velocity of Body2 with repect to Body1
AnyVec3 omega = Rotational.Vel;
/// Linear Velociy of Body2 with respect to Body1
AnyVec3 r_dot = Linear.Vel;
/// Postion of Body2 with respect to Body1
AnyVec3 r = Linear.Pos;
/// The rotation magnitude
AnyVar RotationMagnitude = iffun(eqfun(vnorm(omega),0),1e-15, vnorm(omega));
/// The rotation axis direction
AnyVec3 RotationAxisDirection = omega/RotationMagnitude;
/// The point on the rotation axis closest to Body2
AnyVec3 rc_2 = r + cross(omega, r_dot)/(RotationMagnitude^2);
/// The point on the rotation axis closest to Body1
AnyVec3 rc_1 = rc_2-rc_2*RotationAxisDirection'*RotationAxisDirection;
/// The motion pitch or the ratio of linear motion to angular motion
AnyVar MotionPitch = (omega*r_dot')/(RotationMagnitude^2);
/// Linear Velocity of points on the rotation axis
AnyVec3 rc_dot = MotionPitch*omega;
AnyFolder Visualizations =
{
// Draw the points on the axis closest to the objects
#if SHOW_SHORTEST_DIST == "On"
AnyDrawSphere p2={
Opacity = 0.5;
ScaleXYZ=..SphereSize*{1,1,1};
Position= ..Body1.r+..rc_2*..Body1.Axes';
};
AnyDrawLine DrawShortesDistance2 ={
AnyRefFrame &ref = ..Body1;
p0 = ..r;
p1 = ..rc_2;
Opacity = 0.2;
Line.Thickness = 0.003;
Line.RGB={0,0,0};
GlobalCoord = Off;
};
AnyDrawSphere p1={
Opacity = 0.5;
ScaleXYZ=..SphereSize*{1,1,1};
Position= ..Body1.r+..rc_1*..Body1.Axes';
};
AnyDrawLine DrawShortesDistance1 ={
AnyRefFrame &ref = ..Body1;
p0 = {0,0,0};
p1 = ..rc_1;
Opacity = 0.2;
Line.Thickness = 0.003;
Line.RGB={0,0,0};
GlobalCoord = Off;
};
AnyDrawSphere pmid={
Opacity = 0.5;
ScaleXYZ=..SphereSize*{1,1,1};
Position= ..Body1.r+0.5*(..rc_1+..rc_2)*..Body1.Axes';
RGB = {0,0,1};
};
#endif
// Draw the instant rotation axis
AnyDrawLine DrawRotationAxisLine ={
#if AXIS_LOCATION == "MIDPOINT"
AnyVec3 P = 0.5*(..rc_1+..rc_2);
#endif
#if AXIS_LOCATION == "BODY1"
AnyVec3 P = ..rc_1;
#endif
#if AXIS_LOCATION == "BODY1"
AnyVec3 P = ..rc_2;
#endif
AnyRefFrame &ref = ..Body1;
Opacity = 0.4;
p0 = P-0.5*..RotationAxisDirection*..AxisLength;
p1 = P+0.5*..RotationAxisDirection*..AxisLength;
Line.Thickness=..AxisThickness;
Line.RGB={0,0,1};
GlobalCoord =Off;
};
#if SHOW_LINEAR_VELOCITY == "On"
AnyDrawLine DrawLinearVelocityVector ={
AnyRefFrame &ref = ..Body1;
p0 = ..rc_2;
p1 = p0+..rc_dot;
Opacity = 0.7;
Line.End.Style = Line3DCapStyleArrow;
Line.Thickness=..AxisThickness*1.1;
Line.RGB={1,0,0};
GlobalCoord =Off;
};
#endif
};
};