I have to find out n equi-spaced points on boundary of an ellipse when a (semimajor axis) and b (semiminor axis) are given. Starting point is considered as (a, 0). The formula given in code is used to find out such points.
#include <stdio.h>
#include <math.h>
#define PI 3.142
int main()
{
int n, i, a, b;
double dt, x[20], y[20];
printf("Enter semimajor axis:- ");
scanf("%d", &a);
printf("Enter semiminor axis:- ");
scanf("%d", &b);
printf("Enter no of points to be equi-spaced:- ");
scanf("%d", &n);
//Starting point is:- (a, 0). So x[0] = a and y[0] = 0
x[0] = a;
y[0] = 0;
dt = (2*PI)/n;
for (i=0; i<n; i++)
{
x[i+1] = x[i]*cos(dt) - (a/b)*y[i]*sin(dt);
y[i+1] = (b/a)*x[i]*sin(dt) + y[i]*cos(dt);
}
printf("\n");
for (i=0; i<n; i++)
{
printf("%lf, %lf\n", x[i], y[i]);
}
}
Input:- Enter semimajor axis:- 4\n Enter semiminor axis:- 3\n Enter no of points to be equi-spaced:- 4
Output:- 4.000000, 0.000000\n -0.000815, 0.000000\n 0.000000, -0.000000\n -0.000000, 0.000000
This is not expected output.