Chem::Spatial::Parallelepiped
Inherits Struct / Value / Object
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).
Constructors
Creates a Parallelepiped with the given lengths placed at the
origin.
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 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°).
Instance methods
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 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 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 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 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.