Table of Contents

Class Vector3Extensions

Namespace
FishMMO.Shared
Assembly
FishMMO.Shared.dll

Extension methods for Vector3, providing randomization and geometric utilities for spheres and toroids.

public static class Vector3Extensions
Inheritance
Vector3Extensions
Inherited Members

Methods

GetNearestPointOnFlatToroid(Vector3, Vector3, float, float)

Gets the nearest point on a flat toroid (2D ring) from pointA, clamped to the toroid's bounds.

public static Vector3 GetNearestPointOnFlatToroid(Vector3 pointA, Vector3 pointB, float R, float radius)

Parameters

pointA Vector3

The point to project from.

pointB Vector3

The center of the toroid.

R float

Major radius.

radius float

Tube radius.

Returns

Vector3

The nearest point on the flat toroid.

GetNearestPositionOnSphere(Vector3, Vector3, float)

Gets the nearest position on the surface of a sphere centered at pointB, from pointA.

public static Vector3 GetNearestPositionOnSphere(Vector3 pointA, Vector3 pointB, float radius)

Parameters

pointA Vector3

The point to project from.

pointB Vector3

The center of the sphere.

radius float

The radius of the sphere.

Returns

Vector3

The nearest position on the sphere surface.

GetRandomConicalDirection(Vector3, float, DeterministicRNG)

A rotation looking along a direction drawn uniformly from inside a cone opening along forward.

public static Quaternion GetRandomConicalDirection(this Vector3 forward, float coneAngleDegrees, DeterministicRNG random)

Parameters

forward Vector3

Axis the cone opens along. A degenerate vector yields the identity rotation.

coneAngleDegrees float

TOTAL spread of the cone. Zero or less means no deviation; 360 or more is the whole sphere.

random DeterministicRNG

Deterministic generator. Required — a shared or per-process stream would desynchronise peers.

Returns

Quaternion

A rotation whose forward axis is the sampled direction.

Remarks

This used to read Quaternion.Euler(startPosition - ((distance * forward) + (RandomOnUnitSphere(random) * coneRadius))), which fed a WORLD POSITION into Euler(float, float, float) as if it were Euler angles in degrees. The result was a function of the object's absolute map coordinates rather than of its heading, the arc was applied as a sphere radius, and the same ability produced unrelated rotations at different places in the world. The start position and distance are gone because a direction does not depend on either.

Sampling is uniform over the spherical cap, not over the polar angle: drawing cos(theta) flat keeps the density even across the cap, where drawing theta flat would bunch results towards the axis. Every draw comes from random so two peers running the same ability with the same generator state produce the same direction.

GetRandomPointInFlatToroid(float, float)

Returns a random point inside a flat toroid (2D ring) with major radius R and tube radius.

public static Vector3 GetRandomPointInFlatToroid(float R, float radius)

Parameters

R float

Major radius (distance from center to tube center).

radius float

Tube radius.

Returns

Vector3

A random Vector3 inside the flat toroid (z = 0).

GetRandomPointInToroid(float, float)

Returns a random point inside a 3D toroid (donut shape) with major radius R and tube radius.

public static Vector3 GetRandomPointInToroid(float R, float radius)

Parameters

R float

Major radius (distance from center to tube center).

radius float

Tube radius.

Returns

Vector3

A random Vector3 inside the toroid.

RandomInBoundingBox(Vector3)

Returns a random position inside a bounding box centered at the origin.

public static Vector3 RandomInBoundingBox(Vector3 boundingBox)

Parameters

boundingBox Vector3

The size of the bounding box.

Returns

Vector3

A random Vector3 inside the bounding box.

RandomOnUnitSphere(DeterministicRNG)

Returns a random point on the surface of a unit sphere using a provided or new DeterministicRNG.

public static Vector3 RandomOnUnitSphere(DeterministicRNG random = null)

Parameters

random DeterministicRNG

Optional random number generator.

Returns

Vector3

A random Vector3 on the unit sphere.

RandomPositionWithinRadius(Vector3, float)

Returns a random position within a circle of given radius around a center point (on the XZ plane).

public static Vector3 RandomPositionWithinRadius(Vector3 center, float radius)

Parameters

center Vector3

The center position.

radius float

The radius of the circle.

Returns

Vector3

A random Vector3 position within the radius.