UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SphereTypes.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Math/UnrealMath.h"
6#include "VectorTypes.h"
7
8namespace UE
9{
10namespace Geometry
11{
12
13using namespace UE::Math;
14
15/*
16 * 3D Sphere stored as Center point and Radius
17 */
18template<typename T>
20{
21public:
25 T Radius = (T)0;
26
27 TSphere3() = default;
28
31
33 T Diameter() const
34 {
35 return (T)2 * Radius;
36 }
37
39 T Circumference() const
40 {
41 return (T)2 * TMathUtil<T>::Pi * Radius;
42 }
43
45 T Area() const
46 {
47 return Area(Radius);
48 }
49
51 T Volume() const
52 {
53 return Volume(Radius);
54 }
55
57 bool Contains(const TVector<T>& Point) const
58 {
60 return DistSqr <= Radius * Radius;
61 }
62
64 bool Contains(const TSphere3<T>& OtherSphere) const
65 {
67 return (CenterDist + OtherSphere.Radius) <= Radius;
68 }
69
70
74 inline T DistanceSquared(const TVector<T>& Point) const
75 {
77 return PosDistance * PosDistance;
78 }
79
83 inline T SignedDistance(const TVector<T>& Point) const
84 {
86 }
87
88
89 //
90 // Sphere utility functions
91 //
92
94 static T Area(T Radius)
95 {
96 return (T)(4) * TMathUtil<T>::Pi * Radius * Radius;
97 }
98
100 static T Volume(T Radius)
101 {
102 return (T)(4.0 / 3.0) * TMathUtil<T>::Pi * Radius * Radius * Radius;
103 }
104};
105
106
109
110} // end namespace UE::Geometry
111} // end namespace UE
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition MathUtil.h:150
static RealType Max(const RealType A, const RealType B)
Definition MathUtil.h:246
T Distance(const UE::Math::TVector2< T > &V1, const UE::Math::TVector2< T > &V2)
Definition VectorTypes.h:74
T DistanceSquared(const UE::Math::TVector2< T > &V1, const UE::Math::TVector2< T > &V2)
Definition VectorTypes.h:82
TSphere3< double > FSphere3d
Definition SphereTypes.h:108
TSphere3< float > FSphere3f
Definition SphereTypes.h:107
Definition Sphere.cpp:10
Definition AdvancedWidgetsModule.cpp:13
Definition SphereTypes.h:20
T Diameter() const
Definition SphereTypes.h:33
TVector< T > Center
Definition SphereTypes.h:23
static T Volume(T Radius)
Definition SphereTypes.h:100
T SignedDistance(const TVector< T > &Point) const
Definition SphereTypes.h:83
T Circumference() const
Definition SphereTypes.h:39
T Area() const
Definition SphereTypes.h:45
bool Contains(const TSphere3< T > &OtherSphere) const
Definition SphereTypes.h:64
TSphere3(const TVector< T > &CenterIn, T RadiusIn)
Definition SphereTypes.h:29
T Radius
Definition SphereTypes.h:25
T DistanceSquared(const TVector< T > &Point) const
Definition SphereTypes.h:74
T Volume() const
Definition SphereTypes.h:51
bool Contains(const TVector< T > &Point) const
Definition SphereTypes.h:57
static T Area(T Radius)
Definition SphereTypes.h:94
Definition Vector.h:51
static TVector< T > Zero()
Definition Vector.h:112