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

edges

简介

edges 方法是 Yuka.js 库中 ConvexHull 类的一个静态方法,用于计算凸包的所有边。

ConvexHull 是计算凸包的一个类,ConvexHull 计算多个点的凸包,其中凸包边缘的点称为凸包的边。

语法

ConvexHull.edges(points)

参数

  • points:类型为一个数组,包含一系列的点坐标,每个点坐标是一个由两个数值组成的数组,分别表示点在 x、y 轴上的坐标值。

返回值

返回一个数组,其中包含所有凸包边的两个端点。每个端点也是一个数组,分别表示端点在 x、y 轴上的坐标值。

示例

import { ConvexHull } from 'yuka';

const points = [
  [1, 2],
  [3, 7],
  [4, 5],
  [6, 3],
  [8, 9],
  [9, 1]
];

const edges = ConvexHull.edges(points);

console.log(edges);

输出结果如下:

[
  [1, 2],
  [3, 7],
  [3, 7],
  [8, 9],
  [8, 9],
  [9, 1],
  [9, 1],
  [6, 3],
  [6, 3],
  [1, 2]
]

注意事项

  • edges 方法是 ConvexHull 类的静态方法,因此调用时无需实例化 ConvexHull 类。
  • 边数组中的每个端点只包含一个精度位数。