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

manhattanDistanceTo

描述

Vector3类中的manhattanDistanceTo方法返回向量的曼哈顿距离。

语法

manhattanDistanceTo(vector: Vector3): number

参数

  • vector:Vector3类的实例。用于计算曼哈顿距离的向量。

返回值

  • 返回一个数字,表示向量的曼哈顿距离。

示例

import { Vector3 } from 'yuka';

const vector1 = new Vector3( 1, 2, 3 );
const vector2 = new Vector3( 4, 5, 6 );

const distance = vector1.manhattanDistanceTo( vector2 );
console.log( distance ); // 输出: 9

备注

曼哈顿距离是在欧几里得距离的基础上,将直线距离转换为沿着轴线的距离和。换句话说,曼哈顿距离是对向量坐标轴的距离之和进行求和的结果,因此也称为城市街区距离或L1距离。