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

squaredDistanceTo

源码:

Vector3.prototype.squaredDistanceTo = function (v) {
    let dx = this.x - v.x;
    let dy = this.y - v.y;
    let dz = this.z - v.z;
    return dx * dx + dy * dy + dz * dz;
};

参数:

  • v:Vector3类型,表示所求距离的另一个向量。

返回值:

  • 返回两个向量之间的距离的平方。距离的平方可以用来进行较快的距离比较计算而不涉及平方根。

描述:

该函数用于计算一个向量与另一个向量之间的距离的平方。它通过分别计算两个向量X、Y、Z方向上的距离之差并将它们的平方加起来来实现。这是距离比较的常用实践,因为计算平方的速度比计算平方根要快得多。

实例:

let v1 = new YUKA.Vector3(1,2,3);
let v2 = new YUKA.Vector3(3,2,1);
let squaredDistance = v1.squaredDistanceTo(v2);
console.log(squaredDistance); //结果为8

在此示例中,我们创建两个Vector3对象v1和v2,并使用它们的x、y、z坐标值计算它们之间的距离的平方。输出的结果为8,这是两个向量之间的距离的平方。