summaryrefslogtreecommitdiff
path: root/src/intcgm/circle.c
blob: 4f54feddbcc91c4f78a80d01fba11515c3d5bedd (plain)
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
#include <stdio.h>
#include <math.h>

#include <cd.h>

#include "list.h"
#include "types.h"
#include "intcgm.h"
#include "intcgm6.h"

#include "circle.h"

#define DIM 360

#ifndef PI
#define PI 3.14159265358979323846
#endif

#define PI180 PI/180.
#define TWOPI 2*PI
#define VARCS TWOPI/32.

int cgm_poly_circle ( double xc, double yc, double radius, double angi, double angf, int fechado )
{
 double coseno, seno;
 double xs, ys;
 
 coseno = cos (VARCS);
 seno   = sin (VARCS);

 xs = radius * cos(angi);
 ys = radius * sin(angi);

 cdCanvasBegin(intcgm_canvas,  cgm_setintstyle(intcgm_fill_att.int_style) );

 if ( fechado==CLOSED_PIE ) cdCanvasVertex (intcgm_canvas,  cgm_vdcx2canvas(xc), cgm_vdcy2canvas(yc) );

 cdCanvasVertex (intcgm_canvas,  cgm_vdcx2canvas(xc+xs), cgm_vdcy2canvas(yc+ys) );

 while ( (angi+VARCS) < angf )
  {
   double xe = xs;
   xs = xs * coseno - ys * seno;
   ys = ys * coseno + xe * seno;
   cdCanvasVertex (intcgm_canvas,  cgm_vdcx2canvas(xc+xs), cgm_vdcy2canvas(yc+ys) );
   angi += VARCS;
  }

 cdCanvasVertex (intcgm_canvas,  cgm_vdcx2canvas(xc+radius*cos(angf)), cgm_vdcy2canvas(yc+radius*sin(angf)) );

 cdCanvasEnd(intcgm_canvas);

 return 0;
}

int cgm_line_circle ( double xc, double yc, double radius, double angi, double angf, int fechado )
{
 double coseno, seno;
 double xant, yant, firstx, firsty;
 double xs, ys;

 /* GERA O DESENHO DO CIRCULO/ARCO */

 coseno = cos (VARCS);
 seno   = sin (VARCS);

 xs = radius * cos(angi);
 ys = radius * sin(angi);

 if ( fechado==CLOSED_PIE )
  cdCanvasLine (intcgm_canvas,  cgm_vdcx2canvas(xc), cgm_vdcy2canvas(yc), cgm_vdcx2canvas(xc+xs), cgm_vdcy2canvas(yc+ys) );

 xant = firstx = xc+xs;
 yant = firsty = yc+ys;

 while ( (angi+VARCS) < angf )
  {
   double xe = xs;
   xs = xs * coseno - ys * seno;
   ys = ys * coseno + xe * seno;
   cdCanvasLine (intcgm_canvas,  cgm_vdcx2canvas(xant), cgm_vdcy2canvas(yant), cgm_vdcx2canvas(xc+xs), cgm_vdcy2canvas(yc+ys) );
   xant = xc+xs;
   yant = yc+ys;
   angi += VARCS;
  }

 cdCanvasLine (intcgm_canvas,  cgm_vdcx2canvas(xant), cgm_vdcy2canvas(yant),
          cgm_vdcx2canvas(xc+radius*cos(angf)), cgm_vdcy2canvas(yc+radius*sin(angf)) );

 xant = xc+radius*cos(angf);
 yant = yc+radius*sin(angf);

 if ( fechado==CLOSED_PIE )
  cdCanvasLine (intcgm_canvas,  cgm_vdcx2canvas(xant), cgm_vdcy2canvas(yant), cgm_vdcx2canvas(xc), cgm_vdcy2canvas(yc) );
 else if ( fechado==CLOSED_CHORD )
  cdCanvasLine (intcgm_canvas,  cgm_vdcx2canvas(xant), cgm_vdcy2canvas(yant), cgm_vdcx2canvas(firstx), cgm_vdcy2canvas(firsty) );

 return 0;
}