struct Chem::Spatial::Parallelepiped
- Chem::Spatial::Parallelepiped
- Struct
- Value
- Object
Overview
A parallelepiped is a three-dimensional figure formed by six parallelograms. It is defined by three vectors (basis) and it's useful for representing spatial bounds and unit cells.
It is internally represented by a 3x3 matrix, where each column
correspond to a basis vector (see Mat3.basis
), where
coordinates are expressed in Cartesian space (angstroms). In this
way, the basis matrix can be used to transform from Cartesian to
fractional coordinates, and viceversa, by matrix multiplication (see
#cart
and #fract
).
Defined in:
chem/spatial/parallelepiped.crConstructors
-
.[](a : Number, b : Number, c : Number) : self
Creates a
Parallelepiped
with the given lengths placed at the origin. -
.cubic(a : Number) : self
Creates a cubic parallelepiped (a = b = c and α = β = γ = 90°).
-
.from_io(io : IO, format : IO::ByteFormat) : self
Reads a parallelepiped from io in the given format.
-
.hexagonal(a : Number, c : Number) : self
Creates a hexagonal parallelepiped (a = b, α = β = 90°, and γ = 120°).
-
.monoclinic(a : Number, c : Number, beta : Number) : self
Creates a monoclinic parallelepiped (a ≠ c, α = γ = 90°, and β ≠ 90°).
-
.new(i : Vec3, j : Vec3, k : Vec3, origin : Vec3 = Vec3.zero) : self
Creates a
Parallelepiped
with the given basis vectors located at origin. -
.new(basis : Mat3, origin : Vec3 = Vec3.zero)
Creates a
Parallelepiped
with basis located at origin. -
.new(vmin : Vec3, vmax : Vec3) : self
Creates a
Parallelepiped
spanning from vmin to vmax. -
.new(size : NumberTriple | Size3, angles : NumberTriple = {90, 90, 90}, origin : Vec3 = Vec3.zero) : self
Creates a
Parallelepiped
with the given lengths (in angstroms) and angles (in degrees) located at origin. -
.orthorhombic(a : Number, b : Number, c : Number) : self
Creates an orthorhombic parallelepiped (a ≠ b ≠ c and α = β = γ = 90°).
-
.rhombohedral(a : Number, alpha : Number) : self
Creates an rhombohedral parallelepiped (a = b = c and α = β = γ ≠ 90°).
-
.tetragonal(a : Number, c : Number) : self
Creates an tetragonal parallelepiped (a = b ≠ c and α = β = γ = 90°).
Instance Method Summary
-
#*(value : Number) : self
Returns a parallelepiped with the basis vectors multiplied by value.
- #==(rhs : self) : Bool
-
#angles : NumberTriple
Returns the parallelepiped angles (alpha, beta, gamma) in degrees.
-
#basis : Mat3
Matrix containing the basis vectors.
-
#basisvec : Tuple(Vec3, Vec3, Vec3)
Returns the basis vectors.
-
#cart(vec : Vec3) : Vec3
Returns the vector in Cartesian coordinates equivalent to the given fractional coordinates.
-
#center : Vec3
Returns the center of the parallelepiped.
-
#center_at(vec : Vec3) : self
Centers the parallelepiped at vec.
-
#center_at_origin : self
Centers the parallelepiped at the origin.
-
#close_to?(rhs : self, delta : Number = Float64::EPSILON) : Bool
Returns
true
if the values of the parallelepipeds are within delta from each other, elsefalse
. -
#cubic? : Bool
Returns
true
if the parallelepiped is cubic (a = b = c and α = β = γ = 90°), elsefalse
. -
#each_edge(& : Vec3, Vec3 -> ) : Nil
Yields each parallelepiped' edge as a pair of vertices.
-
#each_vertex(& : Vec3 -> ) : Nil
Yields parallelepiped' vertices.
-
#edges : Array(Tuple(Vec3, Vec3))
Returns the parallelepiped' edges as pairs of vertices.
-
#fract(vec : Vec3) : Vec3
Returns the vector in fractional coordinates equivalent to the given Cartesian coordinates.
-
#hexagonal? : Bool
Returns
true
if the parallelepiped is hexagonal (a = b, α = β = 90°, and γ = 120°), elsefalse
. -
#image(vec : Vec3, ix : Tuple(Int, Int, Int)) : Vec3
Returns the vector's image with respect to the parallelepiped.
-
#includes?(other : self) : Bool
Returns
true
if the parallelepiped encloses other,false
otherwise. -
#includes?(vec : Vec3) : Bool
Returns
true
if the parallelepiped encloses vec,false
otherwise. -
#inspect(io : IO) : Nil
Appends this struct's name and instance variables names and values to the given IO.
-
#monoclinic? : Bool
Returns
true
if the parallelepiped is monoclinic (a ≠ c, α = γ = 90°, and β ≠ 90°), elsefalse
. -
#origin : Vec3
Origin of the parallelepiped.
-
#orthogonal? : Bool
Returns
true
if the parallelepiped is orthogonal (α = β = γ = 90°), elsefalse
. -
#orthorhombic? : Bool
Returns
true
if the parallelepiped is orthorhombic (a ≠ b ≠ c and α = β = γ = 90°), elsefalse
. -
#pad(px : Number, py : Number, pz : Number, centered : Bool = true) : self
Returns a new parallelepiped by expanding the extents by padding in each direction.
-
#pad(padding : Number, centered : Bool = true) : self
Returns a new parallelepiped by expanding the extents by padding in each direction.
-
#pad(padding : Size3, centered : Bool = true) : self
Returns a new parallelepiped by expanding the extents by padding in each direction.
-
#resize(si : Number | Nil, sj : Number | Nil, sk : Number | Nil) : self
Returns a parallelepiped by resizing the basis vectors to the given values.
-
#resize(size : Chem::Spatial::Size3) : self
Returns a parallelepiped by resizing the basis vectors to the given size.
-
#resize(& : Float64, Float64, Float64 -> Tuple(Float64, Float64, Float64)) : self
Yields the basis vectors' sizes to the given block, and returns a parallelepiped by resizing them to the returned values.
-
#resize_by(a : Number, b : Number, c : Number) : self
Returns a parallelepiped by padding the basis vectors by the given values.
-
#rhombohedral? : Bool
Returns
true
if the parallelepiped is rhombohedral (a = b = c and α = β = γ ≠ 90°), elsefalse
. -
#rotate(x : Number, y : Number, z : Number) : self
Returns the parallelepiped rotated by the given Euler angles in degrees.
-
#rotate(about rotaxis : Vec3, by angle : Number) : self
Returns the parallelepiped rotated about the axis vector rotaxis by angle degrees.
-
#rotate(quat : Quat) : self
Returns the parallelepiped rotated by the given quaternion.
-
#size : Size3
Returns the lengths of the basis vectors.
-
#tetragonal? : Bool
Returns
true
if the parallelepiped is tetragonal (a = b ≠ c and α = β = γ = 90°), elsefalse
. -
#to_io(io : IO, format : IO::ByteFormat = :system_endian) : Nil
Writes the binary representation of the parallelepiped to io in the given format.
-
#transform(transformation : Transform) : self
Returns the parallelepiped resulting of applying the given transformation.
-
#transform(& : Vec3, Vec3, Vec3 -> Tuple(Vec3, Vec3, Vec3)) : self
Returns a new parallelepiped with the return value of the given block, which is invoked with the basis vectors.
-
#translate(offset : Vec3) : self
Returns a new parallelepiped translated by offset.
-
#triclinic? : Bool
Returns
true
if the parallelepiped is triclinic (not orthogonal, hexagonal, monoclinic, nor rhombohedral), elsefalse
. -
#vertices : Array(Vec3)
Returns parallelepiped' vertices.
-
#vmax : Vec3
Returns the maximum vertex.
-
#vmin : Vec3
Returns the minimum vertex.
-
#volume : Float64
Returns the volume of the parallelepiped.
-
#wrap(vec : Vec3, around center : Vec3) : Vec3
Returns the vector by wrapping it into the parallelepiped centered at center.
-
#wrap(vec : Vec3) : Vec3
Returns the vector by wrapping it into the parallelepiped.
-
#xyz? : Bool
Whether the parallelepiped is aligned to the X, Y, and Z axes.
Constructor Detail
Creates a Parallelepiped
with the given lengths placed at the
origin.
Creates a cubic parallelepiped (a = b = c and α = β = γ = 90°).
Reads a parallelepiped from io in the given format. See also:
IO#read_bytes
.
Creates a hexagonal parallelepiped (a = b, α = β = 90°, and γ = 120°).
Creates a monoclinic parallelepiped (a ≠ c, α = γ = 90°, and β ≠ 90°).
Creates a Parallelepiped
with the given basis vectors located at
origin.
Creates a Parallelepiped
with basis located at origin.
Creates a Parallelepiped
spanning from vmin to vmax.
Creates a Parallelepiped
with the given lengths (in angstroms)
and angles (in degrees) located at origin. Raises
ArgumentError
if any of the lengths or angles is negative.
NOTE The first basis vector will be aligned to the X axis and the second basis vector will lie in the XY plane.
Creates an orthorhombic parallelepiped (a ≠ b ≠ c and α = β = γ = 90°).
Creates an rhombohedral parallelepiped (a = b = c and α = β = γ ≠ 90°).
Creates an tetragonal parallelepiped (a = b ≠ c and α = β = γ = 90°).
Instance Method Detail
Returns a parallelepiped with the basis vectors multiplied by value.
Returns the vector in Cartesian coordinates equivalent to the given fractional coordinates.
Returns true
if the values of the parallelepipeds are within
delta from each other, else false
.
Returns true
if the parallelepiped is cubic (a = b = c and
α = β = γ = 90°), else false
.
Yields each parallelepiped' edge as a pair of vertices.
Yields parallelepiped' vertices.
Parallelepiped[5, 10, 20].each_vertex { |vec| puts vec }
Prints:
Vec3[0.0, 0.0, 0.0]
Vec3[0.0, 0.0, 20.0]
Vec3[0.0, 10.0, 0.0]
Vec3[0.0, 10.0, 20.0]
Vec3[5.0, 0.0, 0.0]
Vec3[5.0, 0.0, 20.0]
Vec3[5.0, 10.0, 0.0]
Vec3[5.0, 10.0, 20.0]
Returns the parallelepiped' edges as pairs of vertices.
Returns the vector in fractional coordinates equivalent to the given Cartesian coordinates.
Returns true
if the parallelepiped is hexagonal (a = b, α
= β = 90°, and γ = 120°), else false
.
Returns the vector's image with respect to the parallelepiped.
pld = new Parallelepiped.new({2, 2, 3}, {90, 90, 120})
pld.i # => Vec3[2.0, 0.0, 0.0]
pld.j # => Vec3[-1, 1.732, 0.0]
pld.k # => Vec3[0.0, 0.0, 3.0]
vec = Vec3[1, 1, 1.5]
pld.image(vec, {1, 0, 0}) # => Vec3[3.0, 1.0, 1.5]
pld.image(vec, {0, 1, 0}) # => Vec3[0.0, 2.732, 1.5]
pld.image(vec, {0, 0, 1}) # => Vec3[1.0, 1.0, 4.5]
pld.image(vec, {1, 0, 1}) # => Vec3[3.0, 1.0, 4.5]
pld.image(vec, {1, 1, 1}) # => Vec3[2.0, 2.732, 4.5]
Returns true
if the parallelepiped encloses other, false
otherwise.
It effectively checks if every vertex of other is contained by the parallelepiped.
pld = Parallelepiped.new({10, 10, 10}, {90, 90, 120})
pld.includes? Parallelepiped[5, 4, 6] # => true
pld.includes? Parallelepiped.new(Vec3[-1, 2, -4], {5, 4, 6}) # => false
Returns true
if the parallelepiped encloses vec, false
otherwise.
pld = Parallelepiped.new({23.803, 23.828, 5.387}, {90, 90, 120})
pld.includes? Vec3[10, 20, 2] # => true
pld.includes? Vec3[0, 0, 0] # => true
pld.includes? Vec3[30, 30, 10] # => false
pld.includes? Vec3[-3, 10, 2] # => true
pld.includes? Vec3[-3, 2, 2] # => false
Appends this struct's name and instance variables names and values to the given IO.
struct Point
def initialize(@x : Int32, @y : Int32)
end
end
p1 = Point.new 1, 2
p1.to_s # "Point(@x=1, @y=2)"
p1.inspect # "Point(@x=1, @y=2)"
Returns true
if the parallelepiped is monoclinic (a ≠ c, α
= γ = 90°, and β ≠ 90°), else false
.
Returns true
if the parallelepiped is orthogonal (α = β =
γ = 90°), else false
.
Returns true
if the parallelepiped is orthorhombic (a ≠ b ≠
c and α = β = γ = 90°), else false
.
Returns a new parallelepiped by expanding the extents by padding
in each direction. padding can be either a single value, three
values, or a Size3
instance.
If centered is true
, the origin will be changed such that the
center does not change, else it will be kept intact.
pld = Parallelepiped.new(Vec3[1, 5, 3], {10, 5, 12})
other = pld.pad(2.5)
other.size # => Size3[15, 10, 17]
other.origin == pld.origin # => false
other.center == pld.center # => true
other = pld.pad(2.5, centered: false)
other.size # => Size3[15, 10, 17]
other.origin == pld.origin # => true
other.center == pld.center # => false
NOTE Note that its size is actually increased by padding * 2
.
Returns a new parallelepiped by expanding the extents by padding
in each direction. padding can be either a single value, three
values, or a Size3
instance.
If centered is true
, the origin will be changed such that the
center does not change, else it will be kept intact.
pld = Parallelepiped.new(Vec3[1, 5, 3], {10, 5, 12})
other = pld.pad(2.5)
other.size # => Size3[15, 10, 17]
other.origin == pld.origin # => false
other.center == pld.center # => true
other = pld.pad(2.5, centered: false)
other.size # => Size3[15, 10, 17]
other.origin == pld.origin # => true
other.center == pld.center # => false
NOTE Note that its size is actually increased by padding * 2
.
Returns a new parallelepiped by expanding the extents by padding
in each direction. padding can be either a single value, three
values, or a Size3
instance.
If centered is true
, the origin will be changed such that the
center does not change, else it will be kept intact.
pld = Parallelepiped.new(Vec3[1, 5, 3], {10, 5, 12})
other = pld.pad(2.5)
other.size # => Size3[15, 10, 17]
other.origin == pld.origin # => false
other.center == pld.center # => true
other = pld.pad(2.5, centered: false)
other.size # => Size3[15, 10, 17]
other.origin == pld.origin # => true
other.center == pld.center # => false
NOTE Note that its size is actually increased by padding * 2
.
Returns a parallelepiped by resizing the basis vectors to the given values.
pld = Parallelepiped.hexagonal(1, 2)
pld.angles # => {90, 90, 120}
pld.size # => Size3[1, 1, 2]
other = pld.resize(5, 5, 12)
other.angles # => {90, 90, 120}
other.size # => Size3[5, 5, 12]
Use nil
to keep the current size:
other = pld.resize(nil, 5, nil)
other.angles # => {90, 90, 120}
other.size # => Size3[1, 5, 12]
Returns a parallelepiped by resizing the basis vectors to the given size.
pld = Parallelepiped.hexagonal(1, 2)
pld.angles # => {90, 90, 120}
pld.size # => Size3[1, 1, 2]
other = pld.resize(Size3[5, 5, 12])
other.angles # => {90, 90, 120}
other.size # => Size3[5, 5, 12]
Yields the basis vectors' sizes to the given block, and returns a parallelepiped by resizing them to the returned values.
pld = Parallelepiped.hexagonal(1, 2)
pld.angles # => {90, 90, 120}
pld.size # => Size3[1, 1, 2]
other = pld.resize { |a, b, c| {a * 2, b / 10, c} }
other.angles # => {90, 90, 120}
other.size # => Size3[2, 0.1, 2]
Returns a parallelepiped by padding the basis vectors by the given values.
pld = Parallelepiped.hexagonal(1, 2)
pld.angles # => {90, 90, 120}
pld.size # => Size3[1, 1, 2]
other = pld.resize_by(2, 3, -0.5)
other.angles # => {90, 90, 120}
other.size # => Size3[3, 4, 1.5]
Returns true
if the parallelepiped is rhombohedral (a = b =
c and α = β = γ ≠ 90°), else false
.
Returns the parallelepiped rotated by the given Euler angles in
degrees. Delegates to Quat.rotation
for computing the rotation.
Returns the parallelepiped rotated about the axis vector rotaxis
by angle degrees. Delegates to Quat.rotation
for computing the
rotation.
Returns the parallelepiped rotated by the given quaternion.
Returns true
if the parallelepiped is tetragonal (a = b ≠
c and α = β = γ = 90°), else false
.
Writes the binary representation of the parallelepiped to io in
the given format. See also IO#write_bytes
.
Returns the parallelepiped resulting of applying the given transformation.
NOTE the rotation will be applied about the center of the parallelepiped. Translation will be applied afterwards.
Returns a new parallelepiped with the return value of the given block, which is invoked with the basis vectors.
pld = Parallelepiped.cubic(10).transform do |bi, bj, bk|
bi *= 2
bk /= 0.4
{bi, bj, bk}
end
pld.basisvec[0] # => Vec3[20, 0, 0]
pld.basisvec[1] # => Vec3[0, 10, 0]
pld.basisvec[2] # => Vec3[0, 0, 25]
Returns a new parallelepiped translated by offset.
pld = Parallelepiped.new(Vec3[-5, 1, 20], {10, 10, 10}, {90, 90, 120})
pld.translate Vec3[1, 2, 10]
pld.origin # => Vec3[-4.0, 3.0, 30.0]
Returns true
if the parallelepiped is triclinic (not orthogonal,
hexagonal, monoclinic, nor rhombohedral), else false
.
Returns parallelepiped' vertices.
pld = Parallelepiped[5, 10, 20]
pld.vertices # => [Vec3[0.0, 0.0, 0.0], Vec3[0.0, 0.0, 20.0], ...]
Returns the maximum vertex.
pld = Parallelepiped.new(Vec3[1.5, 3, -0.4], {10, 10, 12}, {90, 90, 120})
pld.vmax # => Vec3[6.5, 11.66, 11.6]
Returns the minimum vertex. This is equivalent to the parallelepiped's origin.
pld = Parallelepiped.new(Vec3[1.5, 3, -0.4], {10, 10, 12}, {90, 90, 120})
pld.vmin # => Vec3[1.5, 3, -0.4]
Returns the vector by wrapping it into the parallelepiped centered at center. The vector is assumed to be expressed in Cartesian coordinates.
Returns the vector by wrapping it into the parallelepiped. The vector is assumed to be expressed in Cartesian coordinates.