mirror of
https://github.com/thestk/stk
synced 2026-01-15 14:01:52 +00:00
Version 4.1
This commit is contained in:
committed by
Stephen Sinclair
parent
81475b04c5
commit
2f09fcd019
104
src/Sphere.cpp
Normal file
104
src/Sphere.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
/***************************************************/
|
||||
/*! \class Sphere
|
||||
\brief STK sphere class.
|
||||
|
||||
This class implements a spherical ball with
|
||||
radius, mass, position, and velocity parameters.
|
||||
|
||||
by Perry R. Cook, 1995 - 2002.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
#include "Sphere.h"
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
Sphere::Sphere(double initRadius)
|
||||
{
|
||||
myRadius = initRadius;
|
||||
myMass = 1.0;
|
||||
myPosition = new Vector3D(0, 0, 0);
|
||||
myVelocity = new Vector3D(0, 0, 0);
|
||||
};
|
||||
|
||||
Sphere::~Sphere()
|
||||
{
|
||||
delete myPosition;
|
||||
delete myVelocity;
|
||||
}
|
||||
|
||||
void Sphere::setPosition(double anX, double aY, double aZ)
|
||||
{
|
||||
myPosition->setXYZ(anX, aY, aZ);
|
||||
};
|
||||
|
||||
void Sphere::setVelocity(double anX, double aY, double aZ)
|
||||
{
|
||||
myVelocity->setXYZ(anX, aY, aZ);
|
||||
};
|
||||
|
||||
void Sphere::setRadius(double aRadius)
|
||||
{
|
||||
myRadius = aRadius;
|
||||
};
|
||||
|
||||
void Sphere::setMass(double aMass)
|
||||
{
|
||||
myMass = aMass;
|
||||
};
|
||||
|
||||
Vector3D* Sphere::getPosition()
|
||||
{
|
||||
return myPosition;
|
||||
};
|
||||
|
||||
Vector3D* Sphere::getRelativePosition(Vector3D* aPosition)
|
||||
{
|
||||
workingVector.setXYZ(aPosition->getX() - myPosition->getX(),
|
||||
aPosition->getY() - myPosition->getY(),
|
||||
aPosition->getZ() - myPosition->getZ());
|
||||
return &workingVector;
|
||||
};
|
||||
|
||||
double Sphere::getVelocity(Vector3D* aVelocity)
|
||||
{
|
||||
aVelocity->setXYZ(myVelocity->getX(), myVelocity->getY(), myVelocity->getZ());
|
||||
return myVelocity->getLength();
|
||||
};
|
||||
|
||||
double Sphere::isInside(Vector3D *aPosition)
|
||||
{
|
||||
// Return directed distance from aPosition to spherical boundary ( <
|
||||
// 0 if inside).
|
||||
double distance;
|
||||
Vector3D *tempVector;
|
||||
|
||||
tempVector = this->getRelativePosition(aPosition);
|
||||
distance = tempVector->getLength();
|
||||
return distance - myRadius;
|
||||
};
|
||||
|
||||
double Sphere::getRadius()
|
||||
{
|
||||
return myRadius;
|
||||
};
|
||||
|
||||
double Sphere::getMass()
|
||||
{
|
||||
return myMass;
|
||||
};
|
||||
|
||||
void Sphere::addVelocity(double anX, double aY, double aZ)
|
||||
{
|
||||
myVelocity->setX(myVelocity->getX() + anX);
|
||||
myVelocity->setY(myVelocity->getY() + aY);
|
||||
myVelocity->setZ(myVelocity->getZ() + aZ);
|
||||
}
|
||||
|
||||
void Sphere::tick(double timeIncrement)
|
||||
{
|
||||
myPosition->setX(myPosition->getX() + (timeIncrement * myVelocity->getX()));
|
||||
myPosition->setY(myPosition->getY() + (timeIncrement * myVelocity->getY()));
|
||||
myPosition->setZ(myPosition->getZ() + (timeIncrement * myVelocity->getZ()));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user