3次元空間で点Pから最も近い直線AB上に存在する点を求める方法をメモ。
[ 方法 ]
using System.Collections; using System.Collections.Generic; using UnityEngine; public class script : MonoBehaviour { // 点Pから最も近い直線AB上に存在する点を求める関数 private Vector3 ClosestPointOnStraightLine(Vector3 a, Vector3 b, Vector3 p) { Vector3 vecAB = b - a; Vector3 vecAP = p - a; Vector3 closestPos = a + Vector3.Project(vecAP, vecAB); return closestPos; } }