29package com.jogamp.math;
42 return new Vec2f((
float)(magnitude * Math.cos(radians)), (
float)(magnitude * Math.sin(radians)));
61 return new Vec2f(
this);
64 public Vec2f(
final float[] xy) {
68 public Vec2f(
final float x,
final float y) {
73 public void set(
final Vec2f o) {
79 public void set(
final Vec2i o) {
85 public void set(
final Vec3f o) {
91 public void set(
final float x,
final float y) {
97 public Vec2f set(
final float[] xy) {
111 public void set(
final int i,
final float val) {
113 case 0: x = val;
break;
114 case 1: y = val;
break;
115 default:
throw new IndexOutOfBoundsException();
120 public float[]
get(
final float[] xy) {
127 public float get(
final int i) {
131 default:
throw new IndexOutOfBoundsException();
135 public float x() {
return x; }
136 public float y() {
return y; }
138 public void setX(
final float x) { this.x = x; }
139 public void setY(
final float y) { this.y = y; }
143 this.x = Math.
max(this.x, m.x);
144 this.y = Math.
max(this.y, m.y);
149 this.x = Math.
min(this.x, m.x);
150 this.y = Math.
min(this.y, m.y);
156 return new Vec2f(
this).scale(val);
199 return new Vec2f(
this).add(arg);
225 return new Vec2f(
this).sub(arg);
248 final float cos = (float)Math.cos(radians);
249 final float sin = (float)Math.sin(radians);
253 public void rotate(
final float sin,
final float cos,
final Vec2f ctr) {
254 final float x0 = x - ctr.x;
255 final float y0 = y - ctr.y;
256 final float tmp = x0 * cos - y0 * sin + ctr.x;
257 y = x0 * sin + y0 * cos + ctr.y;
265 return (
float) Math.sqrt(
lengthSq());
280 return (
float) Math.atan2(y, x);
292 final float invSqr = 1.0f / (float)Math.sqrt(
lengthSq);
307 final float dx = x - o.x;
308 final float dy = y - o.y;
309 return dx*dx + dy*dy;
316 return (
float)Math.sqrt(
distSq(o));
325 return x * arg.x + y * arg.y;
336 return x * o.y - y * o.x;
350 return (
float) Math.acos(
cosAngle(o) );
357 return new Vec2f(-y, x);
405 if( o instanceof
Vec2f ) {
414 return x +
" / " + y;
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.
boolean isZero()
Return true if all components are zero, i.e.
Vec2f toArray(final float[] xy)
xy[0..1] = this.
Vec2f plus(final Vec2f a, final Vec2f b)
this = a + b, returns this.
float cross(final Vec2f o)
Returns cross product of this vectors and the given one, i.e.
Vec2f max(final Vec2f m)
this = max(this, m), returns this.
float dist(final Vec2f o)
Return the distance between this vector and the given one.
void rotate(final float radians, final Vec2f ctr)
float angle()
Return the direction angle of this vector in radians.
Vec2f plus(final Vec2f arg)
Returns this + arg; creates new vector.
boolean isEqual(final Vec2f o, final float epsilon)
Equals check using a given FloatUtil#EPSILON value and FloatUtil#isEqual(float, float,...
Vec2f(final Vec3f o)
Creating new Vec2f using Vec3f, dropping z.
Vec2f mul(final float sx, final float sy)
this = this * { sx, sy }, returns this.
Vec2f sub(final Vec2f b)
this = this - b, returns this.
Vec2f normal_ccw()
Return the counter-clock-wise (CCW) normal of this vector, i.e.
float distSq(final Vec2f o)
Return the squared distance between this vector and the given one.
boolean isEqual(final Vec2f o)
Equals check using FloatUtil#EPSILON in FloatUtil#isEqual(float, float).
Vec2f(final float x, final float y)
Vec2f minus(final Vec2f arg)
Returns this - arg; creates new vector.
float length()
Return the length of this vector, a.k.a the norm or magnitude
Vec2f div(final Vec2f a, final Vec2f b)
this = a / b, returns this.
float dot(final Vec2f arg)
Return the dot product of this vector and the given one.
Vec2f mul(final Vec2f a, final Vec2f b)
this = a * b, returns this.
Vec2f mul(final Vec2f s)
this = this * s, returns this.
Vec2f normalize()
Normalize this vector in place.
Vec2f add(final Vec2f b)
this = this + b, returns this.
static Vec2f from_length_angle(final float magnitude, final float radians)
Vec2f scale(final float s)
this = this * s, returns this.
float lengthSq()
Return the squared length of this vector, a.k.a the squared norm or squared magnitude
float cosAngle(final Vec2f o)
Return the cosines of the angle between two vectors.
Vec2f add(final float dx, final float dy)
this = this + { dx, dy }, returns this.
Vec2f minus(final Vec2f a, final Vec2f b)
this = a - b, returns this.
Vec2f mul(final float val)
Returns this * val; creates new vector.
Vec2f div(final Vec2f a)
this = this / a, returns this.
void rotate(final float sin, final float cos, final Vec2f ctr)
Vec2f min(final Vec2f m)
this = min(this, m), returns this.
boolean equals(final Object o)
float angle(final Vec2f o)
Return the angle between two vectors in radians.
2D Vector based upon two integer components.
3D Vector based upon three float components.