1 #ifndef STK_SPHERE_H
2 #define STK_SPHERE_H
3
4 #include "Stk.h"
5 #include "Vector3D.h"
6
7 namespace stk {
8
9 /***************************************************/
10 /*! \class Sphere
11 \brief STK sphere class.
12
13 This class implements a spherical ball with
14 radius, mass, position, and velocity parameters.
15
16 by Perry R. Cook, 1995--2021.
17 */
18 /***************************************************/
19
20 class Sphere : public Stk
21 {
22 public:
23 //! Constructor taking an initial radius value.
24 Sphere( StkFloat radius = 1.0 ) { radius_ = radius; mass_ = 1.0; };
25
26 //! Set the 3D center position of the sphere.
setPosition(StkFloat x,StkFloat y,StkFloat z)27 void setPosition( StkFloat x, StkFloat y, StkFloat z ) { position_.setXYZ(x, y, z); };
28
29 //! Set the 3D velocity of the sphere.
setVelocity(StkFloat x,StkFloat y,StkFloat z)30 void setVelocity( StkFloat x, StkFloat y, StkFloat z ) { velocity_.setXYZ(x, y, z); };
31
32 //! Set the radius of the sphere.
setRadius(StkFloat radius)33 void setRadius( StkFloat radius ) { radius_ = radius; };
34
35 //! Set the mass of the sphere.
setMass(StkFloat mass)36 void setMass( StkFloat mass ) { mass_ = mass; };
37
38 //! Get the current position of the sphere as a 3D vector.
getPosition(void)39 Vector3D* getPosition( void ) { return &position_; };
40
41 //! Get the relative position of the given point to the sphere as a 3D vector.
42 Vector3D* getRelativePosition( Vector3D *position );
43
44 //! Set the velocity of the sphere as a 3D vector.
45 StkFloat getVelocity( Vector3D* velocity );
46
47 //! Returns the distance from the sphere boundary to the given position (< 0 if inside).
48 StkFloat isInside( Vector3D *position );
49
50 //! Get the current sphere radius.
getRadius(void)51 StkFloat getRadius( void ) { return radius_; };
52
53 //! Get the current sphere mass.
getMass(void)54 StkFloat getMass( void ) { return mass_; };
55
56 //! Increase the current sphere velocity by the given 3D components.
57 void addVelocity( StkFloat x, StkFloat y, StkFloat z );
58
59 //! Move the sphere for the given time increment.
60 void tick( StkFloat timeIncrement );
61
62 private:
63 Vector3D position_;
64 Vector3D velocity_;
65 Vector3D workingVector_;
66 StkFloat radius_;
67 StkFloat mass_;
68 };
69
tick(StkFloat timeIncrement)70 inline void Sphere::tick( StkFloat timeIncrement )
71 {
72 position_.setX(position_.getX() + (timeIncrement * velocity_.getX()));
73 position_.setY(position_.getY() + (timeIncrement * velocity_.getY()));
74 position_.setZ(position_.getZ() + (timeIncrement * velocity_.getZ()));
75 };
76
77 } // stk namespace
78
79 #endif
80