UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
CapsuleTypes.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#include "SegmentTypes.h"
8#include "BoxTypes.h"
9#include "OrientedBoxTypes.h"
10
11
12namespace UE
13{
14namespace Geometry
15{
16
17using namespace UE::Math;
18
19/*
20 * 3D Capsule stored as Line Segment and Radius
21 */
22template<typename T>
24{
25public:
29 T Radius = (T)0;
30
31 TCapsule3() = default;
32
35
36 TCapsule3(const TVector<T>& StartPoint, const TVector<T>& EndPoint, T RadiusIn)
37 : Segment(StartPoint, EndPoint), Radius(RadiusIn) {}
38
39
41 const TVector<T>& Center() const
42 {
43 return Segment.Center;
44 }
45
47 const TVector<T>& Direction() const
48 {
49 return Segment.Direction;
50 }
51
53 T Length() const
54 {
55 return (T)2 * Segment.Extent;
56 }
57
59 T Extent() const
60 {
61 return Segment.Extent;
62 }
63
65 T Volume() const
66 {
67 return Volume(Radius, Segment.Extent);
68 }
69
72 {
73 return Segment.GetBounds(Radius);
74 }
75
78 {
79 return TOrientedBox3<T>(
80 TFrame3<T>(Segment.Center, Segment.Direction),
82 }
83
85 bool Contains(const TVector<T>& Point) const
86 {
87 T DistSqr = Segment.DistanceSquared(Point);
88 return DistSqr <= Radius * Radius;
89 }
90
91
95 inline T DistanceSquared(const TVector<T>& Point) const
96 {
98 return PosDistance * PosDistance;
99 }
100
104 inline T SignedDistance(const TVector<T>& Point) const
105 {
106 T SqrDist = Segment.DistanceSquared(Point);
108 }
109
110 //
111 // Sphere utility functions
112 //
113
115 static T Volume(T Radius, T Extent)
116 {
118 return
119 (PiRadSqr * ((T)2 * Extent)) + // cylinder vol = (pi*r^2)*length
120 ((T)(4.0 / 3.0) * PiRadSqr * Radius);
121 }
122
123
124};
125
126
129
130
131} // end namespace UE::Geometry
132} // 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
static RealType Sqrt(const RealType Value)
Definition MathUtil.h:342
TCapsule3< float > FCapsule3f
Definition CapsuleTypes.h:127
TCapsule3< double > FCapsule3d
Definition CapsuleTypes.h:128
Definition Sphere.cpp:10
Definition AdvancedWidgetsModule.cpp:13
Definition BoxTypes.h:247
Definition CapsuleTypes.h:24
T Volume() const
Definition CapsuleTypes.h:65
T DistanceSquared(const TVector< T > &Point) const
Definition CapsuleTypes.h:95
T Extent() const
Definition CapsuleTypes.h:59
TAxisAlignedBox3< T > GetBounds() const
Definition CapsuleTypes.h:71
TOrientedBox3< T > GetOrientedBounds() const
Definition CapsuleTypes.h:77
TCapsule3(const TSegment3< T > &SegmentIn, T RadiusIn)
Definition CapsuleTypes.h:33
TSegment3< T > Segment
Definition CapsuleTypes.h:27
T Length() const
Definition CapsuleTypes.h:53
T Radius
Definition CapsuleTypes.h:29
T SignedDistance(const TVector< T > &Point) const
Definition CapsuleTypes.h:104
bool Contains(const TVector< T > &Point) const
Definition CapsuleTypes.h:85
TCapsule3(const TVector< T > &StartPoint, const TVector< T > &EndPoint, T RadiusIn)
Definition CapsuleTypes.h:36
const TVector< T > & Center() const
Definition CapsuleTypes.h:41
const TVector< T > & Direction() const
Definition CapsuleTypes.h:47
static T Volume(T Radius, T Extent)
Definition CapsuleTypes.h:115
Definition FrameTypes.h:27
Definition OrientedBoxTypes.h:25
Definition SegmentTypes.h:447
Definition Vector.h:51