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

calculate

描述

calculate 方法是 HeuristicPolicyEuclid 类的一个方法。该方法用于计算两个给定物品的欧几里德距离。

语法

HeuristicPolicyEuclid.calculate(item1, item2);

参数

item1: 必需,表示第一个物品对象,格式为 {x: number, y: number}

item2: 必需,表示第二个物品对象,格式同 item1

返回值

该方法返回两个物品之间的欧几里德距离,即 √((x1-x2)^2 + (y1-y2)^2)

示例

const item1 = {x: 1, y: 2};
const item2 = {x: 4, y: 6};
const distance = HeuristicPolicyEuclid.calculate(item1, item2);
console.log(distance); // 输出 5

备注

该方法只适用于计算物品的欧几里德距离,不适用于其他类型的距离计算。item1item2 的格式必须一致,且必须包含 xy 两个属性。