-
Notifications
You must be signed in to change notification settings - Fork 2
/
screw.v
1699 lines (1458 loc) · 58.3 KB
/
screw.v
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
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(* coq-robot (c) 2017 AIST and INRIA. License: LGPL-2.1-or-later. *)
From HB Require Import structures.
From mathcomp Require Import all_ssreflect ssralg ssrint ssrnum rat poly.
From mathcomp Require Import closed_field polyrcf matrix mxalgebra mxpoly zmodp.
From mathcomp Require Import realalg complex fingroup perm.
From mathcomp.analysis Require Import forms.
From mathcomp Require Import interval reals trigo.
Require Import ssr_ext euclidean skew vec_angle frame rot rigid extra_trigo.
(******************************************************************************)
(* Screw Motions *)
(* *)
(* This file develops the theory of screws and twists. It establishes in *)
(* particular Chasles' theorem (given a rigid body motion, it shows *)
(* constructively the existence of an angle and a twist that represent this *)
(* rigid body motion), Mozzi-Chasles' theorem (it shows the existence of a *)
(* set of points that undergo just a translation---this is the screw axis). *)
(* *)
(* Module sqLieAlgebra == square matrices form a Lie algebra *)
(* 'se3[R] == the set of twists *)
(* wedge t == form a twist in 'se3[R] given twist (coordinates) *)
(* (essentially a vector in R^6 ) *)
(* vee E == extract the 6-dimensional vector (the twist coordinates) from *)
(* a twist in 'se3[R] *)
(* emx M k == the Taylor expansion of matrix M *)
(* screw T == type of screw, defined by a line (the screw axis), and angle *)
(* (the screw magnitude), and a pitch *)
(* Rad.f a == the measure in radians of the angle a *)
(* screw_motion s p == motion of the point p by the screw s *)
(* twist T == the type of twists, i.e., two vectors v and w, v representing *)
(* the linear velocity of the motion and w representing the *)
(* angular velocity *)
(* \v{t} == linear velocity of the twist t *)
(* \w{t} == angular velocity of the twist t *)
(* `e$(a, t) == the exponential of a twist t with angle a *)
(* rjoint_twist w p == twist of a revolute joint *)
(* pjoint_twist v == twist of a prismatic joint *)
(* *)
(******************************************************************************)
Reserved Notation "''se3[' R ]" (at level 8, format "''se3[' R ]").
Reserved Notation "'\T(' v , w ')'" (at level 3,
w, v at next level, format "'\T(' v , w ')'").
Reserved Notation "'\v(' t ')'" (format "'\v(' t ')'", at level 3).
Reserved Notation "'\w(' t ')'" (format "'\w(' t ')'", at level 3).
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import Order.TTheory GRing.Theory Num.Def Num.Theory.
Local Open Scope ring_scope.
(* TODO: move? *)
Lemma mulmx_tr_uvect (T : rcfType) (w : 'rV[T]_3) :
norm w = 1 -> (w^T *m w) ^+ 2 = w^T *m w.
Proof.
move=> w1; rewrite expr2 -mulmxE -mulmxA (mulmxA w) dotmulP dotmulvv w1 expr1n.
by rewrite mul1mx.
Qed.
Section taylor_exponential.
Variable T : realFieldType.
Let vector := 'rV[T]_3.
Variable n : nat.
Implicit Type M : 'M[T]_n.+1.
Lemma expr_mulmulV M i (g : 'M[T]_n.+1) : g \in unitmx ->
(g * M * g^-1)^+i = g * M ^+i * g^-1.
Proof.
move=> Hg; elim: i => [|i ih]; first by rewrite 2!expr0 mulr1 divrr.
rewrite exprS ih -!mulrA exprS -mulrA; congr (_ * (_ * _)).
by rewrite mulrA mulVr // mul1r.
Qed.
Definition ecoef M i := i`!%:R^-1 *: M ^+ i.
Lemma ecoefE M i : ecoef M i = i`!%:R^-1 *: M ^+ i.
Proof. by []. Qed.
Lemma ecoefM0 M : ecoef M 0 = 1.
Proof. by rewrite ecoefE expr0 fact0 invr1 scale1r. Qed.
Lemma ecoef0k k : ecoef 0 k = (k == O)%:R.
Proof.
rewrite ecoefE expr0n.
case: k => [|k]; first by rewrite fact0 invr1 scale1r.
by rewrite scaler0.
Qed.
Lemma ecoefS M i : ecoef M i.+1 = i.+1%:R^-1 *: M * ecoef M i.
Proof.
rewrite /ecoef -scalerAr -scalerAl -exprS scalerA; congr (_ *: _).
by rewrite factS natrM invrM // unitfE pnatr_eq0 // -lt0n fact_gt0.
Qed.
Lemma ecoef1 M : ecoef M 1 = M.
Proof. by rewrite ecoefS ecoefM0 mulr1 invr1 scale1r. Qed.
Lemma tr_ecoef M k : (ecoef M k)^T = ecoef M^T k.
Proof.
elim: k => [|k ih]; first by rewrite 2!ecoefM0 trmx1.
rewrite ecoefS -mulmxE -scalemxAl linearZ /= trmx_mul ih ecoefS.
rewrite -mulmxE -scalemxAl; congr (_ *: _).
by rewrite /ecoef -scalemxAr -scalemxAl !mulmxE -exprSr -exprS.
Qed.
Lemma ecoef_mulmulV M (g : 'M[T]_n.+1) i : g \in unitmx ->
ecoef (g * M * g^-1) i = g * ecoef M i * g^-1.
Proof. move=> Hg; by rewrite /ecoef expr_mulmulV // -scalerAr scalerAl. Qed.
Definition emx M k := \sum_(i < k) ecoef M i.
Lemma emxM0 M : emx M 0 = 0.
Proof. by rewrite /emx big_ord0. Qed.
Lemma emxS M k : emx M k.+1 = emx M k + ecoef M k.
Proof. by rewrite /emx big_ord_recr. Qed.
Lemma emx0k k : emx 0 k = (k != O)%:R.
Proof.
elim: k => [|k ih]; first by rewrite emxM0 eqxx.
by rewrite emxS ih /= ecoef0k -natrD addn_negb.
Qed.
Lemma eSmx M k : emx M k.+1 = ecoef M 0 + \sum_(i < k) ecoef M i.+1.
Proof. by rewrite /emx big_ord_recl. Qed.
Lemma emx1 M : emx M 1 = 1.
Proof. by rewrite emxS emxM0 add0r ecoefM0. Qed.
Lemma emx2 M : emx M 2 = 1 + M.
Proof. by rewrite emxS emx1 ecoef1. Qed.
Lemma tr_emx M k : (emx M k)^T = emx M^T k.
Proof.
rewrite /emx.
have H : {morph @trmx T n.+1 n.+1 : x y / x + y >-> x + y}.
move=> x y; by rewrite linearD.
rewrite (@big_morph _ _ _ 0 _ 0 _ H) ?trmx0 //; apply eq_bigr => i _.
by rewrite tr_ecoef.
Qed.
Lemma emx_mulmulV M k (g : 'M[T]_n.+1) : g \in unitmx ->
emx (g * M * g^-1) k = g * emx M k * g^-1.
Proof.
move=> Hg; rewrite /emx big_distrr /= big_distrl /=.
apply/eq_bigr => i _; by rewrite ecoef_mulmulV.
Qed.
End taylor_exponential.
Section sqliealgebra.
Variables (R : comRingType) (n : nat).
Definition sq (t1 t2 : 'M[R]_n.+1) := t1 * t2 - t2 * t1.
Lemma sq_is_linear w : linear (sq w : 'M[R]_n.+1 -> 'M[R]_n.+1).
Proof.
move=> k v u; rewrite /sq.
rewrite mulrDr -addrA addrCA [in RHS]addrCA; congr (_ + _).
rewrite scalerDr scalerAr -addrA; congr (_ + _).
rewrite mulrDl opprD; congr (_ - _).
by rewrite scalerN scalerAl.
Qed.
HB.instance Definition _ x := GRing.isLinear.Build _ _ _ _ _ (sq_is_linear x).
Definition sq_rev t1 t2 := sq t2 t1.
(*Canonical rev_seq := @RevOp _ _ _ sq_rev sq (fun _ _ => erefl).*)
Lemma sq_rev_is_linear w : linear (sq_rev w : 'M[R]_n.+1 -> 'M[R]_n.+1).
Proof.
move=> k u v; rewrite /sq_rev /sq /=.
rewrite mulrDl scalerBr scalerAl -2!addrA; congr (_ + _).
rewrite addrCA; congr (_ + _).
rewrite -opprD; congr (- _).
rewrite mulrDr; congr (_ + _).
by rewrite scalerAr.
Qed.
HB.instance Definition _ x := GRing.isLinear.Build _ _ _ _ _ (sq_rev_is_linear x).
Lemma sq_is_bilinear : bilinear_for
(GRing.Scale.Law.clone _ _ *:%R _) (GRing.Scale.Law.clone _ _ *:%R _)
(sq : _ -> _ -> _).
Proof.
split => [u'|u] a x y /=.
- rewrite /sq.
rewrite !scalerBr mulrDl mulrDr opprD.
rewrite scalerAl -!addrA; congr (_ + _).
rewrite [RHS]addrCA; congr (_ + _).
by rewrite scalerAr.
- rewrite /sq.
rewrite !scalerBr mulrDl mulrDr opprD.
rewrite scalerAl -!addrA.
rewrite -scalerAr -scalerAl; congr (_ + _).
rewrite [RHS]addrCA; congr (_ + _).
by rewrite scalerAl.
Qed.
HB.instance Definition _ :=
bilinear_isBilinear.Build R
[the lmodType R of 'M[R]_n.+1] [the lmodType R of 'M[R]_n.+1]
_ _ _ sq sq_is_bilinear.
Lemma sqxx x : sq x x = 0.
Proof. apply/eqP; by rewrite subr_eq0. Qed.
Lemma sq_jacobi : jacobi_identity sq.
Proof.
move=> x y z; rewrite /sq.
rewrite mulrBr (mulrBl z) opprB !addrA addrC !addrA (mulrA x).
rewrite (addrC _ (x * y * z)) subrr add0r.
rewrite (mulrBl y) opprB addrA (addrC _ (x * z * y)) mulrA !addrA subrr add0r.
rewrite (mulrBr y) !addrA (addrC _ (- (y * (x * z)))) addrC !addrA mulrA subrr.
by rewrite add0r mulrBl opprB mulrA subrK mulrBr addrA mulrA subrK mulrA subrr.
Qed.
HB.instance Definition _ :=
@isLieAlgebra.Build R 'M[R]_n.+1 (sq : {bilinear 'M[R]_n.+1 -> 'M[R]_n.+1 -> 'M[R]_n.+1})
sqxx sq_jacobi.
End sqliealgebra.
Module Twist.
Section twist_coordinates.
Variable T : ringType.
Let vector := 'rV[T]_3.
Definition t := 'rV[T]_6.
Definition mk (v w : vector) : t := block_mx v w 0 0.
Definition lin (x : t) : vector := @ulsubmx T 1 0 3 3 x. (* linear vel. *)
Definition ang (x : t) : vector := @ursubmx T 1 0 3 3 x. (* angular vel. *)
Lemma lin_of v w : lin (mk v w) = v.
Proof. by rewrite /lin /mk block_mxKul. Qed.
Lemma ang_of v w : ang (mk v w) = w.
Proof. by rewrite /ang /mk block_mxKur. Qed.
End twist_coordinates.
End Twist.
Notation twist := Twist.t.
Notation "'\T(' v , w ')'" := (Twist.mk v w).
Notation "'\v(' t ')'" := (Twist.lin t).
Notation "'\w(' t ')'" := (Twist.ang t).
Section twist_coordinates_properties.
Variable R : ringType.
Implicit Types t : twist R.
Lemma twist_mkE t : \T(\v( t ), \w( t )) = t.
Proof.
rewrite /Twist.mk /Twist.ang /Twist.lin -[RHS](@submxK _ 1 0 3 3 t).
f_equal; apply/matrixP; by do 2 case.
Qed.
Lemma twistD v w v' w' : \T(v, w) + \T(v', w')= \T(v + v', w + w') :> twist R.
Proof. by rewrite /Twist.mk (add_block_mx v _ _ _ v') !addr0. Qed.
Lemma ang_tcoor0 : \w( 0 ) = 0 :> 'rV[R]_3.
Proof. by rewrite /Twist.ang -(block_mx0 _ 1 0 3 3) block_mxKur. Qed.
Lemma ang_tcoorE v w : \w( \T(v, w) ) = w :> 'rV[R]_3.
Proof. by rewrite /Twist.ang /Twist.mk block_mxKur. Qed.
Lemma ang_tcoorZ k t : \w( (k *: t) ) = k *: \w( t ).
Proof.
rewrite /Twist.ang -{1}(@submxK _ 1 0 3 3 t).
by rewrite (@scale_block_mx _ 1 0 3 3) block_mxKur.
Qed.
Lemma ang_tcoorD t1 t2 : \w( t1 + t2 ) = \w( t1 ) + \w( t2 ).
Proof.
rewrite /Twist.ang -{1}(@submxK _ 1 0 3 3 t1) -{1}(@submxK _ 1 0 3 3 t2).
set a := ulsubmx _. by rewrite (add_block_mx a) block_mxKur.
Qed.
Lemma lin_tcoor0 : \v( 0 ) = 0 :> 'rV[R]_3.
Proof. by rewrite /Twist.lin -(block_mx0 _ 1 0 3 3) block_mxKul. Qed.
Lemma lin_tcoorE v w : \v( \T(v, w) ) = v :> 'rV[R]_3.
Proof. by rewrite /Twist.lin /Twist.mk block_mxKul. Qed.
Lemma lin_tcoorZ k t : \v( (k *: t) ) = k *: \v( t ).
Proof.
rewrite /Twist.lin -{1}(@submxK _ 1 _ 3 _ t).
by rewrite (@scale_block_mx _ 1 _ 3) block_mxKul.
Qed.
Lemma lin_tcoorD t1 t2 : \v( t1 + t2 ) = \v( t1 ) + \v( t2 ).
Proof.
rewrite /Twist.lin -{1}(@submxK _ 1 0 3 3 t1) -{1}(@submxK _ 1 0 3 3 t2).
set b := ursubmx _. set c := dlsubmx _. by rewrite (add_block_mx _ b c) block_mxKul.
Qed.
End twist_coordinates_properties.
Section se3_qualifier.
Variable T : comUnitRingType.
Implicit Types E : 'M[T]_4.
(* [murray] p.40 *)
Definition se3 := [qualify E : 'M[T]_4 |
[&& @ulsubmx _ 3 1 3 1 E \is 'so[T]_3,
@ursubmx _ 3 1 3 1 E == 0 &
@drsubmx _ 3 1 3 1 E == 0] ].
Fact se3_key : pred_key se3. Proof. by []. Qed.
Canonical se3_keyed := KeyedQualifier se3_key.
Definition lin_of_twist E := @dlsubmx _ 3 1 3 1 E.
Definition ang_of_twist E := unspin (@ulsubmx _ 3 1 3 1 E).
Let lin_of_twistD E1 E2 :
lin_of_twist (E1 + E2) = lin_of_twist E1 + lin_of_twist E2 :> 'rV[T]__.
Proof.
rewrite /lin_of_twist -{1}(@submxK _ 3 1 3 1 E1) -{1}(@submxK _ 3 1 3 1 E2).
set a := ulsubmx _. set b := ursubmx _. by rewrite (add_block_mx a b) block_mxKdl.
Qed.
Let lin_of_twistZ k E : lin_of_twist (k *: E) = k *: lin_of_twist E :> 'rV[T]__.
Proof.
by rewrite /lin_of_twist -{1}(@submxK _ 3 1 3 1 E) (@scale_block_mx _ 3 1 3 1 k) block_mxKdl.
Qed.
Lemma linear_lin_of_twist : linear lin_of_twist.
Proof. move=> k u v; by rewrite lin_of_twistD lin_of_twistZ. Qed.
HB.instance Definition _ := @GRing.isLinear.Build _ _ _ _ _ linear_lin_of_twist.
Let ang_of_twistD E1 E2 :
ang_of_twist (E1 + E2) = ang_of_twist E1 + ang_of_twist E2 :> 'rV[T]__.
Proof.
rewrite /ang_of_twist -{1}(@submxK _ 3 1 3 1 E1) -{1}(@submxK _ 3 1 3 1 E2).
set b := ursubmx _. set c := dlsubmx _.
by rewrite (add_block_mx _ b c) block_mxKul unspinD.
Qed.
Let ang_of_twistZ k E : ang_of_twist (k *: E) = k *: ang_of_twist E :> 'rV[T]__.
Proof.
rewrite /ang_of_twist -{1}(@submxK _ 3 1 3 1 E) (@scale_block_mx _ 3 1 3 1 k) block_mxKul.
by rewrite unspinZ.
Qed.
Lemma linear_ang_of_twist : linear ang_of_twist.
Proof. move=> k u v; by rewrite ang_of_twistD ang_of_twistZ. Qed.
HB.instance Definition _ := @GRing.isLinear.Build _ _ _ _ _ linear_ang_of_twist.
End se3_qualifier.
Notation "''se3[' R ]" := (se3 R) : ring_scope.
Section twist_properties.
Variable T : realFieldType.
Let vector := 'rV[T]_3.
Implicit Types t : twist T.
Implicit Types E : 'M[T]_4.
Definition wedge t : 'M_4 := block_mx \S(\w( t )) 0 (\v( t )) 0.
Definition vee E : twist T := \T(lin_of_twist E, ang_of_twist E).
(* NB: se3 is isomorphic to R^6 via this mapping *)
Lemma lin_of_twist_wedge t : \v( t ) = lin_of_twist (wedge t).
Proof. by rewrite /Twist.lin /lin_of_twist /wedge block_mxKdl. Qed.
Lemma ang_of_twist_wedge t : \w( t ) = ang_of_twist (wedge t).
Proof. by rewrite /Twist.ang /ang_of_twist /wedge block_mxKul spinK. Qed.
Lemma injective_wedge : injective wedge.
Proof.
move=> x y; rewrite /wedge => /(@eq_block_mx _ _ _ _ _ \S(\w( x )) 0 \v(x) 0).
case => /eqP; rewrite spin_inj => /eqP Hw _ Hv _.
by rewrite -(twist_mkE x) Hv Hw twist_mkE.
Qed.
Lemma tcoorZ k u v : k *: wedge \T(u, v) = wedge \T(k *: u, k *: v).
Proof.
by rewrite /wedge !Twist.ang_of !Twist.lin_of (scale_block_mx k \S(v))
2!scaler0 spinZ.
Qed.
Lemma linear_wedge : linear wedge.
Proof.
move=> k x y.
rewrite /wedge (scale_block_mx k \S(\w(x))) !scaler0.
rewrite (add_block_mx _ _ _ _ \S(\w(y))) !addr0.
by rewrite -spinZ -spinD -ang_tcoorZ ang_tcoorD -lin_tcoorZ lin_tcoorD.
Qed.
HB.instance Definition _ := @GRing.isLinear.Build _ _ _ _ _ linear_wedge.
(*
TODO?
Lemma se3E (M : 'M[T]_4) : (M \is se3) = (M == \T( \v( vee M ), \w( vee M ))).
Proof.
apply/idP/idP => [|/eqP ->].
rewrite qualifE => /and3P[].
rewrite qualifE => /eqP H1 /eqP H2 /eqP H3.
rewrite -{1}(@submxK _ 3 1 3 1 M) H2 H3.
rewrite /wedge /=.
rewrite Twist.ang_of Twist.lin_of.
rewrite /vee.
rewrite unskewK //. qualifE; by apply/eqP.
rewrite qualifE.
rewrite /wedge.
rewrite block_mxKul /= block_mxKur /= eqxx /=.
by rewrite block_mxKdr eqxx andbT anti_skew.
Qed.*)
(* [murray] p.56, lem 2.13 (part 1) *)
Lemma conj_SE3_se3 t g : g \is 'SE3[T] -> g^-1 * wedge t * g \is 'se3[T].
Proof.
move=> Hg; rewrite -inv_homE // /inv_hom /hom /wedge.
rewrite [in X in _ * _ * X \is _](SE3E Hg) /hom -mulmxE.
set r := rot_of_hom g. set p := rot_of_hom g.
rewrite (mulmx_block r^T _ _ _ \S(\w( t ))) !(mulmx0,addr0,mul0mx,mul1mx).
rewrite (mulmx_block (r^T *m \S(\w( t ))) _ _ _ r) !(mulmx0,mul0mx,addr0).
rewrite qualifE; apply/and3P; rewrite ?block_mxKul ?block_mxKur ?block_mxKdr.
split => //; by rewrite conj_so // spin_is_so.
Qed.
Lemma linear_vee : linear vee.
Proof.
move=> k x y.
rewrite {1}/vee 2!linearD 2!linearZ; apply: injective_wedge.
rewrite /vee linear_wedge tcoorZ -[X in _ = X + _]scale1r -linear_wedge.
by rewrite scale1r -twistD.
Qed.
HB.instance Definition _ := @GRing.isLinear.Build _ _ _ _ _ linear_vee.
Lemma veeK E : E \is 'se3[T] -> wedge (vee E) = E.
Proof.
rewrite qualifE antiE => /and3P[/eqP H1 /eqP H2 /eqP H3].
rewrite /wedge /vee ang_tcoorE lin_tcoorE /lin_of_twist.
rewrite -[in RHS](@submxK _ 3 1 3 1 E) H1 H2 H3; f_equal.
rewrite unspinK // antiE; by apply/eqP.
Qed.
Lemma wedgeK t : vee (wedge t) = t.
Proof.
rewrite /vee /wedge /lin_of_twist /ang_of_twist block_mxKdl block_mxKul spinK.
by rewrite twist_mkE.
Qed.
Lemma lie_wedgeE t1 t2 :
let v1 := \v( t1 ) in let v2 := \v( t2 ) in
let w1 := \w( t1 ) in let w2 := \w( t2 ) in
lie[wedge t1, wedge t2] =
block_mx \S( w2 *v w1 ) 0 (w2 *v v1 + v2 *v w1) 0.
Proof.
move=> v1 v2 w1 w2.
transitivity (wedge t1 * wedge t2 - wedge t2 * wedge t1) => //.
rewrite /wedge -/v1 -/v2 -/w1 -/w2.
rewrite -mulmxE.
rewrite (mulmx_block \S(w1) 0 v1 0 \S(w2)).
rewrite (mulmx_block \S(w2) 0 v2 0 \S(w1)).
rewrite !(mul0mx,addr0,mulmx0).
rewrite (opp_block_mx (\S(w2) *m \S(w1))) !oppr0.
rewrite (add_block_mx (\S(w1) *m \S(w2))) !addr0.
by rewrite 2!spinE spin_crossmul (@lieC _ (vec3 T) w1 v2) opprK.
Qed.
Lemma lie_wedgeE' t1 t2 :
let v1 := \v( t1 ) in let v2 := \v( t2 ) in
let w1 := \w( t1 ) in let w2 := \w( t2 ) in
lie[wedge t1, wedge t2] = wedge \T( w2 *v v1 + v2 *v w1, w2 *v w1).
Proof.
move=> v1 v2 w1 w2.
by rewrite lie_wedgeE -/v1 -/v2 -/w1 -/w2 /wedge Twist.lin_of Twist.ang_of.
Qed.
End twist_properties.
Section twist_and_adjoint.
(*see differential_kinematics.v for an application*)
Variable T : realFieldType.
Implicit Types t : twist T.
Definition SE3_action (g : 'M[T]_4) t : twist T := t *m Adjoint g.
(* [murray] p.56, lem 2.13 (part 2)
action of 'SE3[T] on twist coordinates *)
Lemma action_Adjoint g : g \is 'SE3[T] -> forall t,
SE3_action g t = vee (g^-1 * wedge t * g).
Proof.
move=> gSE t.
rewrite /SE3_action.
(* lhs *)
rewrite [in LHS]/Adjoint -[in LHS](twist_mkE t) (mulmx_block \v(t) _ 0 0 (rot_of_hom g)).
rewrite !(mulmx0,mul0mx,addr0,add0r).
(* rhs *)
rewrite [in X in _ = vee (_ * _ * X)](SE3E gSE) [in RHS]/hom -mulrA -[in RHS]mulmxE.
rewrite (mulmx_block \S( \w( t ) ) 0 ( \v( t ) ) 0 (rot_of_hom g)).
rewrite !(mulmx0,add0r,mul1mx,mul0mx,addr0).
rewrite -[in RHS]inv_homE // [in RHS]/inv_hom [in RHS]/hom.
rewrite (mulmx_block (rot_of_hom g)^T 0 _ 1 (\S( \w( t ) ) *m rot_of_hom g)).
rewrite !(mul0mx,addr0,mulmx0,mul1mx).
set a' := _ + _. set b' := _ *m _.
set a := _ *m _. set b := _ + _.
rewrite /vee /lin_of_twist block_mxKdl /ang_of_twist block_mxKul /Twist.mk.
f_equal.
- rewrite {}/a' {}/b [in RHS]addrC; congr (_ + _).
rewrite -mulmxE -mulmxA mulmxE mulNmx mulrA spin_similarity ?rot_of_hom_is_SO //.
by rewrite -!mulmxE mulmxA spinE (@lieC _ (vec3 T)) /= -spinE.
- by rewrite {}/a {}/b' mulmxA !mulmxE spin_similarity // ?rot_of_hom_is_SO // spinK.
Qed.
Lemma SE3_action_neutral t : SE3_action 1 t = t.
Proof. by rewrite /SE3_action Adjoint1 mulmx1. Qed.
Lemma SE3_action_comp (g1 g2 : 'M[T]_4) t :
g1 \is 'SE3[T] -> g2 \is 'SE3[T] ->
SE3_action g1 (SE3_action g2 t) = SE3_action (g2 * g1) t.
Proof. by move=> ? ?; rewrite /SE3_action -mulmxA AdjointM. Qed.
Lemma linear_action_Adjoint g : g \is 'SE3[T] -> linear (SE3_action g).
Proof. move=> Hg k y x; by rewrite /SE3_action mulmxDl scalemxAl. Qed.
(*
(* NB: wrong? *)
Lemma AdjointE t1 t2 :
t1 *m Adjoint (wedge t2) = vee lie[wedge t1, wedge t2].
Proof.
rewrite lie_wedgeE' wedgeK.
rewrite /Adjoint.
rewrite -{1}(twist_mkE t1).
rewrite (mulmx_block \v(_) \w(_) 0 0 (rot_of_hom (wedge _))).
rewrite !(mul0mx,mulmx0,add0r).
rewrite /rot_of_hom /wedge block_mxKul.
rewrite /trans_of_hom block_mxKdl.
rewrite /Twist.mk; f_equal; last by rewrite spinE.
rewrite spinE; congr (_ + _).
rewrite -mulmxE mulmxA spinE; congr (_ *v _).
rewrite spinE.
Abort.
*)
End twist_and_adjoint.
Section sample_rigid_transformation.
Variable T : comRingType.
Let vector := 'rV[T]_3.
Implicit Types v w : vector.
Definition rigid_trans w v := hom 1 (v *v w).
Definition inv_rigid_trans w v := hom 1 (- v *v w).
Lemma Vrigid_trans w v : inv_rigid_trans w v * rigid_trans w v = 1.
Proof.
by rewrite /inv_rigid_trans /rigid_trans homM mulr1 mulmx1 addrC linearNl subrr hom10.
Qed.
Lemma rigid_transV w v : rigid_trans w v * inv_rigid_trans w v = 1.
Proof.
by rewrite /inv_rigid_trans /rigid_trans homM mulr1 mulmx1 linearNl subrr hom10.
Qed.
End sample_rigid_transformation.
Section sample_rigid_cont.
Variable T : comUnitRingType.
Let vector := 'rV[T]_3.
Implicit Types v w : vector.
Lemma rigid_trans_unitmx w v : rigid_trans w v \in unitmx.
Proof.
by rewrite unitmxE /rigid_trans (det_lblock 1 (_ *v _)) 2!det1 mulr1 unitr1.
Qed.
Lemma inv_rigid_transE w v : (rigid_trans w v)^-1 = inv_rigid_trans w v.
Proof.
rewrite -[LHS]mul1mx -[X in X *m _ = _](Vrigid_trans w v) -mulmxA.
by rewrite mulmxV ?rigid_trans_unitmx // mulmx1.
Qed.
Lemma rigid_trans_unit w v : rigid_trans w v \is a GRing.unit.
Proof.
apply/unitrP; exists (inv_rigid_trans w v); by rewrite Vrigid_trans rigid_transV.
Qed.
End sample_rigid_cont.
(* exponential coordinates for rbt using taylor expansion of the exponential function *)
(* [murray] proposition 2.8, p. 41-42 *)
Section exponential_coordinates_rigid_using_taylor.
Variable T : rcfType.
Let vector := 'rV[T]_3.
Implicit Types w v : vector.
Lemma exp_twist0v v n : (wedge \T(v, 0)) ^+ n.+2 = 0.
Proof.
elim: n => [|n ih]; last by rewrite exprS ih mulr0.
rewrite expr2.
rewrite /wedge Twist.ang_of Twist.lin_of spin0 -mulmxE.
set a := 0. set b := 0.
by rewrite (mulmx_block a b v _ a b v _) /a /b !(mulmx0,addr0,mul0mx) block_mx0.
Qed.
(* [murray] eqn 2.32, p.41 *)
Lemma emx_twist0E v k : emx (wedge \T(v, 0)) k.+2 = hom 1 v.
Proof.
rewrite /emx 2!big_ord_recl big1 ?addr0; last first.
move=> /= i _; by rewrite ecoefE exp_twist0v scaler0.
rewrite liftE0 eqxx /ecoef factS fact0 expr0 expr1 invr1 2!scale1r.
rewrite /wedge Twist.ang_of Twist.lin_of spin0.
by rewrite -idmxE (@scalar_mx_block _ 3 1 1) (add_block_mx 1 0 0 1 0 _ v) !(addr0,add0r).
Qed.
Lemma p41eq234 w v : norm w = 1 ->
let g := rigid_trans w v in
let h := w *d v in
g^-1 *m wedge \T(v, w) *m g = wedge \T(h *: w, w).
Proof.
move=> w1 g h.
rewrite inv_rigid_transE /inv_rigid_trans /rigid_trans.
rewrite /wedge !Twist.ang_of !Twist.lin_of.
rewrite (mulmx_block 1 0 (- _ *v _) 1 \S( w )) !(mulmx0,addr0,mul0mx,mul1mx).
rewrite spinE linearNl linearNr /=.
rewrite double_crossmul dotmulvv w1 expr1n scale1r opprB subrK.
by rewrite (mulmx_block \S( w ) 0 _ 0 1 0) !(mulmx0,addr0,mul0mx,mul1mx,mulmx1).
Qed.
Lemma p42eq235 w v a k :
let g := rigid_trans w v in
let e' := g^-1 *m wedge \T(v, w) *m g in
emx (a *: wedge \T(v, w) ) k = g * emx (a *: e') k * g^-1.
Proof.
move=> g e'.
rewrite -emx_mulmulV ?rigid_trans_unitmx //; congr (emx _ _).
rewrite /e' mulmxE -/g -(mulrA g^-1) -scalerAr -scalerAl; congr (_ *: _).
rewrite !mulrA divrr ?rigid_trans_unit // mul1r -mulrA.
by rewrite divrr ?mulr1 // rigid_trans_unit.
Qed.
Lemma p42eq2 w v : norm w = 1 ->
let g := rigid_trans w v in
let e' := g^-1 *m wedge \T(v, w) *m g in
forall k, e' ^+ k.+2 = block_mx (\S( w ) ^+ k.+2) 0 0 0.
Proof.
move=> w1 g e' k.
rewrite /e' (p41eq234 _ w1).
set h := w *d v.
rewrite /wedge Twist.ang_of Twist.lin_of.
elim: k => [|k ih].
rewrite (@expr2 _ (block_mx \S( w ) _ _ _)) -mulmxE.
rewrite (mulmx_block \S( w ) _ _ _ \S( w )).
by rewrite !(mulmx0,addr0,mul0mx) mulmxE -expr2 spinE linearZr_LR (@liexx _ (vec3 T))/= scaler0.
rewrite exprS ih -mulmxE (mulmx_block \S( w ) _ _ _ (\S( w ) ^+ k.+2)).
rewrite !(mulmx0,addr0,mul0mx) mulmxE -exprS; congr (block_mx (\S( w ) ^+ k.+3) 0 _ 0).
by rewrite exprS mulmxA spinE linearZr_LR/= (@liexx _ (vec3 T)) scaler0 mul0mx.
Qed.
Lemma emx2_twist w v a : norm w = 1 ->
let g := rigid_trans w v in
let h := w *d v in
emx (a *: wedge \T(v, w) ) 2 = g *m hom (emx (a *: \S( w)) 2) (h *: (a *: w)) *m g^-1.
Proof.
move=> w1 g h.
rewrite {1}/emx 2!big_ord_recl big_ord0 addr0 liftE0 eqxx /ecoef factS fact0 invr1 2!scale1r.
rewrite expr0 expr1.
rewrite (_ : 1 = @block_mx _ 3 _ 3 _ 1 0 0 1); last first.
by rewrite -idmxE (@scalar_mx_block _ 3 1 1).
rewrite tcoorZ /=.
rewrite /wedge Twist.ang_of Twist.lin_of (add_block_mx 1 0 0 1 \S( a *: w )) !(addr0,add0r).
rewrite {1}/g /rigid_trans mulmxE homM mul1r.
rewrite inv_rigid_transE /inv_rigid_trans homM mulr1 mulmx1 emx2.
rewrite -spinZ.
congr (block_mx (1 + \S( a *: w )) 0 _ 1).
rewrite mulmxDr mulmx1 linearNl -addrA addrC addrA subrK spinE.
rewrite scalerA (mulrC h) -scalerA /= linearZl_LR /= -scalerDr; congr (_ *: _).
by rewrite double_crossmul dotmulvv w1 expr1n scale1r -/h addrCA subrr addr0.
Qed.
Lemma p42eq3 w v a : norm w = 1 ->
let g := rigid_trans w v in
let h := w *d v in
let e' := g^-1 *m wedge \T(v, w) *m g in
forall k, emx (a *: e') k.+2 = hom (emx (a *: \S( w )) k.+2) (h *: (a *: w)).
Proof.
move=> w1 g h e'; rewrite /e'.
elim => [|k ih].
rewrite -{2}(invrK g) scalemxAl scalemxAr.
rewrite emx_mulmulV ?unitrV ?rigid_trans_unit //.
rewrite emx2_twist // !mulmxE !mulrA mulVr ?rigid_trans_unit // mul1r.
by rewrite -!mulrA divrr ?unitrV ?rigid_trans_unit // mulr1.
rewrite emxS ih /ecoef exprZn p42eq2 //.
rewrite (scale_block_mx (a ^+ k.+2) (\S(w) ^+ k.+2)) !scaler0.
rewrite -exprZn -spinZ.
rewrite (scale_block_mx ((k.+2)`!%:R^-1) (\S( (a *: w) ) ^+ k.+2)) !scaler0.
by rewrite (add_block_mx (emx \S( a *: w ) k.+2)) !(addr0) -emxS.
Qed.
Definition hom_twist (t : twist T) (a : T) e : 'M[T]_4 :=
let (v, w) := (\v( t ), \w( t )) in
if w == 0 then
hom 1 (a *: v)
else
hom e ((norm w)^-2 *: ((w *v v) *m (1 - e) + (a *: v) *m (w^T *m w))).
(* [murray] eqn 2.36, p.42 *)
Definition emx_twist a t k : 'M_4 :=
hom_twist t a (emx \S( a *: \w( t ) ) k).
(* [murray] eqn 2.36, p.42 *)
Lemma emx_twistE (t : twist T) a k :
emx (a *: wedge t) k.+2 = emx_twist a t k.+2.
Proof.
set v := lin_of_twist (wedge t).
set w := ang_of_twist (wedge t).
rewrite (_ : t = \T(v, w)); last first.
by rewrite -(twist_mkE t) lin_of_twist_wedge ang_of_twist_wedge.
case/boolP : (w == 0) => [/eqP ->|w0].
rewrite tcoorZ /= scaler0 emx_twist0E.
by rewrite /emx_twist /hom_twist ang_tcoorE eqxx lin_tcoorE.
set w' : 'rV_3 := a *: w.
rewrite -(norm_scale_normalize w) (_ : v = (norm w) *: ((norm w)^-1 *: v)); last first.
by rewrite scalerA divrr ?scale1r // unitfE norm_eq0.
rewrite -(tcoorZ (norm w) ((norm w)^-1 *: v) (normalize w)).
rewrite scalerA p42eq235 p42eq3; last by rewrite norm_normalize.
rewrite -mulmxE.
rewrite {1}/rigid_trans mulmxE homM mul1r.
rewrite inv_rigid_transE /inv_rigid_trans homM mulr1 mulmx1.
rewrite -scalerA -spinZ norm_scale_normalize.
rewrite -scalerA norm_scale_normalize.
rewrite /emx_twist /hom_twist.
rewrite ang_tcoorE (negbTE w0) [in RHS]spinZ; congr hom.
rewrite linearZl_LR /= linearZr_LR /= scalerA.
rewrite dotmulZv dotmulvZ !mulrA -[in X in _ + X + _]scalerA.
rewrite /normalize.
rewrite (linearZr_LR crossmul _ _ w) /=.
rewrite linearNl /=.
rewrite (linearZl_LR crossmul) /=.
rewrite [in X in _ + _ + X = _]scalerN.
rewrite [in X in _ + _ + X]scalerA.
rewrite -[in LHS]scalemxAl -scalerDr -scalerBr; congr (_ *: _).
by rewrite -invrM ?unitfE ?norm_eq0.
rewrite -/w' /= [in X in _ = X + _]mulmxBr mulmx1.
rewrite -[in RHS]addrA [in RHS]addrC; congr (_ + _ + _).
- rewrite lin_tcoorE (@lieC _ (vec3 T)) mulNmx.
by rewrite scalerA divrr ?scale1r // ?unitfE ?norm_eq0.
- rewrite lin_tcoorE.
rewrite (scalerA (norm w)) divrr ?scale1r ?unitfE ?norm_eq0 //.
rewrite -scalemxAl.
rewrite mulmxA.
rewrite dotmulP mul_scalar_mx dotmulC.
by rewrite scalerA mulrC -scalerA.
- rewrite (@lieC _ (vec3 T)) opprK; congr (_ *v _).
by rewrite lin_tcoorE scalerA divrr ?scale1r ?lin_of_twistE // unitfE norm_eq0.
Qed.
(* [murray] proposition 2.8, p. 41 *)
Lemma emx_twist_SE3 v w a k :
emx \S(a *: w) k.+2 \is 'SO[T]_3 ->
emx (a *: wedge \T(v, w)) k.+2 \is 'SE3[T].
Proof.
move=> emx_SO; rewrite emx_twistE.
rewrite /emx_twist /hom_twist ang_tcoorE.
case: ifPn => [_|w0]; by rewrite hom_is_SE // rpred1.
Qed.
End exponential_coordinates_rigid_using_taylor.
Section exponential_coordinates_rigid.
Variable T : realType.
(* NB: same definition as exp_twist but using exp_mat instead of the taylor expansion of
the exponential *)
(* [springer] eqn 1.27, p. 17, closed expression for the exponential of a twist *)
Definition etwist a (t : twist T) :=
hom_twist t a (`e^(a, \w( t ))).
Local Notation "'`e$(' a ',' t ')'" := (etwist a t) (format "'`e$(' a ',' t ')'").
Lemma etwistv0 (a : T) : `e$(a, \T(0, 0)) = hom 1 0.
Proof. by rewrite /etwist ang_tcoorE /hom_twist ang_tcoorE eqxx lin_tcoorE scaler0. Qed.
Lemma etwist_is_SE (t : twist T) a : norm \w( t ) = 1 -> `e$(a, t) \is 'SE3[T].
Proof.
move=> w1.
by rewrite /etwist /hom_twist (negbTE (norm1_neq0 w1)) hom_is_SE // eskew_is_SO.
Qed.
Definition etwist_is_onto_SE_mat (a : T) w :=
(a * norm w ^+ 2)%:A
+ ((1 - cos a) * norm w ^+2) *: \S(w)
+ (a - sin a) *: \S(w)^+2.
(*******************STOP*****************************)
Definition etwist_is_onto_SE_mat_inv (a : T) w :=
a^-1%:M
- 2%:R^-1 *: \S(w)
+ (a^-1 - 2%:R^-1 * cot (a / 2%:R)) *: \S(w) ^+ 2.
Lemma etwist_is_onto_SE_matP a w
(aB : - pi < a <= pi) (a0 : a != 0) (w1 : norm w = 1) :
etwist_is_onto_SE_mat_inv a w * etwist_is_onto_SE_mat a w = 1.
Proof.
rewrite /etwist_is_onto_SE_mat /etwist_is_onto_SE_mat_inv.
rewrite w1 expr1n !mulr1.
rewrite !mulrDl.
rewrite 6!mulrDr.
rewrite {1}scalemx1 -{1}mulmxE -scalar_mxM mulVf //.
rewrite -[RHS]addr0 -!addrA; congr (_ + _); rewrite !addrA.
rewrite -!mulmxE.
rewrite !mul_scalar_mx scalemx1 !mul_mx_scalar.
rewrite -!scalemxAl -!scalemxAr.
rewrite 2!mulNmx.
rewrite (scalerN (1 - cos a) (_ *m _)).
rewrite (scalerN (a - sin a) (_ *m _)).
rewrite -!scalemxAl mulmxE -expr2 -exprSr -exprS -exprD.
rewrite (exp_spin _ O) expr1 (exp_spin _ 1).
rewrite w1 expr1n 2!scaleN1r.
rewrite !(scalerN _ \S(w)) !(scalerN _ (\S(w) ^+ 2)).
rewrite (scalerN (a - sin a)) opprK.
rewrite (scalerBl a (sin a) (_ *: _)).
rewrite -!addrA.
rewrite (addrCA (a *: - _)).
rewrite !addrA.
rewrite (scalerN a) subrK.
rewrite (scalerBl (a^-1) _ (- (_ *: \S(w) ^+ 2))).
rewrite (scalerN (a^-1)).
rewrite (addrC (- (_))) !addrA addrC.
rewrite -!addrA.
rewrite addrCA.
rewrite !addrA subrK.
rewrite (scalerBl (a^-1) _ (- (_ *: \S(w)))).
rewrite addrAC.
rewrite (addrC (a^-1 *: - _)) addrA addrC.
rewrite scalerN !addrA.
rewrite (addrC (- _)) subrr add0r.
rewrite (scalerA a).
rewrite mulrBr divff //.
rewrite [X in _ + X - _ + _]scalerBl scale1r.
rewrite (scalerN (2%:R^-1 * _)) opprK.
rewrite (scalerA (2%:R^-1 * _)).
rewrite mulrBr.
rewrite [X in _ + _ + X - _]scalerBl !addrA.
rewrite mulrCA (mulrC a) mulrA.
rewrite subrK.
case/boolP : (sin a == 0) => [|saD0].
rewrite sin_eq0_Npipi // (negPf a0) => /eqP->.
rewrite cospi sinpi scale0r subr0 mulr0 scale0r subr0.
rewrite cot_pihalf mulr0 scale0r subr0 opprK (_ : 1 + 1 = 2%:R) // scalerA.
by rewrite divff ?pnatr_eq0 // scale1r addrC subrr.
rewrite {1}cot_half_angle' -!mulrA mulVf // mulr1 cot_half_angle.
rewrite (scalerN (2%:R^-1 * _)) opprK (scalerA (2%:R^-1 * _)).
rewrite -!mulrA mulVf ?mulr1; last first.
rewrite subr_eq0 eq_sym; apply: contra saD0 => /eqP caE.
by rewrite cos1sin0 // caE normr1.
rewrite (addrC (- _)) addrC !addrA.
rewrite scalerA mulrC subrr add0r.
rewrite (mulrC 2%:R^-1).
rewrite -scalerA.
rewrite scalerBl scale1r opprB.
rewrite scalerDl scale1r opprD !addrA addrC !addrA.
rewrite (addrC (- (cos a *: _))) subrr add0r.
rewrite addrAC.
rewrite -scaleNr -scalerDl.
rewrite -opprD -div1r -splitr scaleN1r.
by rewrite addrC subrr.
Qed.
Lemma etwist_is_onto_SE (f : 'M[T]_4) : f \is 'SE3[T] ->
exists t a, f = `e$(a, t).
Proof.
set p := trans_of_hom f.
case/boolP: (rot_of_hom f == 1) => rotf fSE.
case/boolP : ((norm p) == 0) => p0.
exists \T(p, 0), 1.
rewrite /etwist /hom_twist ang_tcoorE eqxx lin_tcoorE.
by rewrite scale1r (SE3E fSE) (eqP rotf).
exists \T((norm p)^-1 *: p, 0), (norm p).
rewrite /etwist /hom_twist ang_tcoorE eqxx /= lin_tcoorE.
rewrite scalerA divff //.
by rewrite scale1r (SE3E fSE) (eqP rotf).
case: (eskew_is_onto_SO (rot_of_hom_is_SO fSE)) => a aB fexp_skew.
set w := normalize (vaxis_euler _) in fexp_skew.
have a0 : a != 0.
apply: contra rotf => /eqP.
rewrite fexp_skew => ->; by rewrite emx30M.
set A : 'M_3 := \S(w) *m (1 - rot_of_hom f) + a *: (w^T *m w).
suff [v Hv] : { v | p = (norm w)^-2 *: (v *m A) }.
exists \T(v, w), a.
rewrite (SE3E fSE) /etwist /hom_twist ang_tcoorE.
have /negbTE -> : w != 0 by rewrite normalize_eq0 vaxis_euler_neq0 // rot_of_hom_is_SO.
rewrite fexp_skew -/p Hv; congr (hom _ (_ *: _)).
by rewrite lin_tcoorE /A mulmxDr mulmxA spinE -scalemxAr -scalemxAl fexp_skew.
have HA : A = etwist_is_onto_SE_mat a w.
(* TODO: isolate as a lemma? *)
rewrite /A /etwist_is_onto_SE_mat.
rewrite fexp_skew /emx3.
rewrite mulmxBr mulmx1 -(addrA 1) mulmxDr mulmx1 -!addrA opprD !addrA subrr add0r.
rewrite mulmxDr.
rewrite -scalemxAr mulmxE -expr2 opprD.
rewrite [in X in _ = _ + X]scalerBl.
rewrite ![in RHS]addrA [in RHS]addrC.
rewrite -addrA; congr (_ + _).
rewrite -scalerAr.
rewrite -exprS spin3.
rewrite sqr_spin.
rewrite scalerBr.
rewrite -![in RHS]addrA [in RHS]addrC ![in RHS]addrA.
rewrite !scalemx1.
rewrite -[X in _ - _ + X]scale_scalar_mx.
rewrite subrK.
by rewrite scaleNr scalerN opprK scalerA.
suff : { A' : 'M_3 | A' * A = 1 }.
case => A' AA'.
exists ((norm w) ^+2 *: p *m A').
rewrite -mulmxA mulmxE AA' mulmx1 scalerA.
rewrite mulrC divrr ?scale1r // unitfE expf_eq0 /= norm_eq0.
apply: contra rotf; rewrite fexp_skew => /eqP ->.
by rewrite spin0 emx3a0.
(* NB: corresponds to [murray], exercise 9, p.75 *)
(* NB: formula for the inverse matrix in
[Introduction to Robotics: Mechanics, Planning, and Control,
F.C. Park, K. Lynch, Mar. 14 2012] *)
exists (etwist_is_onto_SE_mat_inv a w); rewrite HA.
apply: etwist_is_onto_SE_matP => //.
by rewrite norm_normalize // vaxis_euler_neq0 // rot_of_hom_is_SO.
Qed.
(*
Lemma image_skew_mx (w : 'rV[T]_3) (w0 : w != 0) : (\S(w) == w^C)%MS.
Proof.
have rank_w : \rank (w)%MS = 1%N by rewrite rank_rV w0.
have rank_wC : \rank (w^C)%MS = 2%N by rewrite mxrank_compl rank_w.
have rank_kskew : \rank (kermx \S(w)) = 1%N by rewrite -[RHS]rank_w (eqmx_rank (kernel_spin w0)).
have rank_skew : \rank \S(w) = 2%N.
move: rank_kskew; rewrite mxrank_ker => /eqP.
rewrite -(eqn_add2r (\rank \S(w))) subnK; last by rewrite rank_leq_row.
rewrite add1n => /eqP[] <-; by apply/eqP.
move: (kernel_spin w0) => H.
Abort.
*)
End exponential_coordinates_rigid.
Notation "'`e$(' a ',' t ')'" := (etwist a t) (format "'`e$(' a ',' t ')'").
(* [murray] example 2.6 *)
Module TwistComputationExample.
Section example.
Variable T : realType.
Let vector := 'rV[T]_3.
Variables a1 a2 : T.
Variable a : T.
Hypothesis aB : - pi < a <= pi.
Hypothesis a0 : a != 0.
Definition P20 := row3 (a1 + a2 * cos a) (a2 * sin a) 0.
Definition w : vector := 'e_2%:R.
Let A_inv := etwist_is_onto_SE_mat_inv a w.
Definition v := ((norm w)^+2 *: P20) *m A_inv.
Lemma vP : v = row3 ((a1 + a2) * sin a / (2%:R * (1 - cos a))) (- (a1 - a2) / 2%:R) 0 :> vector.
Proof.
rewrite /v normeE expr1n scale1r /P20.
rewrite /A_inv /etwist_is_onto_SE_mat_inv.
rewrite mulmxDr mulmxBr.
rewrite mul_mx_scalar row3Z mulr0.
rewrite -scalemxAr scalemxAl row3Z mulr0 spinE crossmulE !mxE /=. Simp.r. rewrite /=.
rewrite -scaleN1r row3Z !mulN1r opprK oppr0 row3D addr0.
rewrite -scalemxAr scalemxAl expr2 -mulmxE mulmxA -scalemxAl.
rewrite (spinE (row3 _ _ _)) crossmulE !mxE /=. Simp.r.
rewrite -scalemxAl spinE crossmulE !mxE /=. Simp.r.
rewrite row3Z mulr0 row3D addr0.
case/boolP : (a == pi) => [/eqP ->|api].
rewrite cot_half_angle sinpi cospi !(mulr0,addr0,subr0,oppr0,add0r,mul0r,mulrN1).
rewrite mulrN subrr.
by rewrite mulrC.