The v3d library#

<v3d> class#

The class <v3d> has three dimensions x, y and z of type <float>.

Creation with make#

To create a vector use keywords:

let v = make(<v3d>, x: 1.0, y: 2.0, z: 3.0);

In case that a keyword is not used, the dimension is initialized to 0.0.

Creation with v3d#

Short form to create a v3d.

v3d Function#
signature:

v3d x y z => (v)

parameter x:

Dimension x. An instance of <float>

parameter y:

Dimension y. An instance of <float>

parameter z:

Dimension z. An instance of <float>

value v:

An instance of v3d

description:

The code is shorter but less flexible, all parameters must be passed and the order is important.

example:

let v = v3d(1.0, 2.0, 3.0)

Dimension accessors (x, y and z)#

Dimensions x, y and z can be accessed by v-x, v-y and v-z respectively.

v-x(<v3d>) Method#

Returns the x dimension of a v3d.

signature:

v-x v => (x)

parameter v:

An instance of <v3d>

value x:

An instance of <float>

example:
let u = make(<v3d>, x: 1.0, y: 2.0, z: 3.0);
format-out("x = %=\n", u.v-x);
// prints 'x = 1.0'
v-y(<v3d>) Method#

Returns the y dimension of a v3d.

signature:

v-y v => (y)

parameter v:

An instance of <v3d>

value y:

An instance of <float>

example:
let u = make(<v3d>, x: 1.0, y: 2.0, z: 3.0);
format-out("y = %=\n", u.v-y);
// prints 'y = 2.0'
v-z(<v3d>) Method#

Returns the z dimension of a v3d.

signature:

v-z v => (z)

parameter v:

An instance of <v3d>

value z:

An instance of <float>

example:
let u = make(<v3d>, x: 1.0, y: 2.0, z: 3.0);
format-out("z = %=\n", u.v-z);
// prints 'z = 3.0'

Vector zero ($v3-zero)#

$v3-zero is a constant for a vector with 0.0 in coordinates x, y and z.

Infix operations#

Equals (=)#

=(<v3d>, <v3d>) Method#

Check if two vectors are equal.

signature:

= a b => (equal?)

parameter a:

An instance of <v3d>.

parameter b:

An instance of <v3d>.

value equal?:

An instance of <boolean>.

example:

let v1 = v3d(1.0, 1.0, 1.0);
let v2 = v3d(2.0, 2.0, 2.0);
let result = if (v1 = v2) "equals" else "different" end;

Addition (+)#

+(<v3d>, <v3d>) Method#

Adds two vectors.

signature:

+ a b => (sum)

parameter a:

An instance of <v3d>.

parameter b:

An instance of <v3d>.

value sum:

An instance of <v3d>.

example:

let v1 = v3d(1.0, 1.0, 1.0);
let v2 = v3d(2.0, 2.0, 2.0);
let v3 = v1 + v2;

Substraction (-)#

-(<v3d>, <v3d>) Method#

Substract two vectors.

signature:

- a b => (difference)

parameter a:

An instance of <v3d>.

parameter b:

An instance of <v3d>.

value difference:

An instance of <v3d>.

example:

let v1 = v3d(2.0, 2.0, 2.0);
let v2 = v3d(1.0, 1.0, 1.0);
let v3 = v1 - v2;

Negative (-)#

-(<v3d>) Method#

Substract two vectors.

signature:

- a => (negated)

parameter a:

An instance of <v3d>.

value negated:

An instance of <v3d>.

example:

let v1 = v3d(2.0, 2.0, 2.0);
let v2 = -v1;

Product (*)#

*(<v3d>, <v3d>) Method#

Product of two vectors.

signature:
  • a b => (product)

parameter a:

An instance of <v3d>.

parameter b:

An instance of <v3d>.

value product:

An instance of <float>.

example:

let v1 = v3d(2.0, 2.0, 2.0);
let v2 = v3d(1.0, 1.0, 1.0);
let v3 = v1 * v2;

Scalar multiplication (*)#

*(<v3d>, <number>) Method#

Product scalar of a vector by a number.

Let v = (x1, y1, z1) and let k be scalar. The scalar multiplication of kv = (kx1, ky1, kz1).

signature:
  • a n => (product)

parameter a:

An instance of <v3d>.

parameter n:

An instance of <number>.

value product:

An instance of <v3d>.

example:

let v1 = v3d(1.0, 1.0, 1.0);
let v2 = v1 * 2;

Division (/)#

/(<v3d>, <number>) Method#

Divide a vector by a number.

signature:
  • a n => (division)

parameter a:

An instance of <v3d>.

parameter n:

An instance of <number>.

value division:

An instance of <float>.

example:

let v1 = v3d(3.0, 3.0, 3.0);
let v2 = v1 / 3;