IT공부

[Unity] 수학과 Unity 관점에서 벡터와 스칼라 정리

shine94 2025. 6. 28. 23:50

* 수학에서의 백터와 스칼라

   (1) 스칼라(Scalar)

        크기만 갖는 값

        (예)  5m, 섭씨 20도, 256바이트, 4000 칼로리

 

   (2) 벡터(Vector)

        크기 + 방향을 갖는 값

        (예) 30m/초 동쪽, 약 5마일 북쪽, 힘, 가속도

 

   [정리하자면]

   핵심 차이는 방향의 존재 여부다

 

* 유니티에서의 Vector3

   유니티의 Vector3 구조체는 수학적 벡터 개념을 기반으로 한 자료형이지만,

   실제 의미는 어떻게 사용하느냐에 따라 달라진다

// 위치
transform.position = new Vector3(0, 3, 0);

// 방향(this → target)
Vector3 direction1 = target.position - transform.position;		// 두 위치 차이 벡터
Vector3 direction2 = (target.position - transform.position).normalized;	// 길이를 1로 만들어, 방향만 남긴 단위 벡터(normalized vector)

// 속도 또는 힘의 방향과 크기를 적용할 때(반드시 방향 벡터를 정규화해서 사용)
rigidbody.velocity = direction2 * 3f;
rigidbody.AddForce(direction2 * force);

 

direction1(이동 벡터)

방향 + 시작 위치로부터의 거리

이동해야 할 거리(크기)가 중요한 경우

(예) 목표까지 얼마나 멀리 가야하는지를 중요한 경우, 총알이 목표물까지 날아가는 방향과 거리


direction2(방향 벡터)

방향만

정규화된 단위 벡터(길이 1)

(예) 어디로 향해야 하는지만 중요한 경우, 캐릭터가 어느 방향을 바라보는가

 

 

 

 

* 참고한 문서들

https://www.physicsclassroom.com/class/1dkin/lesson-1/scalars-and-vectors?utm_source=chatgpt.com

 

Scalars and Vectors

Scalars and Vectors Hold down the T key for 3 seconds to activate the audio accessibility mode, at which point you can click the K key to pause and resume audio. Useful for the Check Your Understanding and See Answers. Physics is a mathematical science. Th

www.physicsclassroom.com

https://mathinsight.org/vector_introduction?utm_source=chatgpt.com

 

An introduction to vectors - Math Insight

Definition of a vector A vector is an object that has both a magnitude and a direction. Geometrically, we can picture a vector as a directed line segment, whose length is the magnitude of the vector and with an arrow indicating the direction. The direction

mathinsight.org

https://docs.unity3d.com/ScriptReference/Vector3-normalized.html?utm_source=chatgpt.com