Question
please provide explanation in comments in the program. explaining what exactly is happening and where. C or C++ Generate by random a set of n
please provide explanation in comments in the program. explaining what exactly is happening and where. C or C++ Generate by random a set of n points in 2D Cartesian Coordinates System. Find two different pentagons enveloping all of the points and connected to the set (there is at least one point on each side). Check which pentagons has a smaller area. Use functions for reading, printing appropriate data. Use local variables. Prepare an appropriate graph in Excel.
At first, you create some space (lets say, 300x300 square). Then inside of this space you generate some random points (that belong to the space). Later, you place a pentagon on the space in such a way, that all the points are inside and some of them touch the borders of the pentagon. You place 2 pentagons here and check which is smaller
similar program for reference
#include
int ReadN ();
void bounding (double** Cord , double ang , int n , double* top , double* bot , double* left ,double* right , double* area , int z); void Print_ver_area (double* Area , FILE* f); void Print_points( int n , double** Cord , FILE* f ); void Print_Rect ( double angR , int n , double y_max , double y_min , double x_min ,double x_max, int z , FILE* f);
int main() {
int n= ReadN();
FILE* f;
f=fopen("project_print_data.dat","wt");
//printf("%d ", n);
double **Cord = (double**)malloc (n*sizeof(double*)); //allocation of memory
for (int h=0; h srand ((unsigned) time (NULL)); for (int i =0 ; i for (int h=0; h<2 ; ++h) { Cord[i][h]= (((rand())/ (double)RAND_MAX)*2000.)-1000.; } } Print_points(n , Cord , f); printf(" "); double x_max , x_min , y_max, y_min; double Area[2]; Area[0]=1.; Area[1]=1.; for(int z=0 ; z<2 ; ++z) { int angle= rand()% 361; // printf("angle : %d ", angle); double angR = (angle/180.)*PI; bounding (Cord , angR , n , &y_max , &y_min , &x_min , &x_max , Area, z); printf("Rectangle nr:%d ", z+1 ); printf("%lf , %lf ", (x_min*cos(-(angR))-y_max*sin(-(angR)) ), (x_min*sin(-(angR))+y_max*cos(-(angR)) )); printf("%lf , %lf ", (x_min*cos(-(angR))-y_min*sin(-(angR)) ), (x_min*sin(-(angR))+y_min*cos(-(angR)) )); printf("%lf , %lf ", (x_max*cos(-(angR))-y_max*sin(-(angR)) ) , (x_max*sin(-(angR))+y_max*cos(-(angR)) )); printf("%lf , %lf ", (x_max*cos(-(angR))-y_min*sin(-(angR)) ) , (x_max*sin(-(angR))+y_min*cos(-(angR)) )); printf("Area %d: %lf ", z+1 , (x_max-x_min)*(y_max-y_min) ); Print_Rect ( angR , n , y_max , y_min , x_min , x_max , z , f); } Print_ver_area ( Area , f ); fclose(f); for (int z=0; z free(Cord[z]); } free(Cord); } int ReadN () { int n; printf("Input n:"); scanf("%d", &n); printf(" "); return n; } void bounding (double** Cord , double ang , int n , double* top , double* bot , double* left ,double* right , double* area , int z) { *top=((Cord[0][0])* sin(ang)) + (Cord [0][1]* cos(ang)); *bot=((Cord[0][0])* sin(ang)) + (Cord [0][1]* cos(ang)); *left=((Cord[0][0])* cos(ang)) - (Cord [0][1]* sin(ang)); *right=((Cord[0][0])* cos(ang)) - (Cord [0][1]* sin(ang)); for( int i=0 ; i if( (((Cord[i][0]) * cos(ang)) - (Cord [i][1] * sin(ang))) > *right) *right=((Cord[i][0])* cos(ang)) - (Cord [i][1]* sin(ang)); if( (((Cord[i][0])* sin(ang)) + (Cord [i][1]* cos(ang))) > *top) *top=((Cord[i][0])* sin(ang)) + (Cord [i][1]* cos(ang)); if( (((Cord[i][0])* sin(ang)) + (Cord [i][1]* cos(ang))) < *bot) *bot=((Cord[i][0])* sin(ang)) + (Cord [i][1]* cos(ang)); if( (((Cord[i][0])* cos(ang)) - (Cord [i][1]* sin(ang)) )< *left) *left=((Cord[i][0])* cos(ang)) - (Cord [i][1]* sin(ang)); } area [z]=(*top-*bot)*(*right-*left); } void Print_points( int n , double** Cord , FILE* f) { for (int i =0 ; i printf("%lf , %lf ", Cord[i][0], Cord[i][1] ); fprintf( f ,"%lf \t %lf ", Cord[i][0], Cord[i][1] ); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started