お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
Close2つのベクトルの外積
2つのベクトルの外積は2つのベクトルと垂直な3つめのベクトルの結果です。
求めたが遺跡の大きさは2つのベクトルを互いを乗算したものと、
2つのベクトル間の角度の正弦を乗算したものと等しくなります。
「左手の法則」を使って外積の方向を求めることが出来ます。
左手の法則によって適用されるCross(a, b)
// Get the normal to a triangle from the three corner points, a, b and c. function GetNormal(a: Vector3, b: Vector3, c: Vector3) { // Find vectors corresponding to two of the sides of the triangle. var side1 = b - a; var side2 = c - a; // Cross the vectors to get a perpendicular vector, then normalize it. return Vector3.Cross(side1, side2).normalized; }
using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { Vector3 GetNormal(Vector3 a, Vector3 b, Vector3 c) { Vector3 side1 = b - a; Vector3 side2 = c - a; return Vector3.Cross(side1, side2).normalized; } }
import UnityEngine import System.Collections public class ExampleClass(MonoBehaviour): def GetNormal(a as Vector3, b as Vector3, c as Vector3) as Vector3: side1 as Vector3 = (b - a) side2 as Vector3 = (c - a) return Vector3.Cross(side1, side2).normalized