29package com.jogamp.opengl.test.junit.math;
31import org.junit.Assert;
33import org.junit.FixMethodOrder;
34import org.junit.runners.MethodSorters;
36import com.jogamp.junit.util.JunitTracer;
37import com.jogamp.math.FloatUtil;
38import com.jogamp.math.Quaternion;
39import com.jogamp.math.Vec3f;
41@FixMethodOrder(MethodSorters.NAME_ASCENDING)
43 static final boolean DEBUG =
false;
49 static final Vec3f NEG_ONE =
new Vec3f ( -1f, -1f, -1f );
63 final Vec3f v0 = UNIT_X;
65 Assert.assertEquals(1f, v0.
length(), MACH_EPSILON);
73 System.err.println(
"Test 0-deg, UNIT_X vecs");
74 final Vec3f v0 = UNIT_X;
75 final Vec3f v1 = UNIT_X;
76 System.err.println(
"v0 "+v0);
77 System.err.println(
"v1 "+v1);
78 final float a0_v0_v1 = v0.
angle(v1);
79 System.err.println(
"a0(v0, v1) = "+a0_v0_v1+
" rad, "+
FloatUtil.
radToADeg(a0_v0_v1)+
" deg, via dot, acos");
80 Assert.assertEquals(0f, a0_v0_v1, MACH_EPSILON);
84 System.err.println(
"Test 0-deg, free vecs");
88 System.err.println(
"v0 "+v0);
89 System.err.println(
"v1 "+v1);
90 System.err.println(
"v0_1 "+v0_1);
92 final float a0_x_v0_1 = UNIT_X.
angle(v0_1);
93 System.err.println(
"a0(X, v0_1) = "+a0_x_v0_1+
" rad, "+
FloatUtil.
radToADeg(a0_x_v0_1)+
" deg, via dot, acos");
94 Assert.assertEquals(0f, a0_x_v0_1, MACH_EPSILON);
98 System.err.println(
"Test 180-deg, free vecs");
102 System.err.println(
"v0 "+v0);
103 System.err.println(
"v1 "+v1);
104 System.err.println(
"v0_1 "+v0_1);
106 final float a0_x_v0_1 = UNIT_X.
angle(v0_1);
107 System.err.println(
"a0(X, v0_1) = "+a0_x_v0_1+
" rad, "+
FloatUtil.
radToADeg(a0_x_v0_1)+
" deg, via dot, acos");
108 Assert.assertEquals(
FloatUtil.
PI, a0_x_v0_1, MACH_EPSILON);
112 System.err.println(
"Test 90-deg, UNIT_X, UNIT_Y vecs");
113 final Vec3f v0 = UNIT_X;
114 final Vec3f v1 = UNIT_Y;
115 System.err.println(
"v0 "+v0);
116 System.err.println(
"v1 "+v1);
117 final float a0_v0_v1 = v0.
angle(v1);
118 System.err.println(
"a0(v0, v1) = "+a0_v0_v1+
" rad, "+
FloatUtil.
radToADeg(a0_v0_v1)+
" deg, via dot, acos");
123 System.err.println(
"Test 180-deg, UNIT_X, UNIT_X_NEG vecs");
124 final Vec3f v0 = UNIT_X;
125 final Vec3f v1 = UNIT_X_NEG;
126 System.err.println(
"v0 "+v0);
127 System.err.println(
"v1 "+v1);
128 final float a0_v0_v1 = v0.
angle(v1);
129 System.err.println(
"a0(v0, v1) = "+a0_v0_v1+
" rad, "+
FloatUtil.
radToADeg(a0_v0_v1)+
" deg, via dot, acos");
130 Assert.assertEquals(
FloatUtil.
PI, a0_v0_v1, MACH_EPSILON);
134 public static void main(
final String args[]) {
Basic Float math utility functions.
static final float PI
The value PI, i.e.
static final float EPSILON
Epsilon for floating point {@value}, as once computed via getMachineEpsilon() on an AMD-64 CPU.
static float radToADeg(final float rad)
Converts radians to arc-degree.
static final float HALF_PI
The value PI/2, i.e.
Quaternion implementation supporting Gimbal-Lock free rotations.
3D Vector based upon three float components.
static final Vec3f UNIT_X_NEG
float angle(final Vec3f o)
Return the angle between two vectors in radians using Math#acos(double) on cosAngle(Vec3f).
Vec3f normalize()
Normalize this vector in place.
float length()
Return the length of this vector, a.k.a the norm or magnitude
static final Vec3f UNIT_X
Vec3f minus(final Vec3f arg)
Returns this - arg; creates new vector.
static final Vec3f UNIT_Z
static final Vec3f UNIT_Y
static void main(final String args[])