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

fromSpherical

Yuka.js库中的Vector3类的方法,用于从球面坐标系中的极角和方位角创建一个三维向量。

语法

Vector3.fromSpherical(radius, phi, theta);

参数

  • radius:球面坐标的半径,类型为number
  • phi:球面坐标的极角,也称为仰角,类型为number,以弧度为单位。
  • theta:球面坐标的方位角,也称为方位角,类型为number,以弧度为单位。

返回值

球面坐标系中指定半径、极角、方位角的三维向量。

示例

const radius = 10;
const phi = Math.PI / 4; // 仰角45度
const theta = Math.PI / 2; // 方位角90度
const vector = Vector3.fromSpherical(radius, phi, theta);

console.log(vector); // 输出 Vector3 { x: 0, y: 7.071067811865476, z: 7.071067811865476 }

备注

球面坐标系中,radius表示半径,phi表示仰角,取值范围为[0, π]theta表示方位角,取值范围为[0, 2π]。该方法将球面坐标系中的点表示为笛卡尔坐标系中的向量。