29package com.jogamp.math;
67 return new Vec3f(
this);
70 public Vec3f(
final float[] xyz) {
74 public Vec3f(
final float x,
final float y,
final float z) {
103 public Vec3f set(
final float x,
final float y,
final float z) {
111 public Vec3f set(
final float[] xyz) {
127 public void set(
final int i,
final float val) {
129 case 0: x = val;
break;
130 case 1: y = val;
break;
131 case 2: z = val;
break;
132 default:
throw new IndexOutOfBoundsException();
137 public float[]
get(
final float[] xyz) {
145 public float get(
final int i) {
150 default:
throw new IndexOutOfBoundsException();
154 public float x() {
return x; }
155 public float y() {
return y; }
156 public float z() {
return z; }
158 public void setX(
final float x) { this.x = x; }
159 public void setY(
final float y) { this.y = y; }
160 public void setZ(
final float z) { this.z = z; }
164 this.x = Math.
max(this.x, m.x);
165 this.y = Math.
max(this.y, m.y);
166 this.z = Math.
max(this.z, m.z);
171 this.x = Math.
min(this.x, m.x);
172 this.y = Math.
min(this.y, m.y);
173 this.z = Math.
min(this.z, m.z);
179 return new Vec3f(
this).scale(val);
194 public Vec3f mul(
final float sx,
final float sy,
final float sz) {
227 return new Vec3f(
this).add(arg);
239 public Vec3f add(
final float dx,
final float dy,
final float dz) {
256 return new Vec3f(
this).sub(arg);
284 return (
float) Math.sqrt(
lengthSq());
291 return x*x + y*y + z*z;
304 final float invSqr = 1.0f / (float)Math.sqrt(
lengthSq);
320 final float dx = x - o.x;
321 final float dy = y - o.y;
322 final float dz = z - o.z;
323 return dx*dx + dy*dy + dz*dz;
330 return (
float)Math.sqrt(
distSq(o));
339 return x*o.x + y*o.y + z*o.z;
344 return new Vec3f().cross(
this, arg);
350 x = a.y * b.z - a.z * b.y;
351 y = a.z * b.x - a.x * b.z;
352 z = a.x * b.y - a.y * b.x;
367 return (
float) Math.acos(
cosAngle(o) );
417 if( o instanceof
Vec3f ) {
426 return x +
" / " + y +
" / " + z;
Basic Float math utility functions.
static boolean isZero(final float a, final float epsilon)
Returns true if value is zero, i.e.
static boolean isEqual(final float a, final float b, final float epsilon)
Returns true if both values are equal, i.e.
2D Vector based upon two float components.
3D Vector based upon three float components.
float lengthSq()
Return the squared length of this vector, a.k.a the squared norm or squared magnitude
Vec3f mul(final float val)
Returns this * val; creates new vector.
Vec3f mul(final Vec3f s)
this = this * s, returns this.
Vec3f div(final Vec3f a, final Vec3f b)
this = a / b, returns this.
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).
static final Vec3f UNIT_Y_NEG
float cosAngle(final Vec3f o)
Return the cosine of the angle between two vectors using dot(Vec3f).
Vec3f scale(final float s)
this = this * s, returns this.
static final Vec3f UNIT_Z_NEG
boolean equals(final Object o)
Vec3f max(final Vec3f m)
this = max(this, m), returns this.
Vec3f sub(final Vec3f b)
this = this - b, returns this.
Vec3f mul(final Vec3f a, final Vec3f b)
this = a * b, returns this.
boolean isZero()
Return true if all components are zero, i.e.
Vec3f div(final Vec3f a)
this = this / a, returns this.
Vec3f normalize()
Normalize this vector in place.
Vec3f plus(final Vec3f arg)
Returns this + arg; creates new vector.
Vec3f toArray(final float[] xyz)
xyz[0..2] = this.
Vec3f mul(final float sx, final float sy, final float sz)
this = this * { sx, sy, sz }, returns this.
float dot(final Vec3f o)
Return the dot product of this vector and the given one.
Vec3f(final Vec2f o, final float z)
Creating new Vec3f using { Vec2f, z}.
boolean isEqual(final Vec3f o, final float epsilon)
Equals check using a given FloatUtil#EPSILON value and FloatUtil#isEqual(float, float,...
float distSq(final Vec3f o)
Return the squared distance between this vector and the given one.
Vec3f(final Vec4f o)
Creating new Vec3f using Vec4f, dropping w.
Vec3f(final float x, final float y, final float z)
Vec3f cross(final Vec3f a, final Vec3f b)
this = a cross b.
float dist(final Vec3f o)
Return the distance between this vector and the given one.
float length()
Return the length of this vector, a.k.a the norm or magnitude
static final Vec3f UNIT_X
boolean isEqual(final Vec3f o)
Equals check using FloatUtil#EPSILON in FloatUtil#isEqual(float, float).
Vec3f minus(final Vec3f a, final Vec3f b)
this = a - b, returns this.
Vec3f minus(final Vec3f arg)
Returns this - arg; creates new vector.
Vec3f cross(final Vec3f arg)
Returns this cross arg; creates new vector.
static final Vec3f UNIT_Z
Vec3f add(final Vec3f b)
this = this + b, returns this.
Vec3f min(final Vec3f m)
this = min(this, m), returns this.
static final Vec3f UNIT_Y
Vec3f add(final float dx, final float dy, final float dz)
this = this + { dx, dy, dz }, returns this.
Vec3f plus(final Vec3f a, final Vec3f b)
this = a + b, returns this.
4D Vector based upon four float components.