1 /** This file is part of Shapes.
3 ** Shapes is free software: you can redistribute it and/or modify
4 ** it under the terms of the GNU General Public License as published by
5 ** the Free Software Foundation, either version 3 of the License, or
8 ** Shapes is distributed in the hope that it will be useful,
9 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ** GNU General Public License for more details.
13 ** You should have received a copy of the GNU General Public License
14 ** along with Shapes. If not, see <http://www.gnu.org/licenses/>.
16 ** Copyright 2008, 2010, 2014, 2015 Henrik Tidefelt
20 ##lookin ..Shapes..Geometry3D
22 /** Define transform to work with. **/
23 tf: [shift (3cm,4cm,5cm)]*[Geometry3D..rotate angle:25° dir:(1,1,2)]
24 IO..•stdout << `Linear? ´ << tf.linear? << "{n}
25 IO..•stdout << `Translation? ´ << tf.translation? << "{n}
26 IO..•stdout << `Special? ´ << tf.special? << "{n}
27 IO..•stdout << `Euclidean? ´ << tf.Euclidean? << "{n}
29 IO..•stdout << `Transforms in new coordinates:´ << "{n}
31 /** Compute decompositions, both with automatic and manual selection of rank. **/
32 sda: [Schur_decomp tf]
33 IO..•stdout << sda.U << "{n}
34 IO..•stdout << [sda.U.chop L:0.00001 p:0.000001mm] << ` (chopped)´ << "{n}
36 sdac: [Schur_decomp tf canonical:true]
37 IO..•stdout << sdac.U << "{n}
39 sd0: [Schur_decomp tf rank:'0]
40 IO..•stdout << sd0.U << "{n}
42 sd2: [Schur_decomp tf rank:'2]
43 IO..•stdout << sd2.U << "{n}
45 /** Verify decompositions; if two transforms are equal, then combining one with
46 ** the inverse of the other shall be the identity.
50 /** The decomposition is verified by reconstructing the original transform, and comparing
51 ** with tf by composing with the inverse of tf, and comparing that result with the identity.
52 ** The identity transform is characterized by being both linear and a translation, but to apply
53 ** these predicates we must chop the elements of the transform first.
55 tmp: [( [inverse tf] * decomp.Q*decomp.U*[inverse decomp.Q] ).chop L:0.00001 p:0.00001mm]
56 `Verifying ´ + [Debug..sourceof decomp] + `: ´ + [if tmp.linear? and tmp.translation? `OK´ `Incorrect´]
59 IO..•stdout << `Verification:´ << "{n}
60 IO..•stdout << [check tf [Debug..locate sda]] << "{n}
61 IO..•stdout << [check tf [Debug..locate sdac]] << "{n}
62 IO..•stdout << [check tf [Debug..locate sd0]] << "{n}
63 IO..•stdout << [check tf [Debug..locate sd2]] << "{n}
65 IO..•stdout << `(Not canonical:) Change of coordinates is special? ´ << sda.Q.special? << "{n}
66 IO..•stdout << `(Canonical:) Change of coordinates is special? ´ << sdac.Q.special? << "{n}