반응형
참고
다음과 같이 직선 AB에 임의의 점 C가 있고, 점 D가 있다고 하자.

이때 직선 AB와 점 D의 거리 distance의 공식은 다음과 같다.
유니티 C#으로 구현하면 다음과 같다.
점 A와 점 B로 만든 직선의 임의의 점 C를 따로 정할 필요 없이, 점 A를 선택하였다.
float getDistancePointAndLine(Vector3 A, Vector3 B, Vector3 point)
{
Vector3 AB = B - A;
return (Vector3.Cross(point - A, AB)).magnitude / AB.magnitude;
}
Unity Plus:
Easy 2D, 3D, VR, & AR software for cross-platform development of games and mobile apps. - Unity Store
Have a 2D, 3D, VR, or AR project that needs cross-platform functionality? We can help. Take a look at the easy-to-use Unity Plus real-time dev platform!
store.unity.com
Unity Pro:
Unity Pro
The complete solutions for professionals to create and operate.
unity.com
Unity 프리미엄 학습:
Unity Learn
Advance your Unity skills with live sessions and over 750 hours of on-demand learning content designed for creators at every skill level.
unity.com
반응형
댓글