3import java.util.ArrayList;
6import javax.vecmath.AxisAngle4d;
7import javax.vecmath.Matrix3d;
8import javax.vecmath.Point3d;
9import javax.vecmath.Vector3d;
27 v.x = v.x + newOrigin.x;
28 v.y = v.y + newOrigin.y;
29 v.z = v.z + newOrigin.z;
47 return new Vector3d(x, y, z);
60 return new Vector3d((A.x + B.x), (A.y + B.y), (A.z + B.z));
73 return new Vector3d((A.x - B.x), (A.y - B.y), (A.z - B.z));
86 Vector3d normalDir =
new Vector3d();
88 Vector3d dirX =
new Vector3d(1.0, 0.0, 0.0);
89 Vector3d dirY =
new Vector3d(0.0, 1.0, 0.0);
90 Vector3d dirZ =
new Vector3d(0.0, 0.0, 1.0);
91 List<Vector3d> candidates =
new ArrayList<Vector3d>();
97 List<Double> dotProds =
new ArrayList<Double>();
98 boolean found =
false;
100 for (
int i=0; i<candidates.size(); i++)
102 double res = dir.dot(candidates.get(i));
103 double absRes = Math.abs(res);
109 normalDir = candidates.get(i);
113 dotProds.add(absRes);
121 int mostDivergent = dotProds.indexOf(max);
122 normalDir.cross(dir,candidates.get(mostDivergent));
123 normalDir.normalize();
141 double rad = Math.toRadians(ang);
142 AxisAngle4d aa =
new AxisAngle4d(axis.x,axis.y,axis.z,rad);
143 Matrix3d rotMatrix =
new Matrix3d();
145 rotMatrix.transform(v);
Utilities for working in the Cartesian space.
static Vector3d getSumOfVector(Vector3d A, Vector3d B)
Get sum of vector A and B.
static Vector3d getDiffOfVector(Vector3d A, Vector3d B)
Calculates the vector difference of vectors A and B.
static void translateOrigin(Vector3d v, Point3d newOrigin)
Changes the origin of a vector.
static Vector3d getNormalDirection(Vector3d dir)
Generate a vector that is perpendicular to the given one.
static Vector3d getVectorFromTo(Point3d a, Point3d b)
Creates an object Vector3d that originates from point a and goes to point b.
static void rotatedVectorWAxisAngle(Vector3d v, Vector3d axis, double ang)
Rotate a vector according to a given rotation axis and angle.