# base/vector3 (vanilla.js 0.4.0)

> https://vanillapunch.com/docs/vanilla.js/0.4.0/api/base/vector3/

3차원 벡터.

## Vector3 extends Object

3차원 벡터.

예제: 만들고 외적, 정규화하기

```js
import { Vector3 } from "./build/vanilla.js";

const right = Vector3.create(1, 0, 0);
const up = Vector3.up();
const forward = right.cross(up);
const offset = Vector3.create(3, 0, 4);
const direction = offset.normalize();
console.log(forward.x, forward.y, forward.z);
console.log(direction.x, direction.z, direction.length());
```

- `constructor()` (constructor, since 0.3.0): 생성.
- `equals(other)` (method, since 0.3.0): 비교.
  - `other` any: 비교할 값.
  - returns boolean: 같은 객체이거나 x, y, z 가 모두 같은 Vector3 면 참.
- `clone()` (method, since 0.3.0): 복제.
  - returns this: x, y, z 가 같은 새 벡터.
- `get/set x` (property, since 0.3.0): X 좌표 반환 프로퍼티.
  X 좌표 설정 프로퍼티.
  - returns number: X 좌표.
- `get/set y` (property, since 0.3.0): Y 좌표 반환 프로퍼티.
  Y 좌표 설정 프로퍼티.
  - returns number: Y 좌표.
- `get/set z` (property, since 0.3.0): Z 좌표 반환 프로퍼티.
  Z 좌표 설정 프로퍼티.
  - returns number: Z 좌표.
- `set(x, y, z)` (method, since 0.3.0): 대입.
  - `x` number: X 좌표.
  - `y` number: Y 좌표.
  - `z` number: Z 좌표.
- `getX()` (method, since 0.3.0): 가로축 반환.
  - returns number: X 좌표.
- `getY()` (method, since 0.3.0): 세로축 반환.
  - returns number: Y 좌표.
- `getZ()` (method, since 0.3.0): 깊이축 반환.
  - returns number: Z 좌표.
- `length()` (method, since 0.3.0): 길이.
  - returns number: 벡터의 길이.
- `lengthSquared()` (method, since 0.3.0): 길이 제곱.
  - returns number: 길이의 제곱.
- `normalize()` (method, since 0.3.0): 정규화.
  - returns Vector3: 길이를 1 로 맞춘 새 벡터. (길이가 0 이면 그대로 복사한다)
- `add(other)` (method, since 0.3.0): 더하기.
  - `other` Vector3 | number: 더할 벡터나 수. (수면 세 성분에 같은 수를 더한다, 그 밖의 꼴이면 오류를 던진다)
  - returns Vector3: 계산한 새 벡터. (자신은 바뀌지 않는다)
- `subtract(other)` (method, since 0.3.0): 빼기.
  - `other` Vector3 | number: 뺄 벡터나 수. (수면 세 성분에 같은 수를 뺀다, 그 밖의 꼴이면 오류를 던진다)
  - returns Vector3: 계산한 새 벡터. (자신은 바뀌지 않는다)
- `multiply(other)` (method, since 0.3.0): 곱하기.
  - `other` Vector3 | number: 곱할 벡터나 수. (수면 세 성분에 같은 수를 곱한다, 그 밖의 꼴이면 오류를 던진다)
  - returns Vector3: 계산한 새 벡터. (자신은 바뀌지 않는다)
- `divide(other)` (method, since 0.3.0): 나누기.
  - `other` Vector3 | number: 나눌 벡터나 수. (수면 세 성분을 같은 수로 나눈다, 그 밖의 꼴이면 오류를 던진다)
  - returns Vector3: 계산한 새 벡터. (자신은 바뀌지 않는다)
- `addScalar(scalar)` (method, since 0.4.0): 수 더하기. (모든 성분에 같은 수, add(number) 와 같다)
  - `scalar` number: 더할 수.
  - returns Vector3: 계산한 새 벡터.
- `subtractScalar(scalar)` (method, since 0.4.0): 수 빼기. (모든 성분에 같은 수, subtract(number) 와 같다)
  - `scalar` number: 뺄 수.
  - returns Vector3: 계산한 새 벡터.
- `multiplyScalar(scalar)` (method, since 0.4.0): 수 곱하기. (모든 성분에 같은 수, multiply(number) 와 같다)
  - `scalar` number: 곱할 수.
  - returns Vector3: 계산한 새 벡터.
- `divideScalar(scalar)` (method, since 0.4.0): 수 나누기. (모든 성분에 같은 수, divide(number) 와 같다)
  - `scalar` number: 나눌 수.
  - returns Vector3: 계산한 새 벡터.
- `dot(other)` (method, since 0.3.0): 내적.
  - `other` Vector3: 내적할 벡터.
  - returns number: 내적 값.
- `cross(other)` (method, since 0.3.0): 외적.
  - `other` Vector3: 외적할 벡터.
  - returns Vector3: this 와 other 에 수직인 새 벡터. (this × other)
- `distance(other)` (method, since 0.3.0): 거리.
  - `other` Vector3: 거리를 잴 벡터.
  - returns number: 두 점 사이의 거리.
- `static create(x, y, z)` (static, since 0.3.0): 생성. (정적)
  - `x` number: X 좌표.
  - `y` number: Y 좌표.
  - `z` number: Z 좌표.
  - returns Vector3: 새 벡터.
- `static zero()` (static, since 0.3.0): 영벡터 생성. (정적)
  - returns Vector3: (0, 0, 0) 벡터.
- `static one()` (static, since 0.3.0): 일벡터 생성. (정적)
  - returns Vector3: (1, 1, 1) 벡터.
- `static up()` (static, since 0.3.0): 위쪽 단위벡터 생성. (정적)
  - returns Vector3: (0, 1, 0) 벡터.
- `static lerp(from, to, normalizedTime)` (static, since 0.3.0): 선형 보간. (정적)
  - `from` Vector3: 시작 벡터.
  - `to` Vector3: 끝 벡터.
  - `normalizedTime` number: 0 이면 from, 1 이면 to. (0 ~ 1 밖이어도 자르지 않고 늘여 보간한다)
  - returns Vector3: 보간한 새 벡터.
