Files
learning/c/isp-ws25/weeklies/week02/w02ex01.c

59 lines
1.9 KiB
C
Executable File

/* Bounding Box 2D
- = rectangle that completely encloses the circle (whole circle lies within the rectangle or on its boundary)
- bounding box must be smallest possible rectangle that encloses the circle (square)
[x] ask for x of the center of the circle
[x] ask for y of the center of the circle
[x] ask for radius of the circle
[x] calculate 2D bounding box for given circle
[x] print coordinates of 4 corners
[x] print coordinates with 2 decimals
[x] print as "Bounding Box - <CORNER_NAME>: (<X_COORDINATE> / <Y_COORDINATE>)"
[x] order: TL (top-left), TR (top-right), BL (bottom-left), BR (bottom-right)
[x] circle as typedef struct
[x] bounding box as typedef struct
*/
#include <stdio.h>
struct _circle_
{
float coord_x_;
float coord_y_;
float radius_;
};
struct _bbox_
{
float highest_x;
float highest_y;
float lowest_x;
float lowest_y;
};
typedef struct _circle_ Circle;
typedef struct _bbox_ BoundingBox;
int main()
{
Circle newcircle;
BoundingBox newbox;
printf("X-coordinate of the circle's center: ");
scanf(" %f",&newcircle.coord_x_); //input 6
printf("Y-coordinate of the circle's center: ");
scanf(" %f",&newcircle.coord_y_); //input 3
printf("Radius of the circle: ");
scanf(" %f",&newcircle.radius_); // input 5
newbox.highest_x = newcircle.coord_x_ + newcircle.radius_;
newbox.highest_y = newcircle.coord_y_ + newcircle.radius_;
newbox.lowest_x = newcircle.coord_x_ - newcircle.radius_;
newbox.lowest_y = newcircle.coord_y_ - newcircle.radius_;
printf("Bounding Box - TL: (%.2f/%.2f)\n", newbox.lowest_x, newbox.highest_y);
printf("Bounding Box - TR: (%.2f/%.2f)\n", newbox.highest_x, newbox.highest_y);
printf("Bounding Box - BL: (%.2f/%.2f)\n", newbox.lowest_x, newbox.lowest_y);
printf("Bounding Box - BR: (%.2f/%.2f)\n", newbox.highest_x, newbox.lowest_y);
return 0;
}