Package com.jogamp.opengl.math
Class Vec2f
- java.lang.Object
-
- com.jogamp.opengl.math.Vec2f
-
public final class Vec2f extends Object
2D Vector based upon two float components. Implementation borrowed from [gfxbox2](https://jausoft.com/cgit/cs_class/gfxbox2.git/tree/include/pixel/pixel2f.hpp#n29) and its data layout from JOAL's Vec3f.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Vec2f
add(float dx, float dy)
this = this + { dx, dy }, returns this.Vec2f
add(Vec2f b)
this = this + b, returns this.float
angle()
Return the direction angle of this vector in radiansfloat
angle(Vec2f o)
Return the angle between two vectors in radiansVec2f
copy()
float
cosAngle(Vec2f o)
Return the cosines of the angle between two vectorsfloat
cross(Vec2f o)
Returns cross product of this vectors and the given one, i.e.float
dist(Vec2f o)
Return the distance between this vector and the given one.float
distSq(Vec2f o)
Return the squared distance between this vector and the given one.float
dot(Vec2f arg)
Return the dot product of this vector and the given oneboolean
equals(Object o)
static Vec2f
from_length_angle(float magnitude, float radians)
float[]
get(float[] xy)
xy = this, returns xy.float
get(int i)
Gets the ith component, 0 <= i < 2boolean
isEqual(Vec2f o)
Equals check usingFloatUtil.EPSILON
value andFloatUtil.isEqual(float, float, float)
.boolean
isEqual(Vec2f o, float epsilon)
Equals check using a givenFloatUtil.EPSILON
value andFloatUtil.isEqual(float, float, float)
.boolean
isZero()
Return true if all components are zero, i.e.float
length()
Return the length of this vector, a.k.a the norm or magnitudefloat
lengthSq()
Return the squared length of this vector, a.k.a the squared norm or squared magnitudeVec2f
max(Vec2f m)
this = max(this, m), returns this.Vec2f
min(Vec2f m)
this = min(this, m), returns this.Vec2f
minus(Vec2f arg)
Returns this - arg; creates new vectorVec2f
minus(Vec2f a, Vec2f b)
this = a - b, returns this.Vec2f
mul(float val)
Returns this * val; creates new vectorVec2f
mul(Vec2f a, Vec2f b)
this = a * b, returns this.Vec2f
normal_ccw()
Return the counter-clock-wise (CCW) normal of this vector, i.e.Vec2f
normalize()
Normalize this vector in placeVec2f
plus(Vec2f arg)
Returns this + arg; creates new vectorVec2f
plus(Vec2f a, Vec2f b)
this = a + b, returns this.void
rotate(float sin, float cos, Vec2f ctr)
void
rotate(float radians, Vec2f ctr)
Vec2f
scale(float s)
this = this * s, returns this.Vec2f
scale(float sx, float sy)
this = this * { sx, sy }, returns this.Vec2f
set(float[] xy)
this = xy, returns this.void
set(float x, float y)
this = { x, y }, returns this.void
set(int i, float val)
Sets the ith component, 0 <= i < 2void
set(Vec2f o)
this = o, returns this.void
set(Vec3f o)
this = o while dropping z, returns this.void
setX(float x)
void
setY(float y)
Vec2f
sub(Vec2f b)
this = this - b, returns this.String
toString()
float
x()
float
y()
-
-
-
Method Detail
-
from_length_angle
public static Vec2f from_length_angle(float magnitude, float radians)
-
copy
public Vec2f copy()
-
set
public void set(Vec2f o)
this = o, returns this.
-
set
public void set(Vec3f o)
this = o while dropping z, returns this.
-
set
public void set(float x, float y)
this = { x, y }, returns this.
-
set
public Vec2f set(float[] xy)
this = xy, returns this.
-
set
public void set(int i, float val)
Sets the ith component, 0 <= i < 2
-
get
public float[] get(float[] xy)
xy = this, returns xy.
-
get
public float get(int i)
Gets the ith component, 0 <= i < 2
-
x
public float x()
-
y
public float y()
-
setX
public void setX(float x)
-
setY
public void setY(float y)
-
mul
public Vec2f mul(float val)
Returns this * val; creates new vector
-
scale
public Vec2f scale(float s)
this = this * s, returns this.
-
scale
public Vec2f scale(float sx, float sy)
this = this * { sx, sy }, returns this.
-
add
public Vec2f add(float dx, float dy)
this = this + { dx, dy }, returns this.
-
isZero
public boolean isZero()
Return true if all components are zero, i.e. it's absolute value <#EPSILON
.
-
rotate
public void rotate(float radians, Vec2f ctr)
-
rotate
public void rotate(float sin, float cos, Vec2f ctr)
-
length
public float length()
Return the length of this vector, a.k.a the norm or magnitude
-
lengthSq
public float lengthSq()
Return the squared length of this vector, a.k.a the squared norm or squared magnitude
-
angle
public float angle()
Return the direction angle of this vector in radians
-
normalize
public Vec2f normalize()
Normalize this vector in place
-
distSq
public float distSq(Vec2f o)
Return the squared distance between this vector and the given one.When comparing the relative distance between two points it is usually sufficient to compare the squared distances, thus avoiding an expensive square root operation.
-
dist
public float dist(Vec2f o)
Return the distance between this vector and the given one.
-
dot
public float dot(Vec2f arg)
Return the dot product of this vector and the given one- Returns:
- the dot product as float
-
cross
public float cross(Vec2f o)
Returns cross product of this vectors and the given one, i.e. *this x o. The 2D cross product is identical with the 2D perp dot product.- Returns:
- the resulting scalar
-
cosAngle
public float cosAngle(Vec2f o)
Return the cosines of the angle between two vectors
-
angle
public float angle(Vec2f o)
Return the angle between two vectors in radians
-
normal_ccw
public Vec2f normal_ccw()
Return the counter-clock-wise (CCW) normal of this vector, i.e. perp(endicular) vector
-
isEqual
public boolean isEqual(Vec2f o, float epsilon)
Equals check using a givenFloatUtil.EPSILON
value andFloatUtil.isEqual(float, float, float)
.Implementation considers following corner cases:
- NaN == NaN
- +Inf == +Inf
- -Inf == -Inf
- Parameters:
o
- comparison valueepsilon
- consider usingFloatUtil.EPSILON
- Returns:
- true if all components differ less than
epsilon
, otherwise false.
-
isEqual
public boolean isEqual(Vec2f o)
Equals check usingFloatUtil.EPSILON
value andFloatUtil.isEqual(float, float, float)
.Implementation considers following corner cases:
- NaN == NaN
- +Inf == +Inf
- -Inf == -Inf
- Parameters:
o
- comparison value- Returns:
- true if all components differ less than
FloatUtil.EPSILON
, otherwise false.
-
-