Class Vec3f

  • public final class Vec3f
    extends Object
    3D Vector based upon three float components. Implementation borrowed from [gfxbox2]( and its data layout from JOAL's Vec3f.
    • Field Detail

      • ONE

        public static final Vec3f ONE
      • UNIT_Y

        public static final Vec3f UNIT_Y
      • UNIT_Y_NEG

        public static final Vec3f UNIT_Y_NEG
      • UNIT_Z

        public static final Vec3f UNIT_Z
      • UNIT_Z_NEG

        public static final Vec3f UNIT_Z_NEG
    • Constructor Detail

      • Vec3f

        public Vec3f()
      • Vec3f

        public Vec3f​(Vec3f o)
      • Vec3f

        public Vec3f​(Vec4f o)
        Creating new Vec3f using Vec4f, dropping w.
      • Vec3f

        public Vec3f​(Vec2f o,
                     float z)
        Creating new Vec3f using { Vec2f, z}.
      • Vec3f

        public Vec3f​(float[] xyz)
      • Vec3f

        public Vec3f​(float x,
                     float y,
                     float z)
    • Method Detail

      • copy

        public Vec3f copy()
      • set

        public Vec3f set​(Vec3f o)
        this = o, returns this.
      • set

        public Vec3f set​(Vec2f o,
                         float z)
        this = { o, z }, returns this.
      • set

        public Vec3f set​(Vec4f o)
        this = o while dropping w, returns this.
      • set

        public Vec3f set​(float x,
                         float y,
                         float z)
        this = { x, y, z }, returns this.
      • set

        public Vec3f set​(float[] xyz)
        this = xyz, returns this.
      • set

        public void set​(int i,
                        float val)
        Sets the ith component, 0 <= i < 3
      • get

        public float[] get​(float[] xyz)
        xyz = this, returns xyz.
      • get

        public float get​(int i)
        Gets the ith component, 0 <= i < 3
      • x

        public float x()
      • y

        public float y()
      • z

        public float z()
      • setX

        public void setX​(float x)
      • setY

        public void setY​(float y)
      • setZ

        public void setZ​(float z)
      • max

        public Vec3f max​(Vec3f m)
        this = max(this, m), returns this.
      • min

        public Vec3f min​(Vec3f m)
        this = min(this, m), returns this.
      • mul

        public Vec3f mul​(float val)
        Returns this * val; creates new vector
      • mul

        public Vec3f mul​(Vec3f a,
                         Vec3f b)
        this = a * b, returns this.
      • scale

        public Vec3f scale​(float s)
        this = this * s, returns this.
      • scale

        public Vec3f scale​(float sx,
                           float sy,
                           float sz)
        this = this * { sx, sy, sz }, returns this.
      • plus

        public Vec3f plus​(Vec3f arg)
        Returns this + arg; creates new vector
      • plus

        public Vec3f plus​(Vec3f a,
                          Vec3f b)
        this = a + b, returns this.
      • add

        public Vec3f add​(float dx,
                         float dy,
                         float dz)
        this = this + { dx, dy, dz }, returns this.
      • add

        public Vec3f add​(Vec3f b)
        this = this + b, returns this.
      • minus

        public Vec3f minus​(Vec3f arg)
        Returns this - arg; creates new vector
      • minus

        public Vec3f minus​(Vec3f a,
                           Vec3f b)
        this = a - b, returns this.
      • sub

        public Vec3f sub​(Vec3f b)
        this = this - b, returns this.
      • isZero

        public boolean isZero()
        Return true if all components are zero, i.e. it's absolute value < #EPSILON.
      • 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
      • normalize

        public Vec3f normalize()
        Normalize this vector in place
      • distSq

        public float distSq​(Vec3f 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​(Vec3f o)
        Return the distance between this vector and the given one.
      • dot

        public float dot​(Vec3f o)
        Return the dot product of this vector and the given one
        the dot product as float
      • cross

        public Vec3f cross​(Vec3f arg)
        Returns this cross arg; creates new vector
      • cross

        public Vec3f cross​(Vec3f a,
                           Vec3f b)
        this = a cross b. NOTE: "this" must be a different vector than both a and b.
      • cosAngle

        public float cosAngle​(Vec3f o)
        Return the cosines of the angle between two vectors
      • angle

        public float angle​(Vec3f o)
        Return the angle between two vectors in radians
      • isEqual

        public boolean isEqual​(Vec3f o,
                               float epsilon)
        Equals check using a given FloatUtil.EPSILON value and FloatUtil.isEqual(float, float, float).

        Implementation considers following corner cases:

        • NaN == NaN
        • +Inf == +Inf
        • -Inf == -Inf
        o - comparison value
        epsilon - consider using FloatUtil.EPSILON
        true if all components differ less than epsilon, otherwise false.