노멀 벡터(즉, 평면에 수직인 벡터)는 메시 생성 중에 자주 필요하며 경로 추적 및 다른 상황에서도 유용합니다. 평면의 세 점(예: 메시 삼각형의 코너 점)이 주어질 경우, 노멀을 쉽게 찾을 수 있습니다. 세 점 중 아무 점이나 하나 선택하고, 이 점을 다른 두 점에서 각각 빼면 두 개의 백터를 구할 수 있습니다.
var a: Vector3;
var b: Vector3;
var c: Vector3;
var side1: Vector3 = b - a;
var side2: Vector3 = c - a;
이 두 벡터의 외적은 표면에 수직인 세 번째 벡터를 제공합니다. “왼손 규칙”은 두 벡터를 외적 함수에 전달해야 하는 순서를 결정하는 데 사용할 수 있습니다. 표면의 윗면을 내려다 볼 때(즉 노멀이 가리키며 뻗어나가는 쪽에서 평면 방향을 보면) 첫 번째 벡터는 시계 방향으로 두 번째 벡터로 돌아야 합니다.
var perp: Vector3 = Vector3.Cross(side1, side2);
입력 벡터의 순서가 바뀌면 결과는 정확히 반대 방향을 가리킵니다.
메시의 경우 노멀 벡터도 정규화되어야 합니다. 정규화된 프로퍼티를 사용하여 이 작업을 수행할 수 있지만 때때로 유용한 또 다른 트릭이 있습니다. 직각 벡터를 자체 크기로 나눠 정규화할 수도 있습니다.
var perpLength = perp.magnitude;
perp /= perpLength;
결과적으로 삼각형의 영역은 perpLength / 2와 동일합니다. 메시의 전체 표면 영역을 알고 싶을 때, 또는 상대 영역을 기반으로 삼각형을 임의의 확률로 선택하려는 경우에 유용합니다.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.