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

intersectConvexHull

起点的Yuka js库中的函数,用于计算光线与凸包之间的相交情况。

语法

intersectConvexHull( ray, points )

参数

  • ray - THREE.Ray | THREE.Raycaster,射线对象。
  • points - Array<THREE.Vector3>,表示凸包的点集。

返回值

返回 null,表示光线与凸包没有任何交点。如果相交了,返回一个具有以下属性的对象:

  • point - THREE.Vector3,相交点的位置。
  • distance - Number,相交点到光线原点的距离。

示例

import { intersectConvexHull } from 'yuka';

const convexHull = new THREE.ConvexGeometry( [
    new THREE.Vector3( -50, 50, 0 ),
    new THREE.Vector3( -50, -50, -50 ),
    new THREE.Vector3( 50, 50, 0 ),
    new THREE.Vector3( 50, -50, -50 )
  ] );

const raycaster = new THREE.Raycaster();
let intersection = intersectConvexHull( raycaster.ray, convexHull.vertices );

if ( intersection ) {

    console.log( 'Intersection point:', intersection.point );
    console.log( 'Distance to the intersection point:', intersection.distance );

} else {

    console.log( 'No intersection.' );

}

参考文献

  • Yuka - A JavaScript library for developing 3D games and simulations, https://github.com/metalx1000/Yuka.