Class: Numerix::Vector3

Inherits:
VectorBase show all
Defined in:
lib/numerix/vector3.rb

Overview

A structure encapsulating three single precision floating point values.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Structure

#[], #[]=, #address, #dup, #each, #pack, #ptr, size, unpack

Constructor Details

#initializeVector3 #initialize(xyz) ⇒ Vector3 #initialize(x, y, z) ⇒ Vector3 #initialize(xy, z) ⇒ Vector3

Returns a new instance of Vector3.

Overloads:

  • #initializeVector3

    Creates a Vector with the default values of 0.0.

  • #initialize(xyz) ⇒ Vector3

    Creates a Vector with each component set to a single value.

    Parameters:

    • xyz (Float)

      The value to set for all components.

  • #initialize(x, y, z) ⇒ Vector3

    Creates a Vector with the specified values.

    Parameters:

    • x (Float)

      The X component of the vector.

    • y (Float)

      The Y component of the vector.

    • z (Float)

      The Z component of the vector.

  • #initialize(xy, z) ⇒ Vector3

    Creates a Vector with the specified values.

    Parameters:

    • xy (Vector3)

      Vector2 to use for the X and Y components.

    • z (Float)

      The Z component of the vector.



41
42
# File 'lib/numerix/vector3.rb', line 41

def initialize(*args)
end

Instance Attribute Details

#xFloat

Returns the X component of the vector.

Returns:

  • (Float)

    the X component of the vector.



9
10
11
# File 'lib/numerix/vector3.rb', line 9

def x
  @x
end

#yFloat

Returns the Y component of the vector.

Returns:

  • (Float)

    the Y component of the vector.



13
14
15
# File 'lib/numerix/vector3.rb', line 13

def y
  @y
end

#zFloat

Returns the Z component of the vector.

Returns:

  • (Float)

    the Z component of the vector.



17
18
19
# File 'lib/numerix/vector3.rb', line 17

def z
  @z
end

Class Method Details

.clamp(min, max) ⇒ Vector3 .clamp(min, max) ⇒ Vector3

Returns a vector that is result of clamping a vector between the specified minimum and maximum values.

Overloads:

  • .clamp(min, max) ⇒ Vector3

    Clamps the vector's components between the specified values.

    Parameters:

    • min (Float)

      The minimum value.

    • max (Float)

      The maximum value.

  • .clamp(min, max) ⇒ Vector3

    Clamps the vector's on a component-wise basis between the minimum and maximum values of the specified vectors.

    Parameters:

    • min (Vector3)

      The minimum value.

    • max (Vector3)

      The maximum value.

Returns:

  • (Vector3)

    the result of clamping this vector.



514
515
# File 'lib/numerix/vector3.rb', line 514

def clamp(vector, min, max)
end

.create_norm(x, y, z) ⇒ Vector3

Creates and returns a normalized vector from the specified components.

This is more efficient than creating and then normalizing.

Parameters:

  • x (Float)

    The X component of the vector.

  • y (Float)

    The Y component of the vector.

  • z (Float)

    The Z component of the vector.

Returns:

  • (Vector3)

    the newly created normalized vector.



493
494
# File 'lib/numerix/vector3.rb', line 493

def create_norm(x, y, z)
end

.lerp(vector1, vector2, amount) ⇒ Vector3

Linearly interpolates between two vectors based on the given weighting.

Parameters:

  • vector1 (Vector3)

    The first source vector.

  • vector2 (Vector3)

    The second source vector.

  • amount (Float)

    Value between 0.0 and 1.0 indicating the weight of the second source vector.

Returns:

  • (Vector3)

    the interpolated vector.



526
527
# File 'lib/numerix/vector3.rb', line 526

def lerp(vector1, vector2, amount)
end

.max(vector, other) ⇒ Vector3 .max(vector, value) ⇒ Vector3

Returns a vector with a maximum set of values.

