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

intersectsBoundingSphere

intersectsBoundingSphere是Yuka js库中的一种函数,用于检测光线是否与包围球相交。

语法

intersectsBoundingSphere(ray, sphere, target)

参数

  • ray: 需要检测的光线,是一个Ray对象。
  • sphere: 需要检测的包围球,是一个Sphere对象。
  • target: 可选参数,返回结果的向量。如果没有传递该参数,则会创建一个新的向量。

返回值

  • 如果光线与包围球相交,则返回相交点的向量。
  • 如果光线与包围球不相交,则返回一个无穷大的向量表示不相交。

示例

import { Ray, Sphere } from 'yuka';

const ray = new Ray( new Vector3( 0, 0, 0 ), new Vector3( 0, 1, 0 ) );
const sphere = new Sphere( new Vector3( 0, 2, 0 ), 1 );

const intersection = new Vector3();
const result = intersectsBoundingSphere( ray, sphere, intersection );
if ( result !== Infinity ) {
  console.log( `Intersection found at [${intersection.x}, ${intersection.y}, ${intersection.z}].` );
} else {
  console.log( "No intersection found." );
}

异常

  • 该函数不会抛出异常。