AABB
AlignmentBehavior
ArriveBehavior
AStar
BFS
BoundingSphere
BVH
BVHNode
Cell
CellSpacePartitioning
CohesionBehavior
CompositeGoal
ConvexHull
Corridor
CostTable
DFS
Dijkstra
Edge
EntityManager
EvadeBehavior
EventDispatcher
Behavior
FollowPathBehavior
FuzzyAND
FuzzyCompositeTerm
FuzzyFAIRLY
FuzzyModule
FuzzyOR
FuzzyRule
FuzzySet
FuzzyTerm
FuzzyVariable
FuzzyVERY
GameEntity
Goal
GoalEvaluator
Graph
GraphUtils
HalfEdge
HeuristicPolicyDijkstra
HeuristicPolicyEuclid
HeuristicPolicyEuclidSquared
HeuristicPolicyManhattan
InterposeBehavior
LeftSCurveFuzzySet
LeftShoulderFuzzySet
LineSegment
Logger
MathUtils
Matrix3
Matrix4
MemoryRecord
MemorySystem
MeshGeometry
MessageDispatcher
MovingEntity
NavEdge
NavMesh
NavMeshLoader
NavNode
Node
NormalDistFuzzySet
OBB
ObstacleAvoidanceBehavior
OffsetPursuitBehavior
OnPathBehavior
Path
Plane
Polygon
Polyhedron
PriorityQueue
PursuitBehavior
Quaternion
Ray
RectangleTriggerRegion
Regular
RightSCurveFuzzySet
RightShoulderFuzzySet
SAT
SeekBehavior
SeparationBehavior
SingletonFuzzySet
Smoother
SphericalTriggerRegion
State
StateMachine
SteeringBehavior
SteeringManager
Task
TaskQueue
Telegram
Think
Time
TriangularFuzzySet
Trigger
TriggerRegion
Vector3
Vehicle
Version
WanderBehavior

closestPointToPointParameter

描述

该方法用于计算一个给定点到一个线段上最近点在该线段上的位置参数,范围为0到1。

语法

LineSegment.prototype.closestPointToPointParameter(point, clampToLine)

参数

  • point: {Vector3} 一个 THREE.Vector3 实例,表示目标点的位置。
  • clampToLine: {boolean} 可选参数,表示计算的最近点是否被限制在线段范围内。默认值为 true

返回值

  • {number} 范围为0到1之间的位置参数,表示点到线段最近点在 fromto 点之间的相对位置。

示例

const from = new THREE.Vector3(-10, 0, 0);
const to = new THREE.Vector3(10, 0, 0);
const segment = new THREE.LineSegment(from, to);

const pointA = new THREE.Vector3(5, 5, 0);
const parameterA = segment.closestPointToPointParameter(pointA); // 0.5

const pointB = new THREE.Vector3(-20, 0, 0);
const parameterB = segment.closestPointToPointParameter(pointB); // 0

const pointC = new THREE.Vector3(0, 10, 0);
const parameterC = segment.closestPointToPointParameter(pointC); // 1

const pointD = new THREE.Vector3(-20, -20, 0);
const parameterD = segment.closestPointToPointParameter(pointD, false); // -1

注意事项

  • 如果 clampToLinefalse,则计算的最近点可能位于线段范围之外,此时位置参数可能小于0或大于1。