CalcBot

Searchβ¦

Vector3

Function reference for c-vector3 calculate

Heads up!

This is the documentation for the

`c-vector3`

command. If you mean to read the information on `c-vector2`

, go here.The term **vector** in this document will describe a **3D vector**.

3D vectors

A 3D vector is a representation of a point in three-dimensional space. You can express vectors in CalcBot with 3 or 6 components, which collectively express the magnitude and direction of the vector.

General

c-v3 c <expression>

Shorthand syntax for

`c-vector3 calculate`

.1

> c-v3 c i + j + k

2

(1, 1, 1)

Copied!

c-v3 m [r | d]

Shorthand syntax for switching trigonometric modes.

`c-vector2`

and `c-vector3`

both share the same trigonometric mode.1

> c-v3 m r

2

Set vector mode to radians

3

β

4

> c-v3 m d

5

Set vector mode to degrees

Copied!

Operators

All operators from

`c-calculate`

and `c-vector2 calculate`

are available for use in `c-vector3 calculate`

:not n

Negates **truthy** value, false (0) is returned. Otherwise, true (1) is returned.

`n`

. If `n`

is a 1

> c-v3 c not true

2

0

3

β

4

> c-v3 c not false is true

5

1

Copied!

n!

Take the factorial of

`n`

. If `n`

is a vector, this operation will throw an error.1

> c-v3 c 6!

2

720

3

β

4

> c-v3 c (1, 2, 1)!

5

Cannot take factorials of vectors.

Copied!

a ^ b

Raise **not** return a complex number in any situation, unlike in

`a`

to the power of `b`

. If `b`

is a vector, this operation will immediately throw an error. If `a`

is a vector, but `b`

is not an integer, this operation will also immediately throw an error. This operation will `c-calculate`

.1

> c-v3 c 2 ^ 3

2

8

3

β

4

> c-v3 c (3i + j + k) ^ 3

5

(33, 11, 11)

6

β

7

> c-v3 c -4 ^ (1/2)

8

NaN

9

β

10

> c-v3 c (3i + j + k) ^ (1/2)

11

Vectors cannot be raised to decimal powers.

12

β

13

> c-v3 c 2 ^ (2k)

14

Vectors cannot be on the right side of the '^' operator.

Copied!

a * b

Multiply

`a`

and `b`

. When operating on two vectors, this operator returns the dot product of the two vectors. To compute the cross productof two vectors, see cross(v1, v2).1

> c-v3 c 2 * 4

2

8

3

β

4

> c-v3 c (1, 2, 2) * (5, 4, 1, 2, 1, 3)

5

-5

Copied!

a / b

Divide

`a`

by `b`

. If `b`

is a vector, this operation will immediately throw an error.1

> c-v3 c 15 / 5

2

3

3

β

4

> c-v3 c (1, 2, 2) / 2

5

(0.5, 1, 1)

6

β

7

> c-v3 c (1, 2, 2) / (5, 4, 1, 2, 1, 3)

8

Vectors cannot be on the right side of the '/' operator.

Copied!

a % b

Divide

`a`

by `b`

and return the remainder of the result. This is also known as modulus division, or remainder division. If either `a`

or `b`

is a vector, this operation will immediately throw an error.1

> c-v3 c 8 % 2

2

0

3

β

4

> c-v3 c (1, 2, 2) % 2

5

Vectors cannot be used with the '%' operator.

Copied!

a + b

Add

`a`

and `b`

.1

> c-v3 c 1 + 1

2

2

3

β

4

> c-v3 c (3, 4, 2) + 2

5

(3, 4, 2) + 2

6

β

7

> c-v3 c (3, 4, 2) + (1, 2, 3)

8

(4, 6, 5)

Copied!

a - b

Subtract

`b`

from `a`

.1

> c-v3 c 1 - 1

2

0

3

β

4

> c-v3 c (3, 4, 2) - 2

5

(3, 4, 2) - 2

6

β

7

> c-v3 c (3, 4, 2) - (1, 2, 3)

8

(2, 2, -1)

Copied!

a is b

Returns true (1) if

`a`

is equal to `b`

.1

> c-v3 c 3 is 1 + 2

2

1

3

β

4

> c-v3 c (1, 1, 0) is (2 - 1, 1, 0)

5

1

Copied!

a nis b

Returns true (1) if **not** equal to

`a`

is `b`

.1

> c-v3 c 3 nis 1 + 2

2

0

3

β

4

> c-v3 c (3, 1, 4) nis (2, 1, 0)

5

1

Copied!

