# Vector

Vector에 대한 정보를 다루는 객체에요.

## **연산자**

<br>

| **Vector = Vector + Vector** |
| ---------------------------- |

두 벡터 값을 더해서 그 값을 리턴해줘요.

<br>

| **Vector = Vector - Vector** |
| ---------------------------- |

앞에 벡터에서 뒤의 벡터를 뺀 값을 리턴해줘요.

<br>

| **Vector = Vector \* Vector** |
| ----------------------------- |

두 벡터 값을 곱해서 그 값을 리턴해줘요.

<br>

| **Vector = Vector \* number** |
| ----------------------------- |

벡터와 number 값을 곱해서 그 값을 리턴해줘요.

<br>

| **Vector = -Vector** |
| -------------------- |

벡터의 값을 부정으로 만들어서 그 값을 리턴해줘요.

<br>

| **Vector = Vector + number** |
| ---------------------------- |

벡터의 값과 number값을 더해서 그 값을 리턴해줘요.

<br>

| **Vector = Vector - number** |
| ---------------------------- |

벡터의 값에서 number값을 뺀 값을 리턴해줘요.

<br>

| **Vector = Vector / number** |
| ---------------------------- |

벡터의 값에서 number을 나눈 값을 리턴해줘요. (0으로는 나눌 수 없어요.)

## **속성**

<br>

| **Size** |
| -------- |

벡터의 크기에요.

\-- 샘플 --

```lua
local pos = Vector.new(200, -100, 900)
print(pos.Size)
```

<br>

| **SqrSize** |
| ----------- |

\-- 샘플 --

```lua
local pos = Vector.new(200, -100, 900)
print(pos.SqrSize)
```

<br>

| **X** |
| ----- |

X 좌표에요.

<br>

| **Y** |
| ----- |

Y 좌표에요.

<br>

| **Z** |
| ----- |

Z 좌표에요.

\-- 샘플 --

```lua
local pos1 = Vector.new(1, 2, 3) --pos1.X = 1, pos1.Y = 2, pos1.Z = 3로 할당돼요.
local pos2 = Vector.new(3)       --pos2.X = 3, pos2.Y = 3, pos2.Z = 3로 할당돼요.
local pos3 = pos1 + pos2         --pos3.X = 4, pos3.Y = 5, pos3.Z = 6로 할당돼요.

local cube = Workspace.Cube
local cubeTransform = cube.Transform
cubeTransform.Location = Vector.new(400, 0, 100)
cube.Transform = cubeTransform --오브젝트의 위치를 설정해요.

local pos4 = Vector.new()        --pos4.X = 0,  pos4.Y = 0, pos4.Z = 0로 할당돼요.
pos4.X = 10                      --pos4.X = 10, pos4.Y = 0, pos4.Z = 0로 할당돼요.
pos4.Normalize()                 --pos4.X = 1,  pos4.Y = 0, pos4.Z = 0로 할당돼요.
```

## **생성자**

<br>

| **Vector new(number X, number Y, number Z)** |
| -------------------------------------------- |

Vector를 X, Y, Z 좌표값을 이용해서 생성해줘요. (생성할 X좌표 값, 생성할 Y좌표 값, 생성할 Z좌표 값)

<br>

| **Vector new(number Value)** |
| ---------------------------- |

Vector를 Value값을 이용해서 생성해줘요. (생성할 Value 값)

<br>

| **Vector new()** |
| ---------------- |

Vector의 X, Y, Z 좌표를 0으로해서 생성해줘요.

\-- 샘플 --

```lua
local pos1 = Vector.new(200, -100, 900)
local pos2 = Vector.new(200) --X = 200, Y = 200, Z = 200으로 할당돼요.
local pos3 = Vector.new()    --전부 0으로 할당돼요.
```

## **함수**

<br>

| **void Normalize()** |
| -------------------- |

단위를 1로 정규화 시켜주는 함수에요.

\-- 샘플 --

```lua
local pos = Vector.new(200, -100, 900)
print(pos)

pos:Normalize()
print(pos)
```

<br>

| **number CosineAngle2D(Vector Other)** |
| -------------------------------------- |

두 벡터의 XY 평면의 사잇각의 cos 값을 리턴해줘요. (사잇각을 구할 벡터)

\-- 샘플 --

```lua
local cube = Workspace.Cube
local characterPos = character.Transform.Location
local targetPos = cube.Transform.Location

local angle = characterPos:CosineAngle2D(targetPos)
print(angle)
```

<br>

| **string ToString(Vector Other)** |
| --------------------------------- |

"R:값 , G:값 , B:값, A:값" 형태로 string 을 리턴해요.

\-- 샘플 --

```lua
local vector = Vector.new(300, 0, 300)
print("Vector : " .. vector:ToString())
```

<br>

| **number Dot(Vector Other)** |
| ---------------------------- |

other vector 와의 내적값을 리턴해요.

\-- 샘플 --

```lua
local vector = Vector.new(300, 0, 300)
local otherVector = Vector.new(600, 0, 300)

local result = vector:Dot(otherVector)
print("Vector:Dot : ", result)
```

