-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotbk.c
executable file
·170 lines (119 loc) · 4.27 KB
/
plotbk.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include <stdio.h>
#include <math.h>
main() /* program to plot curvature of a rational
B-spline curve, expressed in piecewise
rational cubic form. All curvatures are expected
in the input file b_kappas.dat. */
{
FILE *file, *plotfile;
int i,j,degree,degree1,degree2,istep,tol,buttno,howmany,dense;
float t,shoulder,width,xmin1,ymin1,xmax1,ymax1,x,y,xx,yy,
kappa_min, kappa_max, scale_x,scale_y, setline;
float coeffx[1000],value[4];
float coeffy[1000];
float abs();
char min[20],max[20];
file = fopen("b_kappas.dat","r");
plotfile= fopen("psplot.ps","w");
fscanf(file,"%d", &howmany);
fscanf(file,"%d", &dense);
for(i=0; i <= howmany ; i++)
{
fscanf(file,"%f",&coeffx[i]);
fscanf(file,"%f",&coeffy[i]);
}
minmax(coeffx,coeffy,howmany,value);
sprintf(min,"%4.2f",value[2]);
sprintf(max,"%4.2f",value[3]);
kappa_max=value[3];
kappa_min=value[2];
width=value[3]-value[2]; /*to scale kappa printouts */
minmax(coeffx,coeffy,howmany,value); /* Setting the window: */
if (value[2] > 0.0) value[2]=0.0; /* make sure kappa=0 is */
if (value[3] < 0.0) value[3]=0.0; /* drawn. Give some room */
width=(value[3]-value[2])/20.0; /* in y-direction. */
value[2]=value[2]-width;
value[3]=value[3]+width;
degree1 = degree+1;
/*********************creating a postscript file for the curvatures: *******************/
/* rotate, so paper is used sideways */
fprintf(plotfile,"90 rotate\n");
fprintf(plotfile,"70 -602 translate\n");
fprintf(plotfile,"10 300 translate\n");
scale_x=450.0/(value[1]-value[0]);
scale_y=300.0/(value[3]-value[2]);
fprintf(plotfile,"0.6 setgray \n");
fprintf(plotfile,"%f setlinewidth\n",0.1);
fprintf(plotfile,"%f %f translate\n",
-1.0*scale_x*value[0], -1.0*scale_y*value[2]);
fprintf(plotfile,"newpath \n");
fprintf(plotfile," %f %f moveto\n",
0.0,0.0);
fprintf(plotfile," %3.2f %3.2f lineto\n",
scale_x*value[1],0.0);
fprintf(plotfile,"stroke\n");
fprintf(plotfile,"newpath \n");
fprintf(plotfile," %f %f moveto\n",
scale_x*value[1],0.0);
fprintf(plotfile," %f %f lineto\n",
scale_x*value[0],0.0);
fprintf(plotfile," %f %f lineto\n",
scale_x*coeffx[0],scale_y*coeffy[0]);
for(j=1; j<= howmany; j++)
{
fprintf(plotfile," %f %f lineto\n",
scale_x*coeffx[j], scale_y*coeffy[j]);
}
fprintf(plotfile," %f %f lineto\n",
scale_x*coeffx[howmany],scale_y*coeffy[howmany]);
fprintf(plotfile,"fill\n");
/******* plot box : *************/
fprintf(plotfile,"0.0 setgray\n");
fprintf(plotfile,"0.3 setlinewidth\n");
fprintf(plotfile,"newpath\n");
fprintf(plotfile,"%f %f moveto\n",
scale_x*value[0],scale_y*value[2]);
fprintf(plotfile,"%f %f lineto\n",
scale_x*value[0],scale_y*value[3]);
fprintf(plotfile,"%f %f lineto\n",
scale_x*value[1],scale_y*value[3]);
fprintf(plotfile,"%f %f lineto\n",
scale_x*value[1],scale_y*value[2]);
fprintf(plotfile,"%f %f lineto\n",
scale_x*value[0],scale_y*value[2]);
fprintf(plotfile,"stroke\n");
/***** plot markers: ************/
fprintf(plotfile,"0.0 setgray\n ");
if(howmany > dense)
for(j=0; j<= howmany; j=j+dense)
{
if(j >= 0) /*to keep numbering right */
/* but to skip first point */
fprintf(plotfile,"%f %f %f %f %f arc stroke\n",
scale_x*coeffx[j], scale_y*coeffy[j],
3.0, 0.0, 360.0);
}
fprintf(plotfile,"1.0 setgray\n ");
if(howmany > dense)
for(j=0; j<= howmany; j=j+dense)
{
if(j >= 0) /* see above */
fprintf(plotfile,"%f %f %f %f %f arc fill\n",
scale_x*coeffx[j], scale_y*coeffy[j],
2.6, 0.0, 360.0);
}
/***** print min-max values: *************/
fprintf(plotfile,"0.0 setgray\n ");
fprintf(plotfile,"/Times-Roman findfont 15 scalefont setfont\n");
fprintf(plotfile,"%f %f moveto\n",
scale_x*value[1]+10, scale_y*kappa_max);
fprintf(plotfile,"(max: %3.3f)show\n",kappa_max);
fprintf(plotfile,"%f %f moveto\n",
scale_x*value[1]+10, scale_y*kappa_min);
fprintf(plotfile,"(min: %3.3f)show\n",kappa_min);
fprintf(plotfile,"showpage");
/*********************************************************************/
fclose(file);
fclose(plotfile);
}