Cylinder3.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: Cylinder3.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 3-D cylinder geometry.
6 > Created Time: 2017/06/24
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_CYLINDER3_H
10 #define CUBBYFLOW_CYLINDER3_H
11 
12 #include <Core/Surface/Surface3.h>
13 
14 namespace CubbyFlow
15 {
22  class Cylinder3 final : public Surface3
23  {
24  public:
25  class Builder;
26 
29 
31  double radius = 1.0;
32 
34  double height = 1.0;
35 
37  Cylinder3(const Transform3& transform = Transform3(), bool isNormalFlipped = false);
38 
40  Cylinder3(const Vector3D& center, double radius, double height,
41  const Transform3& transform = Transform3(), bool isNormalFlipped = false);
42 
44  Cylinder3(const Cylinder3& other);
45 
47  static Builder GetBuilder();
48 
49  protected:
50  // Surface3 implementations
51 
52  Vector3D ClosestPointLocal(const Vector3D& otherPoint) const override;
53 
54  double ClosestDistanceLocal(const Vector3D& otherPoint) const override;
55 
56  bool IntersectsLocal(const Ray3D& ray) const override;
57 
58  BoundingBox3D BoundingBoxLocal() const override;
59 
60  Vector3D ClosestNormalLocal(const Vector3D& otherPoint) const override;
61 
62  SurfaceRayIntersection3 ClosestIntersectionLocal(const Ray3D& ray) const override;
63  };
64 
66  using Cylinder3Ptr = std::shared_ptr<Cylinder3>;
67 
71  class Cylinder3::Builder final : public SurfaceBuilderBase3<Cylinder3::Builder>
72  {
73  public:
76 
78  Builder& WithRadius(double radius);
79 
81  Builder& WithHeight(double height);
82 
84  Cylinder3 Build() const;
85 
87  Cylinder3Ptr MakeShared() const;
88 
89  private:
90  Vector3D m_center{ 0, 0, 0 };
91  double m_radius = 1.0;
92  double m_height = 1.0;
93  };
94 }
95 
96 #endif
Cylinder3 Build() const
Builds Cylinder3.
3-D vector class.
Definition: Vector3.h:26
static Builder GetBuilder()
Returns builder fox Cylinder3.
bool IntersectsLocal(const Ray3D &ray) const override
double height
Height of the cylinder.
Definition: Cylinder3.h:34
double radius
Radius of the cylinder.
Definition: Cylinder3.h:31
Builder & WithRadius(double radius)
Returns builder with radius.
Vector3D ClosestNormalLocal(const Vector3D &otherPoint) const override
3-D cylinder geometry.
Definition: Cylinder3.h:22
double ClosestDistanceLocal(const Vector3D &otherPoint) const override
Builder & WithHeight(double height)
Returns builder with height.
Structure that represents ray-surface intersection point.
Definition: Surface3.h:23
Base class for 3-D surface builder.
Definition: Surface3.h:106
Definition: pybind11Utils.h:24
SurfaceRayIntersection3 ClosestIntersectionLocal(const Ray3D &ray) const override
Returns the closest intersection point for given ray in local frame.
Cylinder3(const Transform3 &transform=Transform3(), bool isNormalFlipped=false)
Constructs a cylinder with.
Abstract base class for 3-D surface.
Definition: Surface3.h:32
Transform3 transform
Local-to-world transform.
Definition: Surface3.h:36
3-D axis-aligned bounding box class.
Definition: BoundingBox3.h:44
Cylinder3Ptr MakeShared() const
Builds shared pointer of Cylinder3 instance.
Represents 3-D rigid body transform.
Definition: Transform3.h:22
Vector3D center
Center of the cylinder.
Definition: Cylinder3.h:25
bool isNormalFlipped
Flips normal when calling Surface3::closestNormal(...).
Definition: Surface3.h:39
Front-end to create Cylinder3 objects step by step.
Definition: Cylinder3.h:71
Vector3D ClosestPointLocal(const Vector3D &otherPoint) const override
BoundingBox3D BoundingBoxLocal() const override
Returns the bounding box of this surface object in local frame.
Class for 3-D ray.
Definition: Ray3.h:23
Builder & WithCenter(const Vector3D &center)
Returns builder with center.
std::shared_ptr< Cylinder3 > Cylinder3Ptr
Shared pointer type for the Cylinder3.
Definition: Cylinder3.h:66