Welcome to mirror list, hosted at ThFree Co, Russian Federation.

framevel.inl « kdl « itasc « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 994b3d2028eeb97af380f6f7cb129019fbdf9d17 (plain)
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
/*****************************************************************************
 * \file  
 *      provides inline functions of rframes.h
 *       
 *  \author 
 *      Erwin Aertbelien, Div. PMA, Dep. of Mech. Eng., K.U.Leuven
 *
 *  \version 
 *      ORO_Geometry V0.2
 *
 *  \par History
 *      - $log$
 *
 *  \par Release
 *      $Id: framevel.inl 19905 2009-04-23 13:29:54Z ben2610 $
 *      $Name:  $ 
 ****************************************************************************/


// Methods and operators related to FrameVelVel
// They all delegate most of the work to RotationVelVel and VectorVelVel
FrameVel& FrameVel::operator = (const FrameVel& arg) {
    M=arg.M;
    p=arg.p;
    return *this;
}

FrameVel FrameVel::Identity() {
    return FrameVel(RotationVel::Identity(),VectorVel::Zero());
}


FrameVel operator *(const FrameVel& lhs,const FrameVel& rhs)
{
    return FrameVel(lhs.M*rhs.M,lhs.M*rhs.p+lhs.p);
}
FrameVel operator *(const FrameVel& lhs,const Frame& rhs)
{
    return FrameVel(lhs.M*rhs.M,lhs.M*rhs.p+lhs.p);
}
FrameVel operator *(const Frame& lhs,const FrameVel& rhs)
{
    return FrameVel(lhs.M*rhs.M , lhs.M*rhs.p+lhs.p );
}

VectorVel FrameVel::operator *(const VectorVel & arg) const
{
    return M*arg+p;
}
VectorVel FrameVel::operator *(const Vector & arg) const
{
    return M*arg+p;
}

VectorVel FrameVel::Inverse(const VectorVel& arg) const
{
    return M.Inverse(arg-p);
}

VectorVel FrameVel::Inverse(const Vector& arg) const
{
    return M.Inverse(arg-p);
}

FrameVel FrameVel::Inverse() const
{
    return FrameVel(M.Inverse(),-M.Inverse(p));
}

FrameVel& FrameVel::operator = (const Frame& arg) {
    M = arg.M;
    p = arg.p;
    return *this;
}
bool Equal(const FrameVel& r1,const FrameVel& r2,double eps) {
    return (Equal(r1.M,r2.M,eps) && Equal(r1.p,r2.p,eps));
}
bool Equal(const Frame& r1,const FrameVel& r2,double eps) {
    return (Equal(r1.M,r2.M,eps) && Equal(r1.p,r2.p,eps));
}
bool Equal(const FrameVel& r1,const Frame& r2,double eps) {
    return (Equal(r1.M,r2.M,eps) && Equal(r1.p,r2.p,eps));
}

Frame FrameVel::GetFrame() const {
    return Frame(M.R,p.p);
}

Twist FrameVel::GetTwist() const {
    return Twist(p.v,M.w);
}


RotationVel operator* (const RotationVel& r1,const RotationVel& r2) {
    return RotationVel( r1.R*r2.R, r1.w + r1.R*r2.w );
}

RotationVel operator* (const Rotation& r1,const RotationVel& r2) {
    return RotationVel( r1*r2.R, r1*r2.w );
}

RotationVel operator* (const RotationVel& r1,const Rotation& r2) {
    return RotationVel( r1.R*r2, r1.w );
}

RotationVel& RotationVel::operator = (const RotationVel& arg) {
        R=arg.R;
        w=arg.w;
        return *this;
    }
RotationVel& RotationVel::operator = (const Rotation& arg) {
    R=arg;
    w=Vector::Zero();
    return *this;
}

VectorVel   RotationVel::UnitX() const {
	return VectorVel(R.UnitX(),w*R.UnitX()); 
}

VectorVel   RotationVel::UnitY() const {
	return VectorVel(R.UnitY(),w*R.UnitY()); 
}

VectorVel   RotationVel::UnitZ() const {
	return VectorVel(R.UnitZ(),w*R.UnitZ()); 
}



RotationVel RotationVel::Identity() {
    return RotationVel(Rotation::Identity(),Vector::Zero());
}

