단위 벡터[프로그래밍][이동 방향, 물리 계산, 3D 그래픽]
단위 벡터(Unit Vector)와 프로그래밍에서의 활용 단위 벡터(Unit Vector)는 크기가 1이고 방향을 나타내는 벡터 로, 전기자기학에서는 전기장(𝐄), 자기장(𝐁), 전위(𝑉) 등의 방향을 표현하는 데 사용됩니다. 또한, 프로그래밍에서는 그래픽스, 게임 개발, 로봇 공학 등에서 방향 계산을 위해 필수적으로 활용됩니다. 1. 단위 벡터란? 벡터 𝐀 의 단위 벡터 â 는 다음과 같이 정의됩니다. a ^ = A ∣ A ∣ a ^ = ∣ A ∣ A 즉, 벡터의 크기를 1로 정규화하여 방향만 남긴 것 입니다. 2. 프로그래밍에서 단위 벡터 활용 (1) 벡터 정규화 (Python 예제) python import numpy as np def normalize_vector ( vector ): magnitude = np.linalg.norm(vector) return vector / magnitude if magnitude != 0 else vector v = np.array([ 3 , 4 , 0 ]) print ( "단위 벡터:" , normalize_vector(v)) (2) 게임 개발에서 이동 방향 설정 (C++ / Unreal Engine) Cpp FVector direction = FVector ( 1 , 2 , 0 ); direction. Normalize (); character-> AddMovementInput (direction, speed); (3) 로봇 공학에서 목표 이동 방향 계산 (Python) python current_pos = np.array([ 2 , 3 , 0 ]) target_pos = np.array([ 5 , 7 , 0 ]) direction = target_pos - current_pos unit_direction = direction / np.linalg.norm(direction) ...