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

标题:vertices

概述

vertices是Yuka js库中ConvexHull对象的属性之一,代表凸壳的顶点列表。ConvexHull对象用于计算二维或三维点集的凸包。

用法

可以通过以下代码访问ConvexHull对象的vertices属性并获取凸壳的顶点列表:

const convexHull = new YUKA.ConvexHull(points);
const vertices = convexHull.vertices;

其中,points是二维或三维点集,是一个数组,例如:

const points = [
  new YUKA.Vector3(0, 1, 0),
  new YUKA.Vector3(1, 1, 0),
  new YUKA.Vector3(1, 0, 0),
  new YUKA.Vector3(0, 0, 0)
];

vertices属性返回的是一个数组,包含凸壳的所有顶点。每个元素是一个YUKA.Vector3对象,代表二维或三维空间中的一个点。

const vertices = [
  new YUKA.Vector3(0, 1, 0),
  new YUKA.Vector3(1, 1, 0),
  new YUKA.Vector3(1, 0, 0),
  new YUKA.Vector3(0, 0, 0)
];

示例

以下代码演示了如何使用ConvexHull对象计算二维点集的凸包,并绘制凸包的顶点:

const points = [
  new YUKA.Vector2(100, 50),
  new YUKA.Vector2(50, 100),
  new YUKA.Vector2(0, 50),
  new YUKA.Vector2(50, 0)
];

const convexHull = new YUKA.ConvexHull(points);
const vertices = convexHull.vertices;

// 显示凸包的顶点
vertices.forEach(vertex => {
  const circle = new PIXI.Graphics();
  circle.lineStyle(2, 0xFF3300, 1);
  circle.beginFill(0xFF9933);
  circle.drawCircle(vertex.x, vertex.y, 5);
  circle.endFill();
  app.stage.addChild(circle);
});

运行以上代码,可以在canvas画布上看到四个顶点的圆形表示。

注意事项

  • points数组中至少需要有三个点。
  • 如果points数组中有重复的点,凸包中只会出现一个。
  • 返回的vertices数组中,顶点的顺序是按照逆时针方向排列的。