RotationVel RotationVel::Inverse() const {
    return RotationVel(R.Inverse(),-R.Inverse(w));
}

VectorVel RotationVel::Inverse(const VectorVel& arg) const {
    Vector tmp=R.Inverse(arg.p);
    return VectorVel(tmp,
                    R.Inverse(arg.v-w*arg.p)
                    );
}

VectorVel RotationVel::Inverse(const Vector& arg) const {
    Vector tmp=R.Inverse(arg);
    return VectorVel(tmp,
                    R.Inverse(-w*arg)
                    );
}


VectorVel RotationVel::operator*(const VectorVel& arg) const {
    Vector tmp=R*arg.p;
    return VectorVel(tmp,w*tmp+R*arg.v);
}

VectorVel RotationVel::operator*(const Vector& arg) const {
    Vector tmp=R*arg;
    return VectorVel(tmp,w*tmp);
}


// = Rotations
// The Rot... static functions give the value of the appropriate rotation matrix back.
// The DoRot... functions apply a rotation R to *this,such that *this = *this * R.

void RotationVel::DoRotX(const doubleVel& angle) {
    w+=R*Vector(angle.grad,0,0);
    R.DoRotX(angle.t);
}
RotationVel RotationVel::RotX(const doubleVel& angle) {
    return RotationVel(Rotation::RotX(angle.t),Vector(angle.grad,0,0));
}

void RotationVel::DoRotY(const doubleVel& angle) {
    w+=R*Vector(0,angle.grad,0);
    R.DoRotY(angle.t);
}
RotationVel RotationVel::RotY(const doubleVel& angle) {
    return RotationVel(Rotation::RotX(angle.t),Vector(0,angle.grad,0));
}

void RotationVel::DoRotZ(const doubleVel& angle) {
    w+=R*Vector(0,0,angle.grad);
    R.DoRotZ(angle.t);
}
RotationVel RotationVel::RotZ(const doubleVel& angle) {
    return RotationVel(Rotation::RotZ(angle.t),Vector(0,0,angle.grad));
}


RotationVel RotationVel::Rot(const Vector& rotvec,const doubleVel& angle) 
// rotvec has arbitrary norm
// rotation around a constant vector !
{
    Vector v(rotvec);
	v.Normalize();
    return RotationVel(Rotation::Rot2(v,angle.t),v*angle.grad);
}

RotationVel RotationVel::Rot2(const Vector& rotvec,const doubleVel& angle) 
    // rotvec is normalized.
{
    return RotationVel(Rotation::Rot2(rotvec,angle.t),rotvec*angle.grad);
}


VectorVel operator + (const VectorVel& r1,const VectorVel& r2) {
    return VectorVel(r1.p+r2.p,r1.v+r2.v);
}

VectorVel operator - (const VectorVel& r1,const VectorVel& r2) {
    return VectorVel(r1.p-r2.p,r1.v-r2.v);
}

VectorVel operator + (const VectorVel& r1,const Vector& r2) {
    return VectorVel(r1.p+r2,r1.v);
}

VectorVel operator - (const VectorVel& r1,const Vector& r2) {
    return VectorVel(r1.p-r2,r1.v);
}

VectorVel operator + (const Vector& r1,const VectorVel& r2) {
    return VectorVel(r1+r2.p,r2.v);
}

VectorVel operator - (const Vector& r1,const VectorVel& r2) {
    return VectorVel(r1-r2.p,-r2.v);
}

// unary -
VectorVel operator - (const VectorVel& r) {
    return VectorVel(-r.p,-r.v);
}

void SetToZero(VectorVel& v){
    SetToZero(v.p);
    SetToZero(v.v);
}

// cross prod.
VectorVel operator * (const VectorVel& r1,const VectorVel& r2) {
    return VectorVel(r1.p*r2.p, r1.p*r2.v+r1.v*r2.p);
}

VectorVel operator * (const VectorVel& r1,const Vector& r2) {
    return VectorVel(r1.p*r2, r1.v*r2);
}

VectorVel operator * (const Vector& r1,const VectorVel& r2) {
    return VectorVel(r1*r2.p, r1*r2.v);
}



// scalar mult.
VectorVel operator * (double r1,const VectorVel& r2) {
    return VectorVel(r1*r2.p, r1*r2.v);
}

