벡터의 내적

ㅋㅋ·2022년 6월 2일

유니티강의

목록 보기
3/24

A(x1, y1) B(x2, y2) 두 벡터가 있을 때

두 벡터의 내적(dot product)은 AB\overset{\rightarrow}{A} \cdot \overset{\rightarrow}{B}로 나타낼 수 있고 스칼라 값이 나오게 된다.

AB\overset{\rightarrow}{A} \cdot \overset{\rightarrow}{B}
= x1x2 + y1y2
= A×B×cosθ\vert \overset{\rightarrow}{A} \vert\times \vert\overset{\rightarrow}{B}\vert \times \cos\theta (θ\theta = 0 ~ 180)

여기서 A, B 벡터의 크기는 0보다 크기 때문에 내적의 값이 +, -, 0값을 가질 때

cosθ\cos\theta에 영향을 받았다는 것을 알 수 있다.

내적의 값이 0보다 크면 cosθ\cos\theta는 +값을 가져야 하기 때문에 0 <= θ\theta < 90 이어야 한다.

내적의 값이 0이면 θ\theta == 90 이며,

내적의 값이 0보다 작으면 90 < θ\theta <= 180 인 것을 알 수 있다.


벡터 A와 B가 방향벡터라면 내적은 cosθ\cos\theta와 같다.

단위벡터 A와 C의 내적이 cosα\cos\alpha일 때 cosθ\cos\theta보다 크다면 α\alphaθ\theta보다 작다는 것을 알 수 있다.

cosα\cos\alpha > cosθ\cos\theta => α\alpha < θ\theta

(0 ~ 180도 사이에서 cos은 1에서 0으로 줄어들며 단조 감소 함수이기 때문에)


Vector3 dirVec = distanceVec.normalized;
                
if(Vector3.Dot(transform.up, dirVec) > Mathf.Cos(rangeAngle*Mathf.Deg2Rad))
    i++;

유니티에서 내적은 Vectot3.Dot 함수를 사용하여 얻을 수 있다.

transform.up은 y축(green) 벡터를 의미하며

transform.up, right, Vector3.left, down 등은 모두 방향벡터이다.

0개의 댓글