Coverage Summary for Class: ChangeOfBasis (net.crystallography.vector.space)
Class | Class, % | Method, % | Line, % |
---|---|---|---|
ChangeOfBasis | 100% (1/ 1) | 33.3% (1/ 3) | 45.5% (5/ 11) |
1 /*---------------------------------------------------------------------------*\
2 **$Author: saulius $
3 **$Date: 2017-11-19 12:24:19 +0200 (Sun, 19 Nov 2017) $
4 **$Revision: 77 $
5 **$URL: svn://www.crystallography.net/smiles-scripts/trunk/src/net/crystallography/vector/space/ChangeOfBasis.java $
6 \*---------------------------------------------------------------------------*/
7
8 // Produce change-of-base matrix and provide a helper function to
9 // change basis of a vector.
10
11 package net.crystallography.vector.space;
12
13 import javax.vecmath.Matrix3d;
14 import javax.vecmath.Point3d;
15 import javax.vecmath.Vector3d;
16
17 public class ChangeOfBasis {
18
19 // Produce a change-of-base matrix given the components of *old*
20 // basis vectors in the *new* basis:
21
22 public static Matrix3d changeOfBaseMatrix( Vector3d va, Vector3d vb,
23 Vector3d vc ) {
24 Matrix3d m = new Matrix3d();
25 m.setColumn(0, va);
26 m.setColumn(1, vb);
27 m.setColumn(2, vc);
28 return m;
29 }
30
31 // Multiply a matrix with a vector (given as a Pion3d) from the
32 // right. If the 'm' matrix was prodcued by the
33 // 'changeOfBaseMatrix()' from this class, and the point 'p'
34 // components are in the same *old* basis, then the result wil be
35 // the point coordinates in the *new* basis:
36
37 public static Point3d mpMultiply( Matrix3d m, Point3d p ) {
38 Point3d xyz = new Point3d();
39 xyz.setX( m.m00 * p.x + m.m01 * p.y + m.m02 * p.z );
40 xyz.setY( m.m10 * p.x + m.m11 * p.y + m.m12 * p.z );
41 xyz.setZ( m.m20 * p.x + m.m21 * p.y + m.m22 * p.z );
42 return xyz;
43 }
44
45 }