a ais b

Returns true (1) if **approximately** equal to

`a`

is `b`

. The difference between them must be less than `1 * 10 ^ -6`

. For vectors, this operator will compare the x and y components separately.This operator is intended to be used when comparing the results of certain mathematical operations that produce slightly imprecise results (like prime notation).

1

> c-v3 c 3.0000002 ais 3

2

1

3

β

4

> c-v3 c (3, 2, 0.9999999) ais (2.9999999, 2, 1)

5

1

Copied!

a anis b

Negates the behavior of the

`ais`

operator.1

> c-v2 c 3 anis 3

2

0

3

β

4

> c-v2 c (5, 2, 0) anis (1, 0, 2)

5

1

Copied!

a > b

Returns true (1) if

`a`

is greater than `b`

.1

> c-v3 c 3 > 2

2

1

Copied!

a < b

Returns true (1) if

`a`

is less than `b`

.1

> c-v3 c 3 < 2

2

0

Copied!

a >= b

Returns true (1) if

`a`

is greater than or equal to `b`

.1

> c-v3 c 3 >= 2

2

1

3

β

4

> c-v3 c 4 >= 4

5

1

Copied!

a <= b

Returns true (1) if

`a`

is less than or equal to `b`

.1

> c-v3 c 3 <= 2

2

0

3

β

4

> c-v3 c 4 <= 4

5

1

Copied!

a and b

Returns true if **both** **truthy** values.

`a`

and `b`

are 1

> c-v3 c 3 and 4

2

1

3

β

4

> c-v3 c 3 and 0

5

0

Copied!

a or b

Returns true if **either** **truthy** values.

`a`

or `b`

are 1

> c-v3 c 3 or 4

2

1

3

β

4

> c-v3 c 3 or 0

5

1

6

β

7

> c-v3 c 0 or 0

8

0

Copied!

Vector literals

(a, b, c)

Syntax for a three-dimensional three-component vector.

1

> c-v3 c (1, 2, 5)

2

(1, 2, 5)

Copied!

(a, b, c, d, e, f)

Syntax for a three-dimensional six-component vector. Vectors of this kind are implicitly converted to their component form when used with other operations during evaluation.

1

> c-v3 c (1, 2, 5, 3, 2, 2)

2

(1, 2, 5, 3, 2, 2)

Copied!

Vector constants

These constants will always be available everywhere in all of

`c-vector3`

's children commands.`i`

`j`

`k`

`zero`

All

`c-vector2`

functions as described here are available to use in `c-vector2 calculate`

, and most of them have been adapted for use with `c-vector3 calculate`

. There are some differences, however:Removed functions

These functions that are available in **not available** in

`c-vector2 calculate`

are `c-vector3 calculate`

(and have been replaced with similar functions):Unique functions

These functions are unique to

`c-vector3 calculate`

:z(v)

Returns the

`z`

component of vector `v`

.1

> c-v3 c z(2i + j + k)

2

1

Copied!

oct(v)

Returns the octant that vector

`v`

's component's head lies in. If the head is on the x-axis, 9 is returned. If the head is on the y-axis, 10 is returned. If the head is on the z-axis, 11 is returned.1

> c-v3 c oct(2i + j + k)

2

1

3

β

4

> c-v3 c oct(k)

5

11

Copied!

dirx(v)

Returns the direction angle vector

`v`

makes with the x-axis.1

> c-v3 c dirx(k)

2

90

Copied!

diry(v)

Returns the direction angle vector

`v`

makes with the y-axis.1

> c-v3 c diry(i + j + k)

2

54.73561031724535

Copied!

dirz(v)

Returns the direction angle vector

`v`

makes with the z-axis.1

> c-v3 c dirz(i - j)

2

90

Copied!

cross(v1, v2)

Returns the cross product of vectors

`v1`

and `v2`

.1

> c-v3 c cross((3, 1, 4), (-2, 0, 5))

2

(5, -23, 2)

Copied!

Last modified 4d ago

Copy link

Contents

Heads up!

3D vectors

General

c-v3 c <expression>

c-v3 m [r | d]

Operators

not n

n!

a ^ b

a * b

a / b

a % b

a + b

a - b

a is b

a nis b

a ais b

a anis b

a > b

a < b

a >= b

a <= b

a and b

a or b

Vector literals

(a, b, c)

(a, b, c, d, e, f)

Vector constants

Modified Vector2 functions

Removed functions

Unique functions

z(v)

oct(v)

dirx(v)

diry(v)

dirz(v)

cross(v1, v2)