Next: Rectangles, Up: Math [Contents][Index]
(use-modules (sly math vector))
Not to be confused with Guile’s vector data structure, Sly provides
dedicated data types for 2D, 3D, and 4D vectors in the mathematical
sense. Vector procedures are polymorphic, and will work with any
dimensionality that the operation supports. In some cases, such as
v+
, v-
, and v*
, scalar values may be passed as
well.
The <vector2>
, <vector3>
, and <vector4>
type
descriptors have been exposed for use with Guile’s (ice-9
match)
pattern matching module.
2D vector data type with fields x
and y
, in that order.
3D vector data type with fields x
, y
, and z
, in
that order.
4D vector data type with fields x
, y
, z
and
w
, in that order.
Create a new 2D vector with coordinates (x, y).
Create a new 3D vector with coordinates (x, y, z).
Create a new 4D vector with coordinates (x, y, z, w).
Return #t
if v
is a 2D vector.
Return #t
if v
is a 3D vector.
Return #t
if v
is a 4D vector.
Return the x coordinate of the 2D, 3D, or 4D vector v.
Return the y coordinate of the 2D, 3D, or 4D vector v.
Return the z coordinate of the 3D or 4D vector v.
Return the w coordinate of the 4D vector v.
Return a new vector that is the result of applying proc to each element of the 2D, 3D, or 4D vector v.
Return the sum of all vectors. vectors may contain scalar values, but it may not contain vectors of mixed dimensions.
Return the difference of all vectors. vectors may contain scalar values, but it may not contain vectors of mixed dimensions.
Return the product of all vectors. vectors may contain scalar values, but it may not contain vectors of mixed dimensions.
Return the dot product of v1 and v2. Both vectors must be of the same dimensionality.
Return the cross product of the 3D vectors v1 and v2.
Return the magnitude of the vector v.
Return the normalized form of the vector v.
Return the linear interpolation of v1 and v2 by the scalar alpha. alpha is expected to be in the range [0, 1].
Next: Rectangles, Up: Math [Contents][Index]