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 Vec2fadd(float dx, float dy)this = this + { dx, dy }, returns this.Vec2fadd(Vec2f b)this = this + b, returns this.floatangle()Return the direction angle of this vector in radiansfloatangle(Vec2f o)Return the angle between two vectors in radiansVec2fcopy()floatcosAngle(Vec2f o)Return the cosines of the angle between two vectorsfloatcross(Vec2f o)Returns cross product of this vectors and the given one, i.e.floatdist(Vec2f o)Return the distance between this vector and the given one.floatdistSq(Vec2f o)Return the squared distance between this vector and the given one.floatdot(Vec2f arg)Return the dot product of this vector and the given onebooleanequals(Object o)static Vec2ffrom_length_angle(float magnitude, float radians)float[]get(float[] xy)xy = this, returns xy.floatget(int i)Gets the ith component, 0 <= i < 2booleanisEqual(Vec2f o)Equals check usingFloatUtil.EPSILONvalue andFloatUtil.isEqual(float, float, float).booleanisEqual(Vec2f o, float epsilon)Equals check using a givenFloatUtil.EPSILONvalue andFloatUtil.isEqual(float, float, float).booleanisZero()Return true if all components are zero, i.e.floatlength()Return the length of this vector, a.k.a the norm or magnitudefloatlengthSq()Return the squared length of this vector, a.k.a the squared norm or squared magnitudeVec2fmax(Vec2f m)this = max(this, m), returns this.Vec2fmin(Vec2f m)this = min(this, m), returns this.Vec2fminus(Vec2f arg)Returns this - arg; creates new vectorVec2fminus(Vec2f a, Vec2f b)this = a - b, returns this.Vec2fmul(float val)Returns this * val; creates new vectorVec2fmul(Vec2f a, Vec2f b)this = a * b, returns this.Vec2fnormal_ccw()Return the counter-clock-wise (CCW) normal of this vector, i.e.Vec2fnormalize()Normalize this vector in placeVec2fplus(Vec2f arg)Returns this + arg; creates new vectorVec2fplus(Vec2f a, Vec2f b)this = a + b, returns this.voidrotate(float sin, float cos, Vec2f ctr)voidrotate(float radians, Vec2f ctr)Vec2fscale(float s)this = this * s, returns this.Vec2fscale(float sx, float sy)this = this * { sx, sy }, returns this.Vec2fset(float[] xy)this = xy, returns this.voidset(float x, float y)this = { x, y }, returns this.voidset(int i, float val)Sets the ith component, 0 <= i < 2voidset(Vec2f o)this = o, returns this.voidset(Vec3f o)this = o while dropping z, returns this.voidsetX(float x)voidsetY(float y)Vec2fsub(Vec2f b)this = this - b, returns this.StringtoString()floatx()floaty()
-
-
-
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.EPSILONvalue 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.EPSILONvalue 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.
-
-