I have a c++ program that creates a list of offsets that correspond to traversing around an ellipse. I need to vary the velocity so that more time (i.e. more of the produced offsets) are near the far ends of the oval. The oval is long and skinny, and the current way I am calculating the offsets results in more offsets near the center of the ellipse, which is the opposite of what i want.
code:
// breathingPeriod, intervalMS, and yRadius are variables.
// Good defaults are: breathingPeriod = 5, intervalMs = 10, yRadius = 20
const int points = breathingPeriod * 1000 / intervalMS;
const double velocityCoeff = 360 / (breathingPeriod * 1000);
const zRadius = 3;
std::ofstream out("output.txt");
for(int i = 0; i < points; ++i)
{
const int age = intervalMS * i;
const uint64_t thetaDeg = static_cast<uint64_t>(age * velocityCoeff) % 360;
const double thetaRad = thetaDeg * M_PI / 180.0;
const double tanTheta = tan(thetaRad);
double zOffset= (yRadius* zRadius) / sqrt(pow(yRadius, 2) + pow(zRadius, 2) * pow(tanTheta, 2));
if(thetaRad > M_PI_2 && thetaRad <= 3 * M_PI_2)
{
zOffset = -zOffset;
}
const double yOffset = zOffset * tanTheta;
double xOffset = 0;
std::string str;
str += std::to_string(xOffset) + " " + std::to_string(yOffset) + " " + std::to_string(zOffset) + "\n";
out << str;
}
out.close;
I have tried varying the velocity based on cos of the previous angle, but i have yet to get that to work successfully.
While the movement is similar to an orbit, It doesn't need to follow most of the rules orbits do. Also, the input parameters are completely different from a normal orbital mechanics equation, and the objective is to create offsets for a single object over time, rather than to figure out the position of a large number of objects given an observer position and a database of stellar coordinates.