29package com.jogamp.math;
60 return new Vec3d(
this);
63 public Vec3d(
final double[] xyz) {
67 public Vec3d(
final double x,
final double y,
final double z) {
96 public Vec3d set(
final double x,
final double y,
final double z) {
104 public Vec3d set(
final double[] xyz) {
120 public void set(
final int i,
final double val) {
122 case 0: x = val;
break;
123 case 1: y = val;
break;
124 case 2: z = val;
break;
125 default:
throw new IndexOutOfBoundsException();
130 public double[]
get(
final double[] xyz) {
138 public double get(
final int i) {
143 default:
throw new IndexOutOfBoundsException();
147 public double x() {
return x; }
148 public double y() {
return y; }
149 public double z() {
return z; }
151 public void setX(
final double x) { this.x = x; }
152 public void setY(
final double y) { this.y = y; }
153 public void setZ(
final double z) { this.z = z; }
157 this.x = Math.
max(this.x, m.x);
158 this.y = Math.
max(this.y, m.y);
159 this.z = Math.
max(this.z, m.z);
164 this.x = Math.
min(this.x, m.x);
165 this.y = Math.
min(this.y, m.y);
166 this.z = Math.
min(this.z, m.z);
172 return new Vec3d(
this).scale(val);
187 public Vec3d mul(
final double sx,
final double sy,
final double sz) {
220 return new Vec3d(
this).add(arg);
232 public Vec3d add(
final double dx,
final double dy,
final double dz) {
249 return new Vec3d(
this).sub(arg);
284 return x*x + y*y + z*z;
297 final double invSqr = 1.0f / Math.sqrt(
lengthSq);
313 final double dx = x - o.x;
314 final double dy = y - o.y;
315 final double dz = z - o.z;
316 return dx*dx + dy*dy + dz*dz;
323 return Math.sqrt(
distSq(o));
332 return x*o.x + y*o.y + z*o.z;
337 return new Vec3d().cross(
this, arg);
343 x = a.y * b.z - a.z * b.y;
344 y = a.z * b.x - a.x * b.z;
345 z = a.x * b.y - a.y * b.x;
410 if( o instanceof
Vec3d ) {
419 return x +
" / " + y +
" / " + z;
Basic Double math utility functions.
static boolean isZero(final double a, final double epsilon)
Returns true if value is zero, i.e.
static boolean isEqual(final double a, final double b, final double epsilon)
Returns true if both values are equal, i.e.
2D Vector based upon two float components.
3D Vector based upon three double components.
Vec3d plus(final Vec3d a, final Vec3d b)
this = a + b, returns this.
void setX(final double x)
Vec3d mul(final Vec3d a, final Vec3d b)
this = a * b, returns this.
Vec3d(final double[] xyz)
double lengthSq()
Return the squared length of this vector, a.k.a the squared norm or squared magnitude
Vec3d(final Vec2f o, final double z)
Creating new Vec3f using { Vec2f, z}.
Vec3d add(final double dx, final double dy, final double dz)
this = this + { dx, dy, dz }, returns this.
double dot(final Vec3d o)
Return the dot product of this vector and the given one.
Vec3d mul(final Vec3d s)
this = this * s, returns this.
Vec3d(final Vec4f o)
Creating new Vec3f using Vec4f, dropping w.
Vec3d minus(final Vec3d arg)
Returns this - arg; creates new vector.
Vec3d min(final Vec3d m)
this = min(this, m), returns this.
double cosAngle(final Vec3d o)
Return the cosine of the angle between two vectors using dot(Vec3d).
Vec3d max(final Vec3d m)
this = max(this, m), returns this.
Vec3d div(final Vec3d a)
this = this / a, returns this.
Vec3d add(final Vec3d b)
this = this + b, returns this.
Vec3d mul(final double sx, final double sy, final double sz)
this = this * { sx, sy, sz }, returns this.
Vec3d mul(final double val)
Returns this * val; creates new vector.
Vec3d normalize()
Normalize this vector in place.
Vec3d div(final Vec3d a, final Vec3d b)
this = a / b, returns this.
Vec3d plus(final Vec3d arg)
Returns this + arg; creates new vector.
boolean isEqual(final Vec3d o)
Equals check using DoubleUtil#EPSILON in DoubleUtil#isEqual(double, double).
double distSq(final Vec3d o)
Return the squared distance between this vector and the given one.
Vec3d minus(final Vec3d a, final Vec3d b)
this = a - b, returns this.
double length()
Return the length of this vector, a.k.a the norm or magnitude
Vec3d cross(final Vec3d arg)
Returns this cross arg; creates new vector.
boolean equals(final Object o)
Vec3d scale(final double s)
this = this * s, returns this.
double dist(final Vec3d o)
Return the distance between this vector and the given one.
Vec3d toArray(final double[] xyz)
xyz[0..2] = this.
void setZ(final double z)
boolean isZero()
Return true if all components are zero, i.e.
double angle(final Vec3d o)
Return the angle between two vectors in radians using Math#acos(double) on cosAngle(Vec3d).
boolean isEqual(final Vec3d o, final double epsilon)
Equals check using a given DoubleUtil#EPSILON value and DoubleUtil#isEqual(double,...
Vec3d sub(final Vec3d b)
this = this - b, returns this.
void setY(final double y)
Vec3d cross(final Vec3d a, final Vec3d b)
this = a cross b.
Vec3d(final double x, final double y, final double z)
4D Vector based upon four float components.