Class: Float4

Float4

Float4 is a class describing 4-dimensional homogeneous points. These can represent points (w == 1), vectors (w == 0), points in homogeneous projective space, or planes (a, b, c = x, y, z), (w = d).


new Float4(x, y, z, w)

Parameters:
Name Type Description
x

The x-coordinate

y

The y-coordinate

z

The z-coordinate

w

The w-coordinate

Author:
  • derschmale <http://www.derschmale.com>

Members


length

The length of the vector.


lengthSqr

The squared length of the vector.


planeFromPoints

Generates a plane representation from 3 contained points.


<static> ORIGIN_POINT

A preset for the origin point (w = 1)


<static> X_AXIS

A preset for the X-axis


<static> Y_AXIS

A preset for the Y-axis


<static> Z_AXIS

A preset for the Z-axis


<static> ZERO

A preset for the zero vector (w = 0)

Methods


abs()

Sets the components of this vector to their absolute values.


add()

Adds a vector to this one in place.


addScaled(v, s)

Adds a scalar multiple of another vector in place.

Parameters:
Name Type Description
v

The vector to scale and add.

s

The scale to apply to v


angle()

Returns the angle between this and another vector.


angleNormalized()

Returns the angle between two vectors, assuming they are normalized


clone()

Returns a copy of this object.


copyFrom()

Copies the values from a different Float4


cross()

Store the cross product of two vectors.


distanceTo()

Returns the distance to a point.


dot()

Returns the 3-component dot product of 2 vectors.


dot3()

Returns the 3-component dot product of 2 vectors.


dot4()

Returns the 4-component dot product of 2 vectors. This can be useful for signed distances to a plane.


fromSphericalCoordinates(radius, azimuthalAngle, polarAngle)

Sets the euclidian coordinates based on spherical coordinates.

Parameters:
Name Type Description
radius

The radius coordinate

azimuthalAngle

The azimuthal coordinate

polarAngle

The polar coordinate


homogeneousProject()

Project a point in homogeneous projective space to carthesian 3D space by dividing by w


lerp(a, b, t)

Linearly interpolates two vectors.

Parameters:
Name Type Description
a Float4

The first vector to interpolate from.

b Float4

The second vector to interpolate to.

t Number

The interpolation factor.

Returns:

The interpolated value.

Type
Float4

maximize()

Replaces the components' values if those of the other Float2 are higher, respectively


maximize3()

Replaces the components' values if those of the other Float2 are higher, respectively. Excludes the w-component.


minimize()

Replaces the components' values if those of the other Float2 are lower, respectively


minimize3()

Replaces the components' values if those of the other Float2 are lower, respectively. Excludes the w-component.


negate()

Negates the components of this vector.


negativeOf()

Copies the negative of a vector


normalize()

Normalizes the vector.


normalizeAsPlane()

Normalizes the vector as if it were a plane.


planeFromNormalAndPoint(normal, point)

Generates a plane representation from the normal vector and a point contained in the plane.

Parameters:
Name Type Description
normal

The vector normal to the plane.

point

A point contained in the plane.


planeFromVectorsAndPoint(vector1, vector2, point)

Generates a plane representation from two contained vectors and a point contained in the plane.

Parameters:
Name Type Description
vector1

A vector contained in the plane.

vector2

A vector contained in the plane.

point

A point contained in the plane.


planeIntersectRay()

Calculates the intersection with a ray (if any)


scale()

Multiplies the components of this vector with a scalar, except the w-component.


scale4()

Multiplies the components of this vector with a scalar, including the w-component.


set()

Sets the components explicitly.


squareDistanceTo()

Returns the squared distance to a point.


subtract()

Subtracts a vector from this one in place.


<static> add(a, b [, target])

Adds 2 vectors.

Parameters:
Name Type Argument Description
a
b
target <optional>

An optional target object. If omitted, a new object will be created.

Returns:

The sum of a and b.


<static> cross(a, b [, target])

Returns the 3-component dot product of 2 vectors.

Parameters:
Name Type Argument Description
a
b
target <optional>

An optional target object. If omitted, a new object will be created.

Returns:

The product of a x b


<static> scale(a, s [, target])

Multiplies a vector with a scalar. The w-coordinate is not scaled, since that's generally not what is desired.

Parameters:
Name Type Argument Description
a
s
target <optional>

An optional target object. If omitted, a new object will be created.

Returns:

The product of a * s


<static> scale4(a, s [, target])

Multiplies a vector with a scalar, including the w-coordinate.

Parameters:
Name Type Argument Description
a
s
target <optional>

An optional target object. If omitted, a new object will be created.

Returns:

The product of a * s


<static> subtract(a, b [, target])

Subtracts 2 vectors.

Parameters:
Name Type Argument Description
a
b
target <optional>

An optional target object. If omitted, a new object will be created.

Returns:

The difference of a and b.