/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * * ##### # # # * * #### ##### ###### # # # # # # # * * # # # # # ## # # # # # * * # # # # ##### # # # # #### # ### * * # # ##### # # # # # # # # # # * * # # # # # ## # # # # # # * * #### # ###### # # ##### ##### # # * * * * Mattia Montanari | University of Oxford 2018 * * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * * * * This file runs an example to illustrate how to invoke the openGJK lib * * within a C program. An executable called 'demo' can be compiled with * * CMake. This reads the coordinates of two polytopes from the input * * files userP.dat and userQ.dat, respectively, and returns the minimum * * distance between them computed using the openGJK library. * * * * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /** * @file main.c * @author Mattia Montanari * @date April 2018 * @brief File illustrating an application that invokes openGJK. * */ #include /* For importing openGJK this is Step 1: include header in subfolder. */ #include "openGJK/openGJK.h" #ifndef WIN32 #define fscanf_s fscanf #endif /** * @brief Function for reading input file with body's coordinates. * */ int readinput ( const char *inputfile, double ***pts, int * out ) { int npoints = 0; int idx = 0; FILE *fp; /* Open file. */ #ifdef WIN32 errno_t err; if ((err = fopen_s(&fp, inputfile, "r")) != 0) { #else if ((fp = fopen(inputfile, "r")) == NULL) { #endif fprintf(stdout, "ERROR: input file %s not found!\n", inputfile); fprintf(stdout, " -> The file must be in the folder from which this program is launched\n\n"); return 1; } /* Read number of input vertices. */ if (fscanf_s(fp, "%1d", &npoints) != 1) return 1; /* Allocate memory. */ double **arr = (double **)malloc(npoints * sizeof(double *)); for (int i=0; i