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

closestPointToPoint

该方法是Yuka js库中LineSegment类的一个实例方法。它用于计算线段上离某一点最近的点的位置。

语法

closestPointToPoint( point, target );

参数

  • point:类型为Vector3的三维向量,表示要寻找最近点的目标点。
  • target:类型为Vector3的可选参数,表示存储最近点结果的向量。如果未提供此参数,则会创建新的Vector3返回结果。

返回值

类型为Vector3的向量,表示The position of the closest point。如果target被提供,则返回target,否则创建一个新的Vector3并返回。

错误处理

如果point参数不是Vector3的实例,则抛出一个TypeError错误。

示例

const segment = new YUKA.LineSegment( new YUKA.Vector3( 0, 0, 0 ), new YUKA.Vector3( 10, 0, 0 ) );

const point = new YUKA.Vector3( 5, 5, 0 );
const closestPoint = segment.closestPointToPoint( point );

console.log( closestPoint ); // Vector3(5, 0, 0)

该示例创建一个Yuka js库的LineSegment类的实例segment。然后创建一个三维向量point表示要寻找最近点的目标点。接着调用closestPointToPoint方法并将point作为参数传入。最后打印输出计算得到的最近点的位置。

参考资料