Implement Sphere::RandomPointOnSurface() RandomPointInside()

This commit is contained in:
2024-05-31 15:19:21 -04:00
parent e5baef35d0
commit e0ba266444
2 changed files with 65 additions and 0 deletions

View File

@@ -24,6 +24,28 @@ namespace J3ML::Geometry
Sphere() {}
Sphere(const Vector3& pos, float radius) : Position(pos), Radius(radius) {}
/// Generates a random point on the surface of this sphere
/** The points are distributed uniformly.
This function uses the rejection method to generate a uniform distribution of points on the surface.
Therefore, it is assumed that this sphere is not degenerate, i.e. it has a positive radius.
A fixed number of 1000 tries is performed, after which a fixed point on the surface is returned as a fallback.
@param rng A pre-seeded random number generator object that is to be used by this function to generate random vlaues.
@see class RNG, RandomPointInside(), IsDegenerate()
@todo Add Sphere::PointOnSurface(polarYaw, polarPitch). */
Vector3 RandomPointOnSurface(RNG& rng) const;
static Vector3 RandomPointOnSurface(RNG& rng, const Vector3& center, float radius);
/// Generates a random point inside this sphere.
/** The points are distributed uniformly.
This function uses the rejection method to generate a uniform distribution of points inside a sphere.
Therefore, it is assumed that this sphere is not degenerate, i.e. it has a positive radius.
A fixed number of 1000 tries is performed, after which the sphere center position is returned as a fallback.
@param rng A pre-seeded random number generator object that is to be used by this function to generate random values.
@see class RNG, RandomPointOnSurface(), IsDegenerate().
@todo Add Sphere::Point(polarYaw, polarPitch, radius). */
Vector3 RandomPointInside(RNG& rng);
static Vector3 RandomPointInside(RNG& rng, const Vector3& center, float radius);
public:
/// Quickly returns an arbitrary point inside this Sphere. Used in GJK intersection test.
Vector3 AnyPointFast() const { return Position; }
/// Computes the extreme point of this Sphere in the given direction.