# Can somebody pls help me with project?

• 01-20-2013
achikha
Can somebody pls help me with project?
Hi, i'm a complete newbie in c , but unfortunately i've beed told to do a project for my classes and i completely don't know how to start it or programme it ... It goes like this: generate random set of n points in 2D carthesian coords system. then find ellipse enveloping all points which area is greatest. and the last is to prepare a graph in excel :P I hope someone could help me, greetings :)
• 01-20-2013
c99tutorial
To start you need to break it down, it sounds like three parts. 1. Generate n points. 2. Find the ellipse. 3. Plot in excel.

1. A point in 2D space is just two numbers (x,y). So if you want n points, generate 2n numbers. Use rand and srand.
2. To find the ellipse, it's best to review equations for representing ellipses and then find one that meets the stated criteria (to maximize the area?).
3. To plot in programs like Excel, you can normally output your information in tabular form and then just import it into the program.
• 01-21-2013
loserone+_+
what do u mean by ellipse?
• 01-21-2013
Quote:

Originally Posted by loserone+_+
what do u mean by ellipse?

An ellipse is an egg shape.

I don't know how you can have random numbers form the ellipse, however.

We need a more thorough description - an example would help, certainly.
• 01-21-2013
nonoob
An ellipse can certainly enclose a set of random points. The trick is to find one that minimally uses up area... But the question states "which area is greatest" - which makes less sense.
• 01-21-2013
achikha
Okay, i finished first step, i wonder if it's good :P anyways it's working ... about the area i personally think that it would be the best to find 2 points with the biggest distance and make them be the part of the ellipse and other points would be inside.. but i don't know if i'm not wrong. That's what i have for now.

Code:

```#include <stdio.h> #include <math.h> #include <stdlib.h> #include <time.h> void main() {         srand( (unsigned) time(NULL));         int x,y;         double x_min = -100;         double x_max = 100;         double y_min = -100;         double y_max = 100;         int i,n;         int lp=0;         printf("Input the number of points:\n");         scanf(" %ld",&n);         for(i = 0; i<n; i++)         {                 x = rand() * (x_max - x_min) / (double) RAND_MAX + x_min;                 y = rand() * (y_max - y_min) / (double) RAND_MAX + y_min;                 printf("\n(%ld;%ld)",x,y);         }         return x,y; }```
• 01-21-2013
nonoob
You’re on the right track.
The coordinates should be saved in some array too... so that the ellipse calculation has something to work with.

The ellipse may not be aligned horizontally or vertically but rather at some angle. Unless the problem domain restricts it. That's what makes it complicated to solve.
I just looked it up myself - and I highly doubt your teacher expects you to invent a new algorithm for this. Copying an existing solution would not teach you much either... so I wonder if your teacher knows exactly what they expect from the students.

Making a circle enclose all coordinates is difficult enough.