// draw elliptical orbit
void renderOrbit(int xSize, int ySize, double rotation){
int centerX = xDisplay / 2;
int centerY = yDisplay / 2;
// Calculate the number of points to plot
double increment = 2 * PI / displayPoints;
double t = 0;
// Iterate over each point on the ellipse outline
for (int i = 0; i < displayPoints; i++) {
// Calculate normalized coordinates (-1 to 1)
double normalizedX = (xSize / 2) * cos(t);
double normalizedY = (ySize / 2) * sin(t);
// Apply rotation
double angleInRadians = rotation * (PI / 180);
double rotatedX = normalizedX * cos(angleInRadians) - normalizedY * sin(angleInRadians);
double rotatedY = normalizedX * sin(angleInRadians) + normalizedY * cos(angleInRadians);
// Calculate pixel coordinates
uint8_t pixelX = centerX + round(rotatedX);
uint8_t pixelY = centerY + round(rotatedY);
currentOrbitX[i] = pixelX;
currentOrbitY[i] = pixelY;
currentOrbitX[2 * displayPoints + i] = pixelX;
currentOrbitY[2 * displayPoints + i] = pixelY+1;
currentOrbitX[3 * displayPoints + i] = pixelX+1;
currentOrbitY[3 * displayPoints + i] = pixelY;
currentOrbitX[4 * displayPoints + i] = pixelX+1;
currentOrbitY[4 * displayPoints + i] = pixelY+1;
// Plot the pixel on the display
tft.drawPixel(currentOrbitX[i], currentOrbitY[i], ST77XX_RED);
tft.drawPixel(currentOrbitX[2 * displayPoints + i], currentOrbitY[2 * displayPoints + i], ST77XX_RED);
tft.drawPixel(currentOrbitX[3 * displayPoints + i], currentOrbitY[3 * displayPoints + i], ST77XX_RED);
tft.drawPixel(currentOrbitX[4 * displayPoints + i], currentOrbitY[4 * displayPoints + i], ST77XX_RED);
// Update angle
t += increment;
}
}
// undraw elliptical orbit
void eraseOrbit(uint16_t* tableData){
// Iterate over each point on the ellipse outline
for (int i = 0; i < displayPoints; i++) {
// Plot the pixel on the display
uint16_t color1 = tableData[currentOrbitY[i] * xDisplay + currentOrbitX[i]]; // Get the value from the table
uint16_t color2 = tableData[currentOrbitY[2 * displayPoints + i] * xDisplay + currentOrbitX[2 * displayPoints + i]]; // Get the value from the table
uint16_t color3 = tableData[currentOrbitY[3 * displayPoints + i] * xDisplay + currentOrbitX[3 * displayPoints + i]]; // Get the value from the table
uint16_t color4 = tableData[currentOrbitY[4 * displayPoints + i] * xDisplay + currentOrbitX[4 * displayPoints + i]]; // Get the value from the table
// Set the pixel on the display with the calculated color
tft.drawPixel(currentOrbitX[i], currentOrbitY[i], color1);
tft.drawPixel(currentOrbitX[2 * displayPoints + i], currentOrbitY[2 * displayPoints + i], color2);
tft.drawPixel(currentOrbitX[3 * displayPoints + i], currentOrbitY[3 * displayPoints + i], color3);
tft.drawPixel(currentOrbitX[4 * displayPoints + i], currentOrbitY[4 * displayPoints + i], color4);
}
}