code
FWIW, here is the rest of the C program, to go with the definition of find_circle() I provided before ("well, what shape, then?"). I just change values and re-compile this program, to generate data sets. Once I have a text file full of values produced by this program, I use "awk" to select columns to make subsets of the data for use with Gnuplot.
Example: awk '{print $4}' < find_circle.out > yvals.txt
(Others might prefer to use use perl, python, whatever...)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define SHOW_COORDS
/****
#define SHOW_ADDTL
****/
#define NUM_STEPS 100
/* position values in mm */
#define X1_INIT (-22.5)
#define Y1_INIT (-3.0)
#define X1_FINAL (-33.0)
#define Y1_FINAL (-25.0)
#define X2_INIT (-7.5)
#define Y2_INIT (0.0)
#define X2_FINAL (-11.0)
#define Y2_FINAL (0.0)
#define X3_INIT (-(X2_INIT))
#define Y3_INIT (Y2_INIT)
#define X3_FINAL (-(X2_FINAL))
#define Y3_FINAL (Y2_FINAL)
/* pos: [0.0 .. 1.0] */
void
find_points(double * x1, double * y1, double * x2, double * y2,
double * x3, double * y3, double pos)
{
*x1 = X1_INIT + pos * (X1_FINAL - X1_INIT);
*y1 = Y1_INIT + pos * (Y1_FINAL - Y1_INIT);
*x2 = X2_INIT + pos * (X2_FINAL - X2_INIT);
*y2 = Y2_INIT + pos * (Y2_FINAL - Y2_INIT);
*x3 = X3_INIT + pos * (X3_FINAL - X3_INIT);
*y3 = Y3_INIT + pos * (Y3_FINAL - Y3_INIT);
}
int
main(void)
{
double cx, cy, r;
double x1, y1, x2, y2, x3, y3;
double position, step;
int i;
step = 1.0 / (NUM_STEPS - 1);
position = 0.0;
for(i = 0; i < NUM_STEPS; ++i) {
find_points(&x1, &y1, &x2, &y2, &x3, &y3, position);
find_circle(&cx, &cy, &r, x1, y1, x2, y2, x3, y3);
#ifdef SHOW_COORDS
printf("(%.1f,%.1f) (%.1f,%.1f) (%.1f,%.1f) ",
x1, y1, x2, y2, x3, y3);
#endif
#ifdef SHOW_ADDTL
printf("%10.4f %10.4f ", position, cx);
#endif
printf("%10.4f %10.4f\n", cy, r);
position += step;
}
return 0;
}
Example: awk '{print $4}' < find_circle.out > yvals.txt
(Others might prefer to use use perl, python, whatever...)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define SHOW_COORDS
/****
#define SHOW_ADDTL
****/
#define NUM_STEPS 100
/* position values in mm */
#define X1_INIT (-22.5)
#define Y1_INIT (-3.0)
#define X1_FINAL (-33.0)
#define Y1_FINAL (-25.0)
#define X2_INIT (-7.5)
#define Y2_INIT (0.0)
#define X2_FINAL (-11.0)
#define Y2_FINAL (0.0)
#define X3_INIT (-(X2_INIT))
#define Y3_INIT (Y2_INIT)
#define X3_FINAL (-(X2_FINAL))
#define Y3_FINAL (Y2_FINAL)
/* pos: [0.0 .. 1.0] */
void
find_points(double * x1, double * y1, double * x2, double * y2,
double * x3, double * y3, double pos)
{
*x1 = X1_INIT + pos * (X1_FINAL - X1_INIT);
*y1 = Y1_INIT + pos * (Y1_FINAL - Y1_INIT);
*x2 = X2_INIT + pos * (X2_FINAL - X2_INIT);
*y2 = Y2_INIT + pos * (Y2_FINAL - Y2_INIT);
*x3 = X3_INIT + pos * (X3_FINAL - X3_INIT);
*y3 = Y3_INIT + pos * (Y3_FINAL - Y3_INIT);
}
int
main(void)
{
double cx, cy, r;
double x1, y1, x2, y2, x3, y3;
double position, step;
int i;
step = 1.0 / (NUM_STEPS - 1);
position = 0.0;
for(i = 0; i < NUM_STEPS; ++i) {
find_points(&x1, &y1, &x2, &y2, &x3, &y3, position);
find_circle(&cx, &cy, &r, x1, y1, x2, y2, x3, y3);
#ifdef SHOW_COORDS
printf("(%.1f,%.1f) (%.1f,%.1f) (%.1f,%.1f) ",
x1, y1, x2, y2, x3, y3);
#endif
#ifdef SHOW_ADDTL
printf("%10.4f %10.4f ", position, cx);
#endif
printf("%10.4f %10.4f\n", cy, r);
position += step;
}
return 0;
}
Comments
Post a Comment