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

intersectsPlane

该方法用于判断光线是否与平面相交。

语法

ray.intersectsPlane(plane, optionalTarget)

参数

  • planeTHREE.Plane 类型的平面对象,用于描述平面的法向量和离平面原点的距离。
  • optionalTarget:可选参数,用于指定交点的输出对象。

如果 optionalTarget 未被指定,则会创建一个新的 THREE.Vector3 向量对象用于存储交点,并返回该向量对象。

如果 optionalTarget 被指定,则不会创建新的向量对象,而是将交点的值存储在 optionalTarget 对象的属性中,并返回该对象。

返回值

如果光线与平面相交,则返回交点向量;否则返回 null

示例

const ray = new THREE.Ray(new THREE.Vector3(0, 0, 0), new THREE.Vector3(0, 0, 1));
const plane = new THREE.Plane(new THREE.Vector3(0, 0, 1), 0);
const intersection = new THREE.Vector3();

if (ray.intersectsPlane(plane, intersection) !== null) {
  console.log('光线与平面相交');
  console.log('交点坐标为:', intersection);
} else {
  console.log('光线与平面不相交');
}

注意事项

  • 如果 optionalTarget 参数未被指定,则会在每次调用该方法时创建新的向量对象,因此频繁调用该方法可能会导致性能问题。建议在调用该方法前预先定义一个向量对象,并将其作为 optionalTarget 参数传入,以避免重复创建对象。

参考链接