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

computeDegreeOfMembership

简介

computeDegreeOfMembership是属于Yuka js库中的RightShoulderFuzzySet类的一个函数。该函数用于计算一个输入值在该右肩形状的模糊集合中的隶属度。

参数

  • value:Number类型。待计算隶属度的输入值。

返回值

Number类型的计算结果,表示该输入值在该右肩形状的模糊集合中的隶属度。

示例

const fuzzySet = new Yuka.RightShoulderFuzzySet(30, 40, 50);
const degree = fuzzySet.computeDegreeOfMembership(35); // 0.5

源码

computeDegreeOfMembership(value) {
  if (value >= this.rightOffset && value <= this.peakPoint) {
    return 1;
  }

  if (value < this.rightOffset) {
    return 0;
  }

  const grad = 1 / (this.peakPoint - this.rightOffset);
  return grad * (value - this.rightOffset);
}

计算过程

在右肩形状的模糊集合中,有两个关键点:右侧的偏移点(rightOffset)和隶属度峰值的位置(peakPoint)。该函数的计算过程如下:

  1. 如果输入值在偏移点和峰值之间,则将其隶属度设置为1;
  2. 如果输入值小于偏移点,则将其隶属度设置为0;
  3. 如果输入值大于偏移点且小于峰值,则通过斜率计算其隶属度。其中斜率等于1除以峰值与偏移点之间的距离。计算公式为 grad * (value - this.rightOffset)

参考资料

Yuka js官方文档 - RightShoulderFuzzySet.computeDegreeOfMembership()