<br>

| **vector Cross(Vector Other)** |
| ------------------------------ |

othervector 와의 외적값을 리턴해요.

\-- 샘플 --

```lua
local vector = Vector.new(300, 0, 300)
local otherVector = Vector.new(600, 0, 300)

local result = vector:Cross(otherVector)
print("Vector:Cross : ", result)
```

<br>

| **number Distance(Vector Other)** |
| --------------------------------- |

othervector 와의 거리값을 리턴해요.

\-- 샘플 --

```lua
local vector = Vector.new(300, 0, 300)
local otherVector = Vector.new(600, 0, 300)

local result = vector:Distance(otherVector)
print("Vector:Distance : ", result)
```

<br>

| **number SqrDistance(Vector Other)** |
| ------------------------------------ |

othervector 와의 거리 제곱값을 리턴해요.

\-- 샘플 --

```lua
local vector = Vector.new(300, 0, 300)
local otherVector = Vector.new(600, 0, 300)

local result = vector:SqrDistance(otherVector)
print("Vector:SqrDistance : ", result)
```

<br>

| **number Angle(Vector Other)** |
| ------------------------------ |

othervector 와의 사이각을 리턴해요.

\-- 샘플 --

```lua
local vector = Vector.new(300, 0, 300)
local otherVector = Vector.new(600, 0, 300)

local result = vector:Angle(otherVector)
print("Vector:Angle : ", result)
```

<br>

| **vector Reflect(Vector Normal)** |
| --------------------------------- |

normal 에 부딪히는 반사각을 리턴해요.

\-- 샘플 --

```lua
local vector = Vector.new(300, 0, 300)
local otherVector = Vector.new(600, 0, 300)

local result = vector:Reflect(otherVector)
print("Vector:Reflect : ", result)
```

<br>

| **vector Clone()** |
| ------------------ |

같은 벡터를 새로 생성해서 리턴해요.

\-- 샘플 --

```lua
local Vector1 = Vector.new(100, 100, 100)
local NewVector = Vector1:Clone(Vector1)
print("Clone Vector : ", NewVector)
```

<br>

| **void SizeLimit(number max)** |
| ------------------------------ |

벡터의 크기를 max로 제한해요.\
((X^2 + Y^2 + Z^2)^(1 / 2)) = Max

\-- 샘플 --

```lua
local Vector1 = Vector.new(100, 100, 100)
Vector1:SizeLimit(50)
print("Size Limit : ", Vector1)
```

<br>

| **vector RotateAxisX(number angle)** |
| ------------------------------------ |

X축을 고정으로 해서 벡터 회전한 다음 리턴해요.

\-- 샘플 --

```lua
local RotateX = Vector1:RotateAxisX(10)
print("RotateAxisX : ", RotateX)
```

<br>

| **vector RotateAxisY(number angle)** |
| ------------------------------------ |

Y축을 고정으로 해서 벡터 회전한 다음 리턴해요.

\-- 샘플 --

```lua
local RotateY = Vector1:RotateAxisY(10)
print("RotateAxisY : ", RotateY)
```

<br>

| **vector RotateAxisZ(number angle)** |
| ------------------------------------ |

Z축을 고정으로 해서 벡터 회전한 다음 리턴해요.

\-- 샘플 --

```lua
local RotateZ = Vector1:RotateAxisZ(10)
print("RotateAxisZ : ", RotateZ)
```

<br>

| **number SignedAngle2D(Vector othervector)** |
| -------------------------------------------- |

othervector 와의 사이각을 리턴해요. (음수 포함)

\-- 샘플 --

```lua
local Vector2 = Vector.new(100, 0, 100)
local Vector3 = Vector.new(0, 100, 100)
local SignedAngle = Vector2:SignedAngle2D(Vector3)
print("SignedAngle2D : ", SignedAngle)
```

<br>

| **vector zero()** |
| ----------------- |

zero 벡터를 리턴해요. (0,0,0)

\-- 샘플 --

```lua
local Zero = Vector.zero()
print("Vector Zero : ", Zero)
```

<br>

| **vector one()** |
| ---------------- |

one 벡터를 리턴해요. (1,1,1)

\-- 샘플 --

```lua
local One = Vector.one()
print("Vector One : ", One)
```

<br>

| **vector forward()** |
| -------------------- |

forward 벡터를 리턴해요. (1,0,0)

\-- 샘플 --

```lua
local Forward = Vector.forward()
print("Vector Forward : ", Forward)
```

<br>

| **vector right()** |
| ------------------ |

right 벡터를 리턴해요. (0,1,0)

\-- 샘플 --

```lua
local Right = Vector.right()
print("Vector Right : ", Right)
```

<br>

| **vector up()** |
| --------------- |

up 벡터를 리턴해요. (0,0,1)

\-- 샘플 --

```lua
local Up = Vector.up()
print("Vector Up : ", Up)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ditoland-utplus.gitbook.io/ditoland/api-reference/common/vector.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
