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

getContour

getContour() 方法返回描述多边形边界的有序点列表。

语法

polygon.getContour()

返回值

一个由多个点组成的数组,按照多边形边缘的顺序排列。每个点是一个由两个数字组成的数组,分别表示该点的 x 和 y 坐标。

例如,一个三角形的轮廓可能如下所示:

[ [50, 150], [100, 50], [150, 150] ]

示例

以下代码创建一个简单的矩形多边形,并获取其边缘轮廓:

const polygon = new Yuka.Polygon();
polygon.vertices.push(new Yuka.Vector2(50, 50));
polygon.vertices.push(new Yuka.Vector2(150, 50));
polygon.vertices.push(new Yuka.Vector2(150, 150));
polygon.vertices.push(new Yuka.Vector2(50, 150));

const contour = polygon.getContour();
console.log(contour);

输出的结果将是类似下面的内容:

[ [50, 50], [150, 50], [150, 150], [50, 150] ]

注意事项

  • 多边形应该是封闭的,否则返回的结果将不会是正确的。
  • 点的顺序应该沿着边界的方向排列。例如,一个三角形应该按照逆时针的方向排列其顶点,而不是顺时针的方向。