DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T a

⟦d328b53e6⟧ TextFile

    Length: 2863 (0xb2f)
    Types: TextFile
    Names: »arc.c«

Derivation

└─⟦a05ed705a⟧ Bits:30007078 DKUUG GNU 2/12/89
    └─⟦148e64aa4⟧ »./plot2ps.tar.Z« 
        └─⟦ff7617d1d⟧ 
            └─⟦this⟧ »arc.c« 

TextFile

/* plot2ps, a utility for converting Unix plot files into postscript.
   Copyright (C) 1989 Free Software Foundation, Inc.

Plot2ps is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY.  No author or distributor accepts responsibility to anyone for the
consequences of using it or for whether it serves any particular purpose or
works at all, unless he says so in writing.  Refer to the GNU General Public
License for full details.

Everyone is granted permission to copy, modify and redistribute plot2ps, but
only under the conditions described in the GNU General Public License.  A copy
of this license is supposed to have been given to you along with plot2ps so
you can know your rights and responsibilities.  It should be in a file named
COPYING.  Among other things, the copyright notice and this notice must be
preserved on all copies.  */

/* This file is the arc routine, which is a standard part of the plot
   library.  It draws an arc with the center at xc,yc, the beginning at
   x0,y0 and the ending at x1,y1 */

#include <math.h>
#include <stdio.h>
#ifdef sequent
#include <strings.h>
#else
#include <string.h>
#endif
#include "plot3.h"
extern int printf();
extern int fprintf();
#ifndef mips
extern char *sprintf();
#endif
extern int fputs(), fputc();

int
arc (xc, yc, x0, y0, x1, y1)
     int xc, yc, x0, y0, x1, y1;
{
  /* center: xc,yc
     from: x0,y0
     to: x1,y1 */
  double dtheta, cos_theta, sin_theta, x, y, radius;
  /* don't confuse these with global last_x and last_y */
  double xlast, ylast;
  int same_quadrant, x_between, y_between;

#ifdef DEBUG
  printf ("%% arc: %d %d %d %d %d %d\n", xc, yc, x0, y0, x1, y1);
#endif
  x = x0 - xc;
  y = y0 - yc;
  radius = sqrt (x*x + y*y);

  if (radius == 0.) /* if the radius is zero, we draw a point. */
    {
       point (xc, yc);
       return 0;
    }
  /* the # of segments is proportional to the radius */
  dtheta = 60./radius;
  if (dtheta > .02) dtheta = .02; /* force at least 50 points on a circle. */
  dtheta *= M_PI;
  cos_theta = cos (dtheta);
  sin_theta = sin (dtheta);
  move ((int) (xc + x), (int) (yc + y));
  x1 -= xc;
  y1 -= yc;
  xlast = x;
  ylast = y;
  x = (x * cos_theta - y * sin_theta);
  y = (y * cos_theta + x * sin_theta);
  cont ((int) (xc + x), (int) (yc + y));
   
  do
    {
      xlast = x;
      ylast = y;
      x = (x * cos_theta - y * sin_theta);
      y = (y * cos_theta + x * sin_theta);
      cont ((int) (xc + x), (int) (yc + y));

      /* are x,y  in the same quadrant as x1,y1 ? */
      same_quadrant = (x * x1 >= 0) && (y * y1 >= 0);

      /* Is x1 between x and xlast */
      x_between = ((x - x1) * (xlast - x1) <= 0);
      /* Is y1 between y and ylast */
      y_between = ((y - y1) * (ylast - y1) <= 0);
    }
  while ( (!same_quadrant) || ((!x_between) && (!y_between)) );

  move (xc, yc);
  return 0;
}