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

getNormalFromSurfacePoint

该方法用于获取BoundingSphere表面某一点的法向量。

语法

getNormalFromSurfacePoint(point, optionalTarget)

参数

  • pointVector3类型,表示表面上的某一点。
  • optionalTargetVector3类型,表示可选的输出目标向量,以避免在创建新对象时分配内存。

返回值

该方法返回一个Vector3类型,表示该点的法向量。

示例

const sphere = new THREE.Sphere(new THREE.Vector3(0, 0, 0), 1);
const surfacePoint = new THREE.Vector3(1, 0, 0);
const normal = sphere.getNormalFromSurfacePoint(surfacePoint);

console.log(normal);
// 输出为:THREE.Vector3(-1, 0, 0)

在上面的示例中,我们创建了一个半径为1的BoundingSphere,并在其表面上选取了一个坐标为(1, 0, 0)的点作为需要求法向量的点。调用getNormalFromSurfacePoint方法后,得到的结果为THREE.Vector3(-1, 0, 0),即该点处的法向量为沿着x轴反方向的一个向量。

实现细节

该方法的实现是基于以下公式:

normal = point - center
normal.normalize()

其中,point表示表面上的某一点,center表示BoundingSphere的圆心。将point减去center得到一个从BoundingSphere圆心指向该点的向量,该向量即为该点处的法向量,最后需要调用normalize方法将该向量归一化。

参考文献