struct

Chem::Spatial::Vec3

Inherits Struct / Value / Object

Constructors

[](x : Number, y : Number, z : Number) : self

Returns a new vector representing the position (x, y, z).

Source
additive_identity

Returns the additive identity of this type. This is the zero vector.

Source
from_io(io : IO, format : IO::ByteFormat) : self

Reads a vector from io in the given format. See also: IO#read_bytes.

Source
new(x : Float64, y : Float64, z : Float64)

Creates a new vector representing the position (x, y, z).

Source
rand(random = Random::DEFAULT) : self

Returns a random vector with the elements within 0 and 1.

Source
zero

Returns the zero vector.

Source

Instance methods

*(rhs : Number) : self

Returns the element-wise multiplication of the vector by rhs.

Source
*(rhs : Vec3) : self

Returns the element-wise multiplication of the vector by rhs.

Source
*(rhs : Quat) : self

Returns the conjugate of the vector by the inverse of rhs. See Quat#* for details.

Source
+(rhs : Number) : self

Returns the element-wise addition of the vector by rhs.

Source
+(rhs : Vec3) : self

Returns the element-wise addition of the vector by rhs.

Source
+(rhs : Size3) : self

Returns the element-wise addition of the vector by rhs.

Source
-(rhs : Number) : self

Returns the element-wise subtraction of the vector by rhs.

Source
-(rhs : Vec3) : self

Returns the element-wise subtraction of the vector by rhs.

Source
-(rhs : Size3) : self

Returns the element-wise subtraction of the vector by rhs.

Source
-

Returns the negation of the vector.

Source
/(rhs : Number) : self

Returns the element-wise division of the vector by rhs.

Source
/(rhs : Vec3) : self

Returns the element-wise division of the vector by rhs.

Source
[](index : Int32) : Float64

Returns the ith component of the vector in the XYZ order. Raises IndexError if index is invalid.

Source
abs

Returns the absolute value (norm or length) of the vector.

Source
abs2

Returns the square of the absolute value of the vector.

Source
close_to?(rhs : self, delta : Number = Float64::EPSILON) : Bool

Returns true if the elements of the vectors are within delta from each other, else false.

Vec3[1, 2, 3].close_to?(Vec3[1, 2, 3])                     # => true
Vec3[1, 2, 3].close_to?(Vec3[1.001, 1.999, 3.00004], 1e-3) # => true
Vec3[1, 2, 3].close_to?(Vec3[3, 2, 1])                     # => false
Vec3[1, 2, 3].close_to?(Vec3[1.001, 1.999, 3.00004], 1e-8) # => false
Source
cross(rhs : Vec3) : self

Returns the cross product of the vector and rhs.

Source
dot(rhs : Vec3) : Float64

Returns the dot product of the vector and rhs.

Source
image(i : Int, j : Int, k : Int) : self

Returns vector's PBC image in fractional coordinates

vec = Vec3[0.456, 0.1, 0.8]
vec.image 1, 0, 0   # => Vec3[1.456, 0.1, 0.8]
vec.image -1, 0, 0  # => Vec3[-0.544, 0.1, 0.8]
vec.image -1, 1, -5 # => Vec3[-0.544, 1.1, -4.2]
Source
inv

Returns the inverse of the vector. It is equivalent to the unary negation operator.

Source
map

Returns a vector with the results of the component-wise mapping by the given block. This is useful to perform non-standard transformations.

Vec3[1, 2, 3].map(&.**(2)) # => Vec3[1.0, 4.0, 9.0]
Source
map_with_index

Returns a vector with the results of the component-wise mapping by the given block yielding both the value and index. This is useful to perform non-standard transformations.

Vec3[1, 2, 3].map { |ele, i| ele * i } # => Vec3[0.0, 2.0, 6.0]
Source
normalize

Returns the unit vector pointing in the same direction of the vector.

v = Vec3[2.5, 0, 0].normalize # => Vec[1.0, 0.0, 0.0]
v.abs                         # => 1.0
v = Vec3[1, 1, 1].normalize   # => Vec[0.577, 0.577, 0.577]
v.abs                         # => 1.0
Source
pad(padding : Number) : self

Returns a vector by increasing the length by padding.

Vec3[1, 0, 0].pad(2) # => Vec3[3, 0, 0]
a = Vec3[1, 2, 3]
a.abs                             # => 3.7416573867739413
b = a.pad(2)                      # => Vec3[1.535, 3.069, 4.604]
b.abs                             # => 5.741657386773941
a.normalize.close_to? b.normalize # => true
Source
project(vec : self) : self

Returns the projection of the vector on vec.

Source
reject(vec : self) : self

Returns the rejection of the vector on vec.

Source
resize(length : Number) : self

Returns a vector pointing in the same direction with the given length.

a = Vec3[1, 2, 3]
a.abs                              # => 3.7416573867739413
b = a.resize 0.5                   # => Vec3[0.134, 0.267, 0.401]
b.abs                              # => 0.5
b.normalize.close_to?(a.normalize) # => true
Source
rotate(x : Number, y : Number, z : Number) : self

Returns the vector rotated by the given Euler angles in degrees. Delegates to Quat.rotation for computing the rotation.

Source
rotate(about rotaxis : Vec3, by angle : Number) : self

Returns the vector rotated about rotaxis by angle degrees. Delegates to Quat.rotation for computing the rotation.

Source
rotate(quat : Quat) : self

Returns the vector rotated by the given quaternion.

Source
to_a

Returns an array with the components of the vector.

Vec3[1, 2, 3].to_a # => [1.0, 2.0, 3.0]
Source
to_io(io : IO, format : IO::ByteFormat = :system_endian) : Nil

Writes the binary representation of the vector to io in the given format. See also IO#write_bytes.

Source
to_q

Returns the quaternion representation of the vector, i.e., Quat[0, x, y, z].

Source
to_s(io : IO) : Nil

Same as #inspect(io).

Source
transform(transformation : Transform) : self

Returns the vector resulting of applying the given transformation.

Source
transform

Returns a new vector with the return value of the given block, which is invoked with the X, Y, and Z components.

Vec3[3, 2, 1].transform do |x, y, z|
  x *= 2
  z /= 0.5
  {x, y, z}
end # => Vec3[6, 2, 2]
Source
translate(by offset : Vec3) : self

Returns the vector translated by the given offset.

Source
unsafe_fetch(index : Int) : Float64
Source
wrap(around center : self) : self

Returns the vector by wrapping into the primary unit cell centered at center. The vector is assumed to be expressed in fractional coordinates.

Source
wrap

Returns the vector by wrapping into the primary unit cell. The vector is assumed to be expressed in fractional coordinates.

Source
x

X component of the vector.

Source
x?

Returns true if the vector lies along X axis, else false.

Source
xy?

Returns true if the vector lies in the XY-plane, else false.

Source
xz?

Returns true if the vector lies in the XZ-plane, else false.

Source
y

Y component of the vector.

Source
y?

Returns true if the vector lies along Y axis, else false.

Source
yz?

Returns true if the vector lies in the YZ-plane, else false.

Source
z

Z component of the vector.

Source
z?

Returns true if the vector lies along Z axis, else false.

Source
zero?

Returns true if the vector is zero, else false.

Source