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

area

area() 是Yuka js库中MathUtils对象提供的一个函数,用于计算二维图形的面积。该函数接受两个参数,分别为图形的宽度和高度,返回值为计算出的面积。下面是该函数的语法示例:

MathUtils.area(width, height);

参数

  • width:表示图形的宽度,必须是大于零的数字。
  • height:表示图形的高度,必须是大于零的数字。

返回值

  • 返回一个以“像素平方”为单位的数字值,表示计算出的图形面积。

使用示例

以下代码是用于计算长方形面积的示例:

let width = 10;
let height = 5;

let area = MathUtils.area(width, height);

console.log(`长方形的面积为${area}像素平方。`);

输出结果为:

长方形的面积为50像素平方。

注意事项

  • 该函数只接受两个参数,如果参数个数不对会抛出异常。

  • 函数传入的参数必须是大于零的数字,否则无法进行计算。

  • 函数返回的面积值只适用于二维平面上的图形,不能用于计算三维物体的表面积。