Overloads:

  • .max(vector, other) ⇒ Vector3

    Returns a vector whose elements are the maximum of each of the pairs of elements in the two source vectors.

    Parameters:

    • vector (Vector3)

      The first source vector.

    • other (Vector3)

      The second source vector.

  • .max(vector, value) ⇒ Vector3

    Returns a vector whose elements are the maximum of each of vector element and the specified value.

    Parameters:

    • vector (Vector3)

      The source vector.

    • value (Float)

      The maximum value.

Returns:

  • (Vector3)

    the maximized vector.



568
569
# File 'lib/numerix/vector3.rb', line 568

def max(vector, other)
end

.min(vector, other) ⇒ Vector3 .min(vector, value) ⇒ Vector3

Returns a vector with a minimum set of values.

Overloads:

  • .min(vector, other) ⇒ Vector3

    Returns a vector whose elements are the minimum of each of the pairs of elements in the two source vectors.

    Parameters:

    • vector (Vector3)

      The first source vector.

    • other (Vector3)

      The second source vector.

  • .min(vector, value) ⇒ Vector3

    Returns a vector whose elements are the minimum of each of vector element and the specified value.

    Parameters:

    • vector (Vector3)

      The source vector.

    • value (Float)

      The minimum value.

Returns:

  • (Vector3)

    the minimized vector.



547
548
# File 'lib/numerix/vector3.rb', line 547

def min(vector, other)
end

.oneVector3

Returns the vector <1.0, 1.0, 1.0>.

Returns:

  • (Vector3)

    the vector <1.0, 1.0, 1.0>.



465
466
# File 'lib/numerix/vector3.rb', line 465

def one
end

.unit_xVector3

Returns the vector <1.0, 0.0, 0.0>.

Returns:

  • (Vector3)

    the vector <1.0, 0.0, 0.0>.



470
471
# File 'lib/numerix/vector3.rb', line 470

def unit_x
end

.unit_yVector3

Returns the vector <0.0, 1.0, 0.0>.

Returns:

  • (Vector3)

    the vector <0.0, 1.0, 0.0>.



475
476
# File 'lib/numerix/vector3.rb', line 475

def unit_y
end

.unit_zVector3

Returns the vector <0.0, 0.0, 1.0>.

Returns:

  • (Vector3)

    the vector <0.0, 0.0, 1.0>.



480
481
# File 'lib/numerix/vector3.rb', line 480

def unit_z
end

.zeroVector3

Returns the vector <0.0, 0.0, 0.0>.

Returns:

  • (Vector3)

    the vector <0.0, 0.0, 0.0>.



460
461
# File 'lib/numerix/vector3.rb', line 460

def zero
end

Instance Method Details

#*(scalar) ⇒ Vector3 #*(other) ⇒ Vector3

Vector multiplication.

Overloads:

  • #*(scalar) ⇒ Vector3

    Scalar vector multiplication.

    Parameters:

    • scalar (Float)

      The scalar value.

  • #*(other) ⇒ Vector3

    Multiplies this vector by another.

    Parameters:

    • other (Vector3)

      The source vector to multiply.

Returns:

  • (Vector3)

    the product vector.



318
319
# File 'lib/numerix/vector3.rb', line 318

def *(other)
end

#**(exponent) ⇒ Vector3

Raises the vector to the given power.

Parameters:

  • exponent (Float)

    The power to raise the vector to.

Returns:

  • (Vector3)

    New vector that is result of the operation.



97
98
# File 'lib/numerix/vector3.rb', line 97

def **(exponent)
end

#+(other) ⇒ Vector3

Adds this vector with another.

Parameters:

  • other (Vector3)

    The vector to add.

Returns:

  • (Vector3)

    the sum of the vectors.



292
293
# File 'lib/numerix/vector3.rb', line 292

def +(other)
end

#-(other) ⇒ Vector3

Gets the difference of this vector and another.

Parameters:

  • other (Vector3)

    The vector to subtract.

Returns:

  • (Vector3)

    the difference of the vectors.



301
302
# File 'lib/numerix/vector3.rb', line 301

def -(other)
end

#-@Vector3

