X = radius * cos(time);
Y = constant;
Z = radius * sin(time);
And then remember to increment time after each iteration. Is that what you're after?
{
// Lorenz integration parameters
double dt = 0.003;
double s = -1.7;
double b = 2.66;
double r = 50;
// Old vectors
double D,Nx,Ny,Nz;
double Dx0 = Dx;
double Dy0 = Dy;
double Dz0 = Dz;
double Ux0 = Ux;
double Uy0 = Uy;
double Uz0 = Uz;
// Fix degenerate case
if (X==0 && Y==0 && Z==0) Y = Z = 40;
// Update position
Dx = s*(Y-X);
Dy = X*(r-Z)-Y;
Dz = X*Y - b*Z;
X += dt*Dx;
Y += dt*Dy;
Z += dt*Dz;
// Normalize DX
D = sqrt(Dx*Dx+Dy*Dy+Dz*Dz);
Dx /= D;
Dy /= D;
Dz /= D;
// Calculate sideways
Sx = Dy0*Dz-Dz0*Dy;
Sy = Dz0*Dx-Dx0*Dz;
Sz = Dx0*Dy-Dy0*Dx;
// Calculate Up
Ux = Dz*Sy - Dy*Sz;
Uy = Dx*Sz - Dz*Sx;
Uz = Dy*Sx - Dx*Sy;
// Normalize Up
D = sqrt(Ux*Ux+Uy*Uy+Uz*Uz);
Ux /= D;
Uy /= D;
Uz /= D;
// Eye and lookat position
Ex = X-7*Dx;
Ey = Y-7*Dy;
Ez = Z-7*Dz;
Ox = X;
Oy = Y;
Oz = Z;
// Next DX
Nx = s*(Y-X);
Ny = X*(r-Z)-Y;
Nz = X*Y - b*Z;
// Pitch angle
pitch = 180*acos(Dx*Dx0+Dy*Dy0+Dz*Dz0);
// Roll angle
D = (Ux*Ux0+Uy*Uy0+Uz*Uz0) / (Dx*Dx0+Dy*Dy0+Dz*Dz0);
if (D>1) D = 1;
roll = (Nx*Sx+Ny*Sy+Nz*Sz>0?+1:-1)*960*acos(D);
// Yaw angle
yaw = 0;
// Power setting (0-1)
if (Dy>0.8)
pwr = 100;
else if (Dy>-0.2)
pwr = 20+100*Dy;
else
pwr = 0;
}
if (fly)
{
// Lorenz integration parameters
double dt = 0.003;
// Old vectors
double D,Nx,Ny,Nz;
double Dx0 = Dx;
double Dy0 = Dy;
double Dz0 = Dz;
double Ux0 = Ux;
double Uy0 = Uy;
double Uz0 = Uz;
// Fix degenerate case
if (X==0 && Y==0 && Z==0) Y = Z = 40;
// Update position
Dx = -sin(B52_direction);
Dy = 20;
Dz = cos(B52_direction);
X += dt*Dx;
Y += 0;
Z += dt*Dz;
// Normalize DX
D = sqrt(Dx*Dx+Dy*Dy+Dz*Dz);
Dx /= D;
Dy /= D;
Dz /= D;
// Calculate sideways
Sx = Dy0*Dz-Dz0*Dy;
Sy = Dz0*Dx-Dx0*Dz;
Sz = Dx0*Dy-Dy0*Dx;
// Calculate Up
Ux = Dz*Sy - Dy*Sz;
Uy = Dx*Sz - Dz*Sx;
Uz = Dy*Sx - Dx*Sy;
// Normalize Up
D = sqrt(Ux*Ux+Uy*Uy+Uz*Uz);
Ux /= D;
Uy /= D;
Uz /= D;
// Eye and lookat position
Ex = X-7*Dx;
Ey = Y-7*Dy;
Ez = Z-7*Dz;
Ox = X;
Oy = Y;
Oz = Z;
// Next DX
Nx = -sin(B52_direction);
Ny = 20;
Nz = cos(B52_direction);
// Pitch angle
pitch = 180*acos(Dx*Dx0+Dy*Dy0+Dz*Dz0);
// Roll angle
D = (Ux*Ux0+Uy*Uy0+Uz*Uz0) / (Dx*Dx0+Dy*Dy0+Dz*Dz0);
if (D>1) D = 1;
roll = (Nx*Sx+Ny*Sy+Nz*Sz>0?+1:-1)*960*acos(D);
// Yaw angle
yaw = 0;
// Power setting (0-1)
if (Dy>0.8)
pwr = 100;
else if (Dy>-0.2)
pwr = 20+100*Dy;
else
pwr = 0;
}
// Static Roll/Pitch/Yaw
else
{
Ex = -2*dim*Sin(th)*Cos(ph);
Ey = +2*dim *Sin(ph);
Ez = +2*dim*Cos(th)*Cos(ph);
Ox = Oy = Oz = 0;
X = Z = 0;
Y = 20;
Dx = 1; Dy = 0; Dz = 0;
Ux = 0; Uy = 1; Uz = 0;
}
if (fly)
{
// Lorenz integration parameters
double dt = 0.003;
// Old vectors
double D,Nx,Ny,Nz;
double Dx0 = Dx;
double Dy0 = Dy;
double Dz0 = Dz;
double Ux0 = Ux;
double Uy0 = Uy;
double Uz0 = Uz;
// Fix degenerate case
if (X==0 && Y==0 && Z==0) Y = Z = 40;
// Update position
Dx = -sin(B52_direction);
Dy = 20;
Dz = cos(B52_direction);
X += dt*Dx;
Y += 0;
Z += dt*Dz;
// Normalize DX
D = sqrt(Dx*Dx+Dy*Dy+Dz*Dz);
Dx /= D;
Dy /= D;
Dz /= D;
// Calculate sideways
Sx = Dy0*Dz-Dz0*Dy;
Sy = Dz0*Dx-Dx0*Dz;
Sz = Dx0*Dy-Dy0*Dx;
// Calculate Up
Ux = Dz*Sy - Dy*Sz;
Uy = Dx*Sz - Dz*Sx;
Uz = Dy*Sx - Dx*Sy;
// Normalize Up
D = sqrt(Ux*Ux+Uy*Uy+Uz*Uz);
Ux /= D;
Uy /= D;
Uz /= D;
// Eye and lookat position
Ex = X-7*Dx;
Ey = Y-7*Dy;
Ez = Z-7*Dz;
Ox = X;
Oy = Y;
Oz = Z;
// Next DX
Nx = -sin(B52_direction);
Ny = 20;
Nz = cos(B52_direction);
// Pitch angle
pitch = 180*acos(Dx*Dx0+Dy*Dy0+Dz*Dz0);
// Roll angle
D = (Ux*Ux0+Uy*Uy0+Uz*Uz0) / (Dx*Dx0+Dy*Dy0+Dz*Dz0);
if (D>1) D = 1;
roll = 0;
// Yaw angle
yaw = 0;
// Power setting (0-1)
if (Dy>0.8)
pwr = 100;
else if (Dy>-0.2)
pwr = 20+100*Dy;
else
pwr = 0;
}
// Static Roll/Pitch/Yaw
else
{
Ex = -2*dim*Sin(th)*Cos(ph);
Ey = +2*dim *Sin(ph);
Ez = +2*dim*Cos(th)*Cos(ph);
Ox = Oy = Oz = 0;
X = Z = 0;
Y = 20;
Dx = 1; Dy = 0; Dz = 0;
Ux = 0; Uy = 1; Uz = 0;
}
Title | # Comments | Views | Activity |
---|---|---|---|
copyEndy challenge | 15 | 58 | |
Logarithms | 2 | 52 | |
Coordinate Geometry-Finding ratio of a point splitting a line | 4 | 43 | |
Volatile formula's, speeding up calculations and match first and last name in separate columns to return value from a third. | 6 | 51 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
20 Experts available now in Live!