cpan:JEFFOBER

Math::Vector3D

0.0.1

# SYNOPSIS

``````use Math::Vector3D;

my \$vec = vec(10, 20, 30);

\$vec -= \$other-vector;
\$vec *= 42;
\$vec /= 10;

\$vec.normalize;

my \$len = \$vec.length;
``````

• Math::Vector

Has support for any number of dimensions.

## class Math::Vector3D

Vector object

Default: 0

Default: 0

Default: 0

### method length-squared

```method length-squared() returns Numeric
```

Returns the squared length of the vector

### method length

```method length() returns Numeric
```

Returns the length of the vector

```multi method add(
Math::Vector3D:D \$v
) returns Math::Vector3D
```

Destructively adds a vector to this vector.

```multi method add(
Numeric:D \$n
) returns Math::Vector3D
```

Destructively adds a scalar to this vector.

### multi method sub

```multi method sub(
Math::Vector3D:D \$v
) returns Math::Vector3D
```

Destructively subtracts a vector from this vector.

### multi method sub

```multi method sub(
Numeric:D \$n
) returns Math::Vector3D
```

Destructively subtracts a scalar from this vector.

### multi method mul

```multi method mul(
Math::Vector3D:D \$v
) returns Math::Vector3D
```

Destructively multiplies this vector by another vector.

### multi method mul

```multi method mul(
Numeric:D \$n
) returns Math::Vector3D
```

Destructively multiplies this vector by a scalar value.

### multi method div

```multi method div(
Math::Vector3D:D \$v
) returns Math::Vector3D
```

Destructively divides this vector by another vector.

### multi method div

```multi method div(
Numeric:D \$n
) returns Math::Vector3D
```

Destructively divides this vector by a scalar value.

### method negate

```method negate() returns Math::Vector3D
```

Returns a new vector with negated values for x, y, and z.

### method cross

```method cross(
Math::Vector3D:D \$v
) returns Math::Vector3D
```

Destructively updates this vector to be the cross product of itself and another vector.

### method dot

```method dot(
Math::Vector3D:D \$v
) returns Numeric
```

Computes the dot product of the vector and the supplied number.

### method angle-to

```method angle-to(
Math::Vector3D:D \$v
) returns Numeric
```

Computes the angle to the supplied vector.

### method distance-to-squared

```method distance-to-squared(
Math::Vector3D:D \$v
) returns Numeric
```

Computes the square of the distance between this vector and the supplied vector.

### method distance-to

```method distance-to(
Math::Vector3D:D \$v
) returns Numeric
```

Computes the distance between this vector and the supplied vector.

### method normalize

```method normalize() returns Math::Vector3D
```

Destructively normalizes this vector.

### method set-length

```method set-length(
Numeric:D \$n
) returns Math::Vector3D
```

Destructively sets the length of the vector.

### method lerp

```method lerp(
Math::Vector3D:D \$target,
Numeric:D \$n
) returns Math::Vector3D
```

Lerps toward the target vector by the supplied value.

### method List

```method List() returns List
```

Coerces to a List of [x, y, z]

### multi sub infix:<+>

```multi sub infix:<+>(
Math::Vector3D:D \$v,
\$n
) returns Math::Vector3D
```

### multi sub infix:<->

```multi sub infix:<->(
Math::Vector3D:D \$v,
\$n
) returns Math::Vector3D
```

### multi sub infix:<*>

```multi sub infix:<*>(
Math::Vector3D:D \$v,
\$n
) returns Math::Vector3D
```

### multi sub infix:</>

```multi sub infix:</>(
Math::Vector3D:D \$v,
\$n
) returns Math::Vector3D
```

### multi sub infix:<==>

```multi sub infix:<==>(
Math::Vector3D:D \$v1,
Math::Vector3D:D \$v2
) returns Bool
```

== is overloaded to compare two vectors' x, y, and z values

### multi sub vec

```multi sub vec(
Numeric:D \$x = 0,
Numeric:D \$y = 0,
Numeric:D \$z = 0
) returns Math::Vector3D
```

Syntactic sugar to construct a new vector from three numbers.

### multi sub vec

```multi sub vec(
Math::Vector3D:D \$v
) returns Math::Vector3D
```

Syntactic sugar to construct a new vector from another vector (clone).