Performs unary negation on this vector instance.

Returns:

  • (Vector3)

    the vector with swapped +/- values.



351
352
# File 'lib/numerix/vector3.rb', line 351

def -@
end

#*(scalar) ⇒ Vector3 #*(other) ⇒ Vector3

Vector division.

Overloads:

  • #*(scalar) ⇒ Vector3

    Scalar vector division.

    Parameters:

    • scalar (Float)

      The scalar value.

  • #*(other) ⇒ Vector3

    Divides this vector by another.

    Parameters:

    • other (Vector3)

      The source vector to divide.

Returns:

  • (Vector3)

    the resulting vector.



335
336
# File 'lib/numerix/vector3.rb', line 335

def /(other)
end

#==(other) ⇒ Boolean

Returns flag if this vector instance is equal to the given object.

Parameters:

  • other (Object)

    The object to compare.

Returns:

  • (Boolean)

    true if objects are equal, otherwise false.



344
345
# File 'lib/numerix/vector3.rb', line 344

def ==(other)
end

#absVector3

Returns a vector whose elements are the absolute values of each of this vector's elements.

Returns:

  • (Vector3)

    a vector whose elements are the absolute values of each of this vector's elements.



186
187
# File 'lib/numerix/vector3.rb', line 186

def abs
end

#angle(other) ⇒ Float

Computes the angle between this vector and another.

Parameters:

  • other (Vector3)

    The vector to calculate angle from.

Returns:

  • (Float)

    the angle, in degrees, between the two vectors.



453
454
# File 'lib/numerix/vector3.rb', line 453

def angle(other)
end

#clamp(min, max) ⇒ Vector3 #clamp(min, max) ⇒ Vector3

Returns a vector that is result of clamping this vector between the specified minimum and maximum values.

Overloads:

  • #clamp(min, max) ⇒ Vector3

    Clamps the vector's components between the specified values.

    Parameters:

    • min (Float)

      The minimum value.

    • max (Float)

      The maximum value.

  • #clamp(min, max) ⇒ Vector3

    Clamps the vector's on a component-wise basis between the minimum and maximum values of the specified vectors.

    Parameters:

    • min (Vector3)

      The minimum value.

    • max (Vector3)

      The maximum value.

Returns:

  • (Vector3)

    the result of clamping this vector.

See Also:



224
225
# File 'lib/numerix/vector3.rb', line 224

def clamp(min, max)
end

#clamp!(min, max) ⇒ Vector3 #clamp!(min, max) ⇒ Vector3

Clamps this vector between the specified minimum and maximum values.

Overloads:

  • #clamp!(min, max) ⇒ Vector3

    Clamps the vector's components between the specified values.

    Parameters:

    • min (Float)

      The minimum value.

    • max (Float)

      The maximum value.

  • #clamp!(min, max) ⇒ Vector3

    Clamps the vector's on a component-wise basis between the minimum and maximum values of the specified vectors.

    Parameters:

    • min (Vector3)

      The minimum value.

    • max (Vector3)

      The maximum value.

Returns:

See Also:



246
247
# File 'lib/numerix/vector3.rb', line 246

def clamp!(min, max)
end

#cross(other) ⇒ Vector3

Computes the cross product of two vectors.

Parameters:

  • other (Vector3)

    The source vector.

Returns:



416
417
# File 'lib/numerix/vector3.rb', line 416

def cross(other)
end

#cross!(other) ⇒ self

Computes the cross product of two vectors, altering the values of this vector.

Parameters:

  • other (Vector3)

    The source vector.

Returns:

  • (self)


425
426
# File 'lib/numerix/vector3.rb', line 425

def cross!(other)
end

#distance(vector) ⇒ Float

Returns the Euclidean distance between this vector and another.

Parameters:

  • vector (Vector3)

    The point to get distance between.

Returns:

  • (Float)

    the distance.



128
129
# File 'lib/numerix/vector3.rb', line 128

def distance(vector)
end

#distance_squared(vector) ⇒ Float

