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

contains

概述

contains方法用于判断一个点是否在指定的多边形内。

参数

  • points: Array,多边形的坐标点,格式为二维数组,如[[x1, y1], [x2, y2], [x3, y3]],其中[x1,y1]为多边形的第一个顶点坐标,以此类推。
  • point: Array,要判断的点的坐标,格式为一维数组,如[x,y],其中x为点的横坐标,y为点的纵坐标。

返回值

方法的返回值为Boolean,表示要判断的点是否在多边形内。若在,则返回true,不在,则返回false。

使用示例

//创建多边形
var polygon = [[0,0],[0,10],[10,10],[10,0]];
//要判断的点
var point = [5,5];
//调用contains方法
var result = Yuka.Polygon.contains(polygon, point);
//输出结果
console.log(result);  //true

注意事项

  • 多边形的坐标点必须按照顺时针或逆时针的方向排列,否则结果可能不正确;
  • 判断的多边形必须是凸多边形,否则结果可能不正确;
  • 若判断的多边形有重叠部分,则返回结果可能不确定。