-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace PolyZone.Shapes.Interfaces; | ||
|
||
/// <summary> | ||
/// A 3d spherical shape | ||
/// </summary> | ||
public interface ISphere : ISpatial3dShape; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using CitizenFX.Core; | ||
using PolyZone.Shapes.Interfaces; | ||
|
||
namespace PolyZone.Shapes; | ||
|
||
/// <summary> | ||
/// A 3d sphere constructed from a center 3d point and a radius | ||
/// </summary> | ||
/// <param name="center">Center of the sphere</param> | ||
/// <param name="radius">Radius of the sphere</param> | ||
public class Sphere(in Vector3 center, float radius) : ISphere | ||
{ | ||
public Vector3 Center { get; } = center; | ||
public float Radius { get; } = radius; | ||
|
||
/// <inheritdoc cref="ISpatial3dShape.Contains"/> | ||
public bool Contains(in Vector3 point) | ||
{ | ||
// Calculate the distance from the center of the sphere to the given point | ||
var distance = (float) Math.Sqrt(Math.Pow(point.X - Center.X, 2) + Math.Pow(point.Y - Center.Y, 2) + Math.Pow(point.Z - Center.Z, 2)); | ||
|
||
// Check if the distance is less than or equal to the radius | ||
return distance <= Radius; | ||
|
||
} | ||
} |