Returns the squared Euclidean distance between this vector and another.

Parameters:

  • vector (Vector3)

    The point to get distance between.

Returns:

  • (Float)

    the distance squared.



136
137
# File 'lib/numerix/vector3.rb', line 136

def distance_squared(vector)
end

#dot(other) ⇒ Float

Returns the dot product of this vector and another.

Parameters:

  • other (Vector3)

    the source vector to compute dot product of.

Returns:

  • (Float)

    the dot product.



201
202
# File 'lib/numerix/vector3.rb', line 201

def dot(other)
end

#lengthFloat Also known as: magnitude

Returns the length of the vector.

Returns:

  • (Float)

    the length of the vector.



46
47
# File 'lib/numerix/vector3.rb', line 46

def length
end

#length_squaredFloat

Returns the length of the vector squared.

Returns:

  • (Float)

    the length of the vector squared.



53
54
# File 'lib/numerix/vector3.rb', line 53

def length_squared
end

#lerp(vector, amount) ⇒ Vector3

Linearly interpolates between this vector and another based on the given weighting.

Parameters:

  • vector (Vector3)

    The source vector to interpolate between.

  • amount (Float)

    Value between 0.0 and 1.0 indicating the weight of the given vector.

Returns:

  • (Vector3)

    the interpolated vector.

See Also:



166
167
# File 'lib/numerix/vector3.rb', line 166

def lerp(vector, amount)
end

#lerp!(vector, amount) ⇒ self

Linearly interpolates between this vector and another based on the given weighting, altering the values of this vector.

Parameters:

  • vector (Vector3)

    The source vector to interpolate between.

  • amount (Float)

    Value between 0.0 and 1.0 indicating the weight of the given vector.

Returns:

  • (self)

See Also:



180
181
# File 'lib/numerix/vector3.rb', line 180

def lerp!(vector, amount)
end

#mapObject Also known as: collect

See Also:



70
71
# File 'lib/numerix/vector3.rb', line 70

def map
end

#map! {|component| ... } ⇒ self Also known as: collect!

Invokes the given block once for each element of self, replacing the element with the value returned by the block.

The values of the vector are altered without creating a ne object.

Yields:

  • (component)

    Yields a component of the vector to the block.

Yield Parameters:

  • component (Float)

    The yielded component.

Returns:

  • (self)

See Also:



85
86
# File 'lib/numerix/vector3.rb', line 85

def map!
end

#max_valueFloat

Returns the greatest value of the vector's components.

Returns:

  • (Float)

    the greatest value of the vector's components.



119
120
# File 'lib/numerix/vector3.rb', line 119

def max_value
end

#min_valueFloat

Returns the lowest value of the vector's components.

Returns:

  • (Float)

    the lowest value of the vector's components.



114
115
# File 'lib/numerix/vector3.rb', line 114

def min_value
end

#normalizeVector3

Returns a new vector with the same direction as the given vector, but with a length of 1.0.

Returns:

  • (Vector3)

    a normalized vector.



144
145
# File 'lib/numerix/vector3.rb', line 144

def normalize
end

#normalize!self

Alters this vector instance to maintain same direction, but adjust values so that vector has a length of 1.0.

Returns:

  • (self)


152
153
# File 'lib/numerix/vector3.rb', line 152

def normalize!
end

#one?Boolean

Returns flag indicating if all values of the vector are equal to 1.0.

Returns:

  • (Boolean)

    flag indicating if all values of the vector are equal to 1.0.



103
104
# File 'lib/numerix/vector3.rb', line 103

def one?
end

#reflect(other) ⇒ Vector3

Alters this vector to be the reflection of the specified normal.

Parameters:

  • other (Vector3)

    The normal of the surface being reflected off.

Returns:

  • (Vector3)

    a newly created reflected vector.



434
435
# File 'lib/numerix/vector3.rb', line 434

def reflect(other)
end

#reflect!(other) ⇒ self

Returns the reflection of a vector off a surface that has the specified normal.

