Написал 6е задание на вычислительную геометрию, задача наименьшего круга по алгоритму Велзля
This commit is contained in:
parent
6e9934a2d8
commit
b36187b77d
18 changed files with 264 additions and 1 deletions
54
ComputationalGeometry/6Ex/tools.c
Normal file
54
ComputationalGeometry/6Ex/tools.c
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#include "tools.h"
|
||||
|
||||
FILE * getFile(void) {
|
||||
char filename[50];
|
||||
|
||||
printf("Enter file name: ");
|
||||
if (scanf("%s", filename) == 1) {
|
||||
FILE * file = fopen(filename, "r");
|
||||
if (file == NULL) {
|
||||
printf("Error file!\n)");
|
||||
return NULL;
|
||||
} else {
|
||||
return file;
|
||||
}
|
||||
} else {
|
||||
printf("Empty name!\n");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
points getPoints(FILE * file) {
|
||||
int i, size = 2;
|
||||
point * array = NULL;
|
||||
point p;
|
||||
double current;
|
||||
|
||||
if (fscanf(file, "%lf", ¤t) != 1) {
|
||||
printf("File is empty!\n");
|
||||
return (points){.array=NULL, 0};
|
||||
}
|
||||
|
||||
array = (point *)malloc(size * sizeof(point));
|
||||
|
||||
i = 0, p.x = current;
|
||||
while (fscanf(file, "%lf", ¤t) == 1) {
|
||||
if (++i / 2 >= size) {
|
||||
size *= 2;
|
||||
array = (point *)realloc(array, size * sizeof(point));
|
||||
}
|
||||
|
||||
if (i % 2 == 1) {
|
||||
p.y = current;
|
||||
array[i / 2] = p;
|
||||
} else p.x = current;
|
||||
}
|
||||
|
||||
if (i == 0) {
|
||||
printf("Array is empty!\n");
|
||||
return (points){.array=NULL, 0};
|
||||
}
|
||||
|
||||
return (points){array, (i + 1) / 2};
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue