package scad_ml

  1. Overview
  2. Docs

Module Scad_ml.Vec3Source

3-dimensional vector type.

In addition to basic math and vector operations, relevant transformation functions (and aliases) are mirroring those found in Scad are provided. This allows for points in space represented by this type to moved around in a similar fashion to Scad.t.

include module type of struct include Vec3 end
Sourcetype t = float * float * float
Sourceval zero : t

Zero vector = (0., 0., 0.)

Sourceval equal : t -> t -> bool

Basic Arithmetic

Sourceval horizontal_op : (float -> float -> float) -> t -> t -> t

horizontal_op f a b

Hadamard (element-wise) operation between vectors a and b using the function f.

Sourceval add : t -> t -> t

add a b

Hadamard (element-wise) addition of vectors a and b.

Sourceval sub : t -> t -> t

sub a b

Hadamard (element-wise) subtraction of vector b from a.

Sourceval mul : t -> t -> t

mul a b

Hadamard (element-wise) product of vectors a and b.

Sourceval div : t -> t -> t

div a b

Hadamard (element-wise) division of vector a by b.

Sourceval negate : t -> t

negate t

Negation of all elements of t.

Sourceval add_scalar : t -> float -> t

add_scalar t s

Element-wise addition of s to t.

Sourceval sub_scalar : t -> float -> t

sub_scalar t s

Element-wise subtraction of s from t.

Sourceval mul_scalar : t -> float -> t

mul_scalar t s

Element-wise multiplication of t by s.

Sourceval div_scalar : t -> float -> t

div_scalar t s

Element-wise division of t by s.

Vector Math

Sourceval norm : t -> float

norm t

Calculate the vector norm (a.k.a. magnitude) of t.

Sourceval distance : t -> t -> float

distance a b

Calculate the magnitude of the difference (Hadamard subtraction) between a and b.

Sourceval normalize : t -> t

normalize t

Normalize t to a vector for which the magnitude is equal to 1. e.g. norm (normalize t) = 1.

Sourceval dot : t -> t -> float

dot a b

Vector dot product of a and b.

Sourceval cross : t -> t -> t

cross a b

Vector cross product of a and b.

Sourceval mean : t list -> t

mean l

Calculate the mean / average of all vectors in l.

Transformations

Equivalent to those found in Scad. Quaternion operations are provided when this module is included in Scad_ml.

Sourceval rotate_x : float -> t -> t

rotate_x theta t

Rotate t by theta radians about the x-axis.

Sourceval rotate_y : float -> t -> t

rotate_y theta t

Rotate t by theta radians about the y-ayis.

Sourceval rotate_z : float -> t -> t

rotate_z theta t

Rotate t by theta radians about the z-azis.

Sourceval rotate : t -> t -> t

rotate r t

Euler (xyz) rotation of t by the angles in theta. Equivalent to rotate_x rx t |> rotate_y ry |> rotate_z rz, where (rx, ry, rz) = r.

Sourceval rotate_about_pt : t -> t -> t -> t

rotate_about_pt r pivot t

Translates t along the vector pivot, euler rotating the resulting vector with r, and finally, moving back along the vector pivot. Functionally, rotating about the point in space arrived at by the initial translation along the vector pivot.

Sourceval translate : t -> t -> t

translate p t

Translate t along the vector p. Equivalent to add.

Sourceval scale : t -> t -> t

scale s t

Scale t by factors s. Equivalent to mul.

Sourceval mirror : t -> t -> t

mirror ax t

Mirrors t on a plane through the origin, defined by the normal vector ax.

Sourceval projection : t -> t

projection t

Project t onto the XY plane.

Utilities

Sourceval map : (float -> 'b) -> t -> 'b * 'b * 'b
Sourceval get_x : t -> float
Sourceval get_y : t -> float
Sourceval get_z : t -> float
Sourceval to_string : t -> string
Sourceval deg_of_rad : t -> t

deg_of_rad t

Element-wise conversion of t from radians to degrees.

Sourceval rad_of_deg : t -> t

rad_to_deg t

Element-wise conversion of t from degrees to radians.

2d - 3d conversion

Sourceval to_vec2 : t -> float * float
Sourceval of_vec2 : (float * float) -> t

Infix operations

Sourceval (<+>) : t -> t -> t

a <+> b

Hadamard (element-wise) addition of a and b.

Sourceval (<->) : t -> t -> t

a <-> b

Hadamard (element-wise) subtraction of b from a.

Sourceval (<*>) : t -> t -> t

a <*> b

Hadamard (element-wise) product of a and b.

Sourceval (</>) : t -> t -> t

a </> b

Hadamard (element-wise) division of a by b.

Sourceval quaternion : Quaternion.t -> Vec3.t -> Vec3.t

quaternion q t

Rotate t with the quaternion q.

Sourceval quaternion_about_pt : Quaternion.t -> Vec3.t -> Vec3.t -> Vec3.t

quaternion_about_pt q p t

Translates t along the vector p, rotating the resulting vector with the quaternion q, and finally, moving back along the vector p. Functionally, rotating about the point in space arrived at by the initial translation along the vector p.

OCaml

Innovation. Community. Security.