Parameters:

  • other (Vector3)

    The normal of the surface being reflected off.

Returns:

  • (self)


444
445
# File 'lib/numerix/vector3.rb', line 444

def reflect!(other)
end

#sqrtVector3

Returns a vector whose elements are the square root of each of this vector's elements.

Returns:

  • (Vector3)

    a vector whose elements are the square root of each of this vector's elements.



192
193
# File 'lib/numerix/vector3.rb', line 192

def sqrt
end

#to_aArray<Float> Also known as: elements

Returns an Array representation of this instance.

Returns:

  • (Array<Float>)

    an Array representation of this instance.



256
257
# File 'lib/numerix/vector3.rb', line 256

def to_a
end

#to_hHash{Symbol => Float}

Returns a Hash representation of this instance.

Returns:

  • (Hash{Symbol => Float})

    a Hash representation of this instance.



263
264
# File 'lib/numerix/vector3.rb', line 263

def to_h
end

#to_planePlane

Returns a Plane representation of this instance.

Returns:

  • (Plane)

    a Plane representation of this instance.



273
274
# File 'lib/numerix/vector3.rb', line 273

def to_plane
end

#to_quaternionQuaternion

Returns a Quaternion representation of this instance.

Returns:



268
269
# File 'lib/numerix/vector3.rb', line 268

def to_quaternion
end

#to_sString

Returns a String representation of this instance.

Returns:

  • (String)

    a String representation of this instance.



251
252
# File 'lib/numerix/vector3.rb', line 251

def to_s
end

#to_vec2Vector2

Returns a Numerix::Vector2 representation of this instance.

Returns:



278
279
# File 'lib/numerix/vector3.rb', line 278

def to_vec2
end

#to_vec4Vector4

Returns a Numerix::Vector4 representation of this instance.

Returns:



283
284
# File 'lib/numerix/vector3.rb', line 283

def to_vec4
end

#transform(matrix) ⇒ Vector3 #transform(rotation) ⇒ Vector3

Returns a new vector by applying a transformation.

Overloads:

  • #transform(matrix) ⇒ Vector3

    Transforms this vector by the given matrix.

    Parameters:

    • matrix (Matrix4x4)

      The transformation matrix.

  • #transform(rotation) ⇒ Vector3

    Transforms this vector by the specified rotation value.

    Parameters:

    • rotation (Quaternion)

      The rotation to apply.

Returns:

  • (Vector3)

    new transformed vector.

See Also:



370
371
# File 'lib/numerix/vector3.rb', line 370

def transform(other)
end

#transform(matrix) ⇒ self #transform(rotation) ⇒ self

Transforms this vector by the given matrix.

Overloads:

  • #transform(matrix) ⇒ self

    Transforms this vector by the given matrix.

    Parameters:

    • matrix (Matrix4x4)

      The transformation matrix.

  • #transform(rotation) ⇒ self

    Transforms this vector by the specified rotation value.

    Parameters:

    • rotation (Quaternion)

      The rotation to apply.

Returns:

  • (self)

See Also:



389
390
# File 'lib/numerix/vector3.rb', line 389

def transform!(other)
end

#transform_normal(matrix) ⇒ Vector3

Transforms a vector normal by the given matrix.

Parameters:

  • matrix (Matrix4x4)

    The transformation matrix.

Returns:

  • (Vector3)

    new transformed vector.



398
399
# File 'lib/numerix/vector3.rb', line 398

def transform_normal(matrix)
end

#transform_normal!(matrix) ⇒ self

Transforms a vector normal by the given matrix.

Parameters:

  • matrix (Matrix4x4)

    The transformation matrix.

Returns:

  • (self)


407
408
# File 'lib/numerix/vector3.rb', line 407

def transform_normal!(matrix)
end

#zero?Boolean

Returns flag indicating if all values of the vector are equal to 0.0.

Returns:

  • (Boolean)

    flag indicating if all values of the vector are equal to 0.0.



109
110
# File 'lib/numerix/vector3.rb', line 109

def zero?
end