base/vector2
2차원 벡터.
2D vector.
Vector2extends Object
2차원 벡터.
2D vector.
import { Vector2 } from "./build/vanilla.js";
const position = Vector2.create(3, 4);
const moved = position.add(Vector2.create(1, 0));
console.log(moved.x, moved.y, position.length());생성.
Constructor.
새로운 벡터 생성.
Creates a new vector.
- xnumber
- X 좌표.X coordinate.
- ynumber
- Y 좌표.Y coordinate.
반환ReturnsVector2 새 벡터.A new vector.
짝Counterpart: vanilla-engine Vector2.create
0의 값을 가진 벡터 생성.
Creates a vector with the value 0.
반환ReturnsVector2 (0, 0) 벡터.A (0, 0) vector.
짝Counterpart: vanilla-engine Vector2.zero
1의 값을 가진 벡터 생성.
Creates a vector with the value 1.
반환ReturnsVector2 (1, 1) 벡터.A (1, 1) vector.
짝Counterpart: vanilla-engine Vector2.one
-1의 값을 가진 벡터 생성.
Creates a vector with the value -1.
반환ReturnsVector2 (-1, -1) 벡터.A (-1, -1) vector.
짝Counterpart: vanilla-engine Vector2.minus_one
최대값 벡터 생성.
Creates a maximum-value vector.
반환ReturnsVector2 (Infinity, Infinity) 벡터.An (Infinity, Infinity) vector.
짝Counterpart: vanilla-engine Vector2.positive_infinity
최소값 벡터 생성.
Creates a minimum-value vector.
반환ReturnsVector2 (-Infinity, -Infinity) 벡터.A (-Infinity, -Infinity) vector.
짝Counterpart: vanilla-engine Vector2.negative_infinity
선형 보간.
Linear interpolation.
- fromVector2
- 시작 벡터.Start vector.
- toVector2
- 끝 벡터.End vector.
- normalizedTimenumber
- 0 이면 from, 1 이면 to. (0 ~ 1 밖이어도 자르지 않고 늘여 보간한다)0 gives from, 1 gives to. (values outside 0 ~ 1 are not clamped and extrapolate)
반환ReturnsVector2 보간한 새 벡터.A new interpolated vector.
짝Counterpart: vanilla-engine Vector2.lerp
import { Vector2 } from "./build/vanilla.js";
const start = Vector2.create(0, 0);
const end = Vector2.create(100, 50);
const middle = Vector2.lerp(start, end, 0.5);
console.log(middle.x, middle.y);범위 제한.
Clamps to a range.
- valueVector2
- 자를 벡터.Vector to clamp.
- minVector2
- 성분별 최솟값.Per-component minimum.
- maxVector2
- 성분별 최댓값.Per-component maximum.
반환ReturnsVector2 성분마다 min ~ max 로 자른 새 벡터.A new vector with each component clamped to min ~ max.
짝Counterpart: vanilla-engine Vector2.clamp
X 좌표 반환 프로퍼티. X 좌표 설정 프로퍼티.
X coordinate getter property. X coordinate setter property.
반환Returnsnumber X 좌표.X coordinate.
짝Counterpart: vanilla-engine Vector2.x
Y 좌표 반환 프로퍼티. Y 좌표 설정 프로퍼티.
Y coordinate getter property. Y coordinate setter property.
반환Returnsnumber Y 좌표.Y coordinate.
짝Counterpart: vanilla-engine Vector2.y
비교.
Comparison.
- otherany
- 비교할 값.Value to compare.
반환Returnsboolean 같은 객체이거나 x, y 가 모두 같은 Vector2 면 참.True if it is the same object or a Vector2 with the same x and y.
대입.
Assignment.
- xnumber
- X 좌표.X coordinate.
- ynumber
- Y 좌표.Y coordinate.
짝Counterpart: vanilla-engine Vector2.set
가로축 반환.
Returns the horizontal axis.
반환Returnsnumber X 좌표.X coordinate.
짝Counterpart: vanilla-engine Vector2.get_x
세로축 반환.
Returns the vertical axis.
반환Returnsnumber Y 좌표.Y coordinate.
짝Counterpart: vanilla-engine Vector2.get_y
정규화.
Normalize.
반환ReturnsVector2 길이를 1 로 맞춘 새 벡터. (길이가 0 이면 그대로 복사한다)A new vector scaled to length 1. (copied as is if the length is 0)
짝Counterpart: vanilla-engine Vector2.normalize
더하기.
Add.
- otherVector2 | number
- 더할 벡터나 수. (수면 두 성분에 같은 수를 더한다, 그 밖의 꼴이면 오류를 던진다)Vector or number to add. (a number is added to both components, other types throw an error)
반환ReturnsVector2 계산한 새 벡터. (자신은 바뀌지 않는다)A new computed vector. (this vector is not changed)
짝Counterpart: vanilla-engine Vector2.add
빼기.
Subtract.
- otherVector2 | number
- 뺄 벡터나 수. (수면 두 성분에 같은 수를 뺀다, 그 밖의 꼴이면 오류를 던진다)Vector or number to subtract. (a number is subtracted from both components, other types throw an error)
반환ReturnsVector2 계산한 새 벡터. (자신은 바뀌지 않는다)A new computed vector. (this vector is not changed)
짝Counterpart: vanilla-engine Vector2.subtract
곱하기.
Multiply.
- otherVector2 | number
- 곱할 벡터나 수. (수면 두 성분에 같은 수를 곱한다, 그 밖의 꼴이면 오류를 던진다)Vector or number to multiply by. (both components are multiplied by a number, other types throw an error)
반환ReturnsVector2 계산한 새 벡터. (자신은 바뀌지 않는다)A new computed vector. (this vector is not changed)
짝Counterpart: vanilla-engine Vector2.multiply
나누기.
Divide.
- otherVector2 | number
- 나눌 벡터나 수. (수면 두 성분을 같은 수로 나눈다, 그 밖의 꼴이면 오류를 던진다)Vector or number to divide by. (both components are divided by a number, other types throw an error)
반환ReturnsVector2 계산한 새 벡터. (자신은 바뀌지 않는다)A new computed vector. (this vector is not changed)
짝Counterpart: vanilla-engine Vector2.divide
나머지.
Modulo.
- otherVector2 | number
- 나눌 벡터나 수. (나머지를 구한다, 수면 두 성분을 같은 수로 나누고, 그 밖의 꼴이면 오류를 던진다)Vector or number to divide by. (takes the remainder, both components are divided by a number, other types throw an error)
반환ReturnsVector2 계산한 새 벡터. (자신은 바뀌지 않는다)A new computed vector. (this vector is not changed)
짝Counterpart: vanilla-engine Vector2.modulo
수 더하기. (모든 성분에 같은 수, add(number) 와 같다)
Adds a number. (Same number to every component, same as add(number))
- scalarnumber
- 더할 수.Number to add.
반환ReturnsVector2 계산한 새 벡터.A new computed vector.
짝Counterpart: vanilla-engine Vector2.add_scalar
수 빼기. (모든 성분에 같은 수, subtract(number) 와 같다)
Subtracts a number. (Same number from every component, same as subtract(number))
- scalarnumber
- 뺄 수.Number to subtract.
반환ReturnsVector2 계산한 새 벡터.A new computed vector.
짝Counterpart: vanilla-engine Vector2.subtract_scalar
수 곱하기. (모든 성분에 같은 수, multiply(number) 와 같다)
Multiplies by a number. (Same number for every component, same as multiply(number))
- scalarnumber
- 곱할 수.Number to multiply by.
반환ReturnsVector2 계산한 새 벡터.A new computed vector.
짝Counterpart: vanilla-engine Vector2.multiply_scalar
수 나누기. (모든 성분에 같은 수, divide(number) 와 같다)
Divides by a number. (Same number for every component, same as divide(number))
- scalarnumber
- 나눌 수.Number to divide by.
반환ReturnsVector2 계산한 새 벡터.A new computed vector.
짝Counterpart: vanilla-engine Vector2.divide_scalar
수 나머지. (모든 성분에 같은 수, modulo(number) 와 같다)
Modulo by a number. (Same number for every component, same as modulo(number))
- scalarnumber
- 나눌 수. (나머지를 구한다)Number to divide by. (takes the remainder)
반환ReturnsVector2 계산한 새 벡터.A new computed vector.
짝Counterpart: vanilla-engine Vector2.modulo_scalar
절반.
Half.
반환ReturnsVector2 x, y 를 2 로 나눈 새 벡터.A new vector with x and y divided by 2.
짝Counterpart: vanilla-engine Vector2.half
내적.
Dot product.
- otherVector2
- 내적할 벡터.Vector for the dot product.
반환Returnsnumber 내적 값.Dot product.
짝Counterpart: vanilla-engine Vector2.dot
외적 (2D cross product -> 스칼라 반환).
Cross product (2D cross product -> returns a scalar).
- otherVector2
- 외적할 벡터.Vector for the cross product.
반환Returnsnumber 외적 값. (this.x * other.y - this.y * other.x)Cross product. (this.x * other.y - this.y * other.x)
짝Counterpart: vanilla-engine Vector2.cross
두 벡터 사이의 거리.
Distance between two vectors.
- otherVector2
- 거리를 잴 벡터.Vector to measure the distance to.
반환Returnsnumber 두 점 사이의 거리.Distance between the two points.
짝Counterpart: vanilla-engine Vector2.distance
길이의 제곱 (루트 연산 최적화).
Squared length (square root optimization).
반환Returnsnumber 길이의 제곱.Squared length.
짝Counterpart: vanilla-engine Vector2.length_squared
두 벡터 사이의 각도 반환 (라디안).
Returns the angle between two vectors (radians).
- otherVector2
- 각도를 잴 벡터.Vector to measure the angle to.
반환Returnsnumber 두 벡터 사이의 각도. (라디안, 0 ~ π, 어느 한쪽 길이가 0 이면 NaN)Angle between the two vectors. (radians, 0 ~ π, NaN if either length is 0)
짝Counterpart: vanilla-engine Vector2.angle
import { Vector2, Math } from "./build/vanilla.js";
const right = Vector2.create(1, 0);
const up = Vector2.create(0, -1);
const radian = right.angle(up);
console.log(radian, Math.radianToDegree(radian));