VectorVel operator * (const VectorVel& r1,double r2) {
    return VectorVel(r1.p*r2, r1.v*r2);
}



VectorVel operator * (const doubleVel& r1,const VectorVel& r2) {
    return VectorVel(r1.t*r2.p, r1.t*r2.v + r1.grad*r2.p);
}

VectorVel operator * (const VectorVel& r2,const doubleVel& r1) {
    return VectorVel(r1.t*r2.p, r1.t*r2.v + r1.grad*r2.p);
}

VectorVel operator / (const VectorVel& r1,double r2) {
    return VectorVel(r1.p/r2, r1.v/r2);
}

VectorVel operator / (const VectorVel& r2,const doubleVel& r1) {
    return VectorVel(r2.p/r1.t, r2.v/r1.t - r2.p*r1.grad/r1.t/r1.t);
}

VectorVel operator*(const Rotation& R,const VectorVel& x) {
    return VectorVel(R*x.p,R*x.v);
}

VectorVel& VectorVel::operator = (const VectorVel& arg) {
    p=arg.p;
    v=arg.v;
    return *this;
}
VectorVel& VectorVel::operator = (const Vector& arg) {
    p=arg;
    v=Vector::Zero();
    return *this;
}
VectorVel& VectorVel::operator += (const VectorVel& arg) {
    p+=arg.p;
    v+=arg.v;
    return *this;
}
VectorVel& VectorVel::operator -= (const VectorVel& arg) {
    p-=arg.p;
    v-=arg.v;
    return *this;
}

VectorVel VectorVel::Zero() {
    return VectorVel(Vector::Zero(),Vector::Zero());
}
void VectorVel::ReverseSign() {
    p.ReverseSign();
    v.ReverseSign();
}
doubleVel VectorVel::Norm() const {
    double n = p.Norm();
    return doubleVel(n,dot(p,v)/n);
}

bool Equal(const VectorVel& r1,const VectorVel& r2,double eps) {
    return (Equal(r1.p,r2.p,eps) && Equal(r1.v,r2.v,eps));
}
bool Equal(const Vector& r1,const VectorVel& r2,double eps) {
    return (Equal(r1,r2.p,eps) && Equal(Vector::Zero(),r2.v,eps));
}
bool Equal(const VectorVel& r1,const Vector& r2,double eps) {
    return (Equal(r1.p,r2,eps) && Equal(r1.v,Vector::Zero(),eps));
}

bool Equal(const RotationVel& r1,const RotationVel& r2,double eps) {
    return (Equal(r1.w,r2.w,eps) && Equal(r1.R,r2.R,eps));
}
bool Equal(const Rotation& r1,const RotationVel& r2,double eps) {
    return (Equal(Vector::Zero(),r2.w,eps) && Equal(r1,r2.R,eps));
}
bool Equal(const RotationVel& r1,const Rotation& r2,double eps) {
    return (Equal(r1.w,Vector::Zero(),eps) && Equal(r1.R,r2,eps));
}
bool Equal(const TwistVel& a,const TwistVel& b,double eps) {
        return (Equal(a.rot,b.rot,eps)&&
                Equal(a.vel,b.vel,eps)  );
}
bool Equal(const Twist& a,const TwistVel& b,double eps) {
        return (Equal(a.rot,b.rot,eps)&&
                Equal(a.vel,b.vel,eps)  );
}
bool Equal(const TwistVel& a,const Twist& b,double eps) {
        return (Equal(a.rot,b.rot,eps)&&
                Equal(a.vel,b.vel,eps)  );
}



IMETHOD doubleVel dot(const VectorVel& lhs,const VectorVel& rhs) {
    return doubleVel(dot(lhs.p,rhs.p),dot(lhs.p,rhs.v)+dot(lhs.v,rhs.p));
}
IMETHOD doubleVel dot(const VectorVel& lhs,const Vector& rhs) {
    return doubleVel(dot(lhs.p,rhs),dot(lhs.v,rhs));
}
IMETHOD doubleVel dot(const Vector& lhs,const VectorVel& rhs) {
    return doubleVel(dot(lhs,rhs.p),dot(lhs,rhs.v));
}












TwistVel TwistVel::Zero()
{
    return TwistVel(VectorVel::Zero(),VectorVel::Zero());
}


void TwistVel::ReverseSign()
{   
    vel.ReverseSign();
    rot.ReverseSign();
}

TwistVel TwistVel::RefPoint(const VectorVel& v_base_AB)
     // Changes the reference point of the TwistVel.
     // The VectorVel v_base_AB is expressed in the same base as the TwistVel
     // The VectorVel v_base_AB is a VectorVel from the old point to
     // the new point.
     // Complexity : 6M+6A
{
    return TwistVel(this->vel+this->rot*v_base_AB,this->rot);
}

TwistVel& TwistVel::operator-=(const TwistVel& arg)
{
    vel-=arg.vel;
    rot -=arg.rot;
    return *this;
}

TwistVel& TwistVel::operator+=(const TwistVel& arg)
{
    vel+=arg.vel;
    rot +=arg.rot;
    return *this;
}


TwistVel operator*(const TwistVel& lhs,double rhs)
{
    return TwistVel(lhs.vel*rhs,lhs.rot*rhs);
}

TwistVel operator*(double lhs,const TwistVel& rhs)
{
    return TwistVel(lhs*rhs.vel,lhs*rhs.rot);
}

TwistVel operator/(const TwistVel& lhs,double rhs)
{
    return TwistVel(lhs.vel/rhs,lhs.rot/rhs);
}


TwistVel operator*(const TwistVel& lhs,const doubleVel& rhs)
{
    return TwistVel(lhs.vel*rhs,lhs.rot*rhs);
}

TwistVel operator*(const doubleVel& lhs,const TwistVel& rhs)
{
    return TwistVel(lhs*rhs.vel,lhs*rhs.rot);
}

TwistVel operator/(const TwistVel& lhs,const doubleVel& rhs)
{
    return TwistVel(lhs.vel/rhs,lhs.rot/rhs);
}



// addition of TwistVel's
TwistVel operator+(const TwistVel& lhs,const TwistVel& rhs)
{
    return TwistVel(lhs.vel+rhs.vel,lhs.rot+rhs.rot);
}

TwistVel operator-(const TwistVel& lhs,const TwistVel& rhs)
{
    return TwistVel(lhs.vel-rhs.vel,lhs.rot-rhs.rot);
}

// unary -
TwistVel operator-(const TwistVel& arg) 
{
    return TwistVel(-arg.vel,-arg.rot);
}

void SetToZero(TwistVel& v)
{
   SetToZero(v.vel);
   SetToZero(v.rot);
}





TwistVel RotationVel::Inverse(const TwistVel& arg) const
{
    return TwistVel(Inverse(arg.vel),Inverse(arg.rot));
}

TwistVel RotationVel::operator * (const TwistVel& arg) const
{
    return TwistVel((*this)*arg.vel,(*this)*arg.rot);
}

TwistVel RotationVel::Inverse(const Twist& arg) const
{
    return TwistVel(Inverse(arg.vel),Inverse(arg.rot));
}

TwistVel RotationVel::operator * (const Twist& arg) const
{
    return TwistVel((*this)*arg.vel,(*this)*arg.rot);
}


TwistVel FrameVel::operator * (const TwistVel& arg) const
{
    TwistVel tmp;
    tmp.rot = M*arg.rot;
    tmp.vel = M*arg.vel+p*tmp.rot;
    return tmp;
}

TwistVel FrameVel::operator * (const Twist& arg) const
{
    TwistVel tmp;
    tmp.rot = M*arg.rot;
    tmp.vel = M*arg.vel+p*tmp.rot;
    return tmp;
}

TwistVel FrameVel::Inverse(const TwistVel& arg) const
{
    TwistVel tmp;
    tmp.rot =  M.Inverse(arg.rot);
    tmp.vel = M.Inverse(arg.vel-p*arg.rot);
    return tmp;
}

TwistVel FrameVel::Inverse(const Twist& arg) const
{
    TwistVel tmp;
    tmp.rot =  M.Inverse(arg.rot);
    tmp.vel = M.Inverse(arg.vel-p*arg.rot);
    return tmp;
}

Twist TwistVel::GetTwist() const {
    return Twist(vel.p,rot.p);
}

Twist TwistVel::GetTwistDot() const {
    return Twist(vel.v,rot.v);
}