CAD/CAM Developer's Kit/3D

 

Reference Guide

 

1. Introduction

 

2. 2D Geometry

 

3. 3D Geometry

 

4. DXF

 

5. Display

 

6. Lists

 

7. Home

 

 

Copyright (c) 1988-2009 Building Block Software, Inc. All rights reserved.

 

CAD/CAM Developer's Kit/3D

 

 

Overview

========

 

The Building Block Software CAD/CAM Developer's Kits (CCDK)  are a collection

of C function libraries for writing CAD/CAM  applications.  The CCDK

libraries provide functions for operations  such as reading and writing of

DXF files, display of geometry, and  2D and 3D geometric computations.

 

The set of types, macros and functions that support operations with 2D points,

vectors and curves are called "2D GEOMETRY".  The operations supported include:

 

* construction of lines, arcs, circles, ellipses, polycurves  and NURB splines

 

* coordinate, tangent vector and curvature evaluation

 

* computation of curve intersection points

 

* curve offset construction

 

 

This reference provides:

 

* fundamental concepts behind the objects and functions in 2D GEOMETRY

 

* type definitions for 2D objects

 

* public functions and macros (organized by category)

 

* public functions and macros (organized alphabetically)

 

 

 

Fundamental Concepts

====================

 

Introduction

------------

 

This section presents the concepts behind the 2D GEOMETRY objects and operations.

 

 

2D Objects

----------

 

The object types supported in 2D GEOMETRY are:

 

* points/vectors

 

* curves

 

* bounding boxes

 

* transform

 

A point is a set of cartesian coordinates representing a location in space.

The term vector denotes a direction and a magnitude.

 

A curve is an object that can represent curve  geometry. Curve types

supported in CCDK/2D are:

 

* line

 

* arc

 

* ellipse

 

* polycurve

 

* Non-Uniform Rational B-spline (NURB-spline)

 

A line is a linear segment.

 

An arc is a circular segment or a full circle.

 

An ellipse is an elliptical segment, either partial or  closed.

 

A polycurve is an end-to-end chain of line and arc segments.

 

A Non-Uniform Rational B-spline (NURB-spline) is a general type of B-spline. 

It can represent a range of spline types, including uniform, non-rational and

Bezier splines as well as conic curves.

 

 

A bounding box is a rectangle, often used to record the  extents of a 2D

object.  This box is aligned with the coordinate  axes.

 

Bounding boxes are useful for determining the approximate locations  and

sizes of curves.  This information can be applied to "cull"  curves from a

set of curves to increase display performance in  "zoom" operations.  They

can also be used to determine quickly if  two curves have no intersection

points (if the bounding boxes of two  curves do not intersect, then the

curves do not intersect).

 

A transform is a matrix used to transform objects in one  coordinate system

into another.

 

Curve Properties

----------------

 

All curve types have a common set of properties.  These properties are defined by the

following statements:

 

* Every curve has a start point, an end point and an "orientation";  if a curve is

  closed, the start point and the end point are the same; the  orientation is

  the direction one follows along the curve to travel from the start point

  to the end point.

 

* For each point on a curve, there is a corresponding real  number called a

  parameter value; in mathematical terms, there  is a "one-to-one mapping"

  between points on a curve and a continuous  range of real numbers.

 

* At each point on a curve, one may evaluate a tangent vector,  a curvature,

  and other mathematical properties.

 

* curves may be rotated, scaled, translated, mirrored,  intersected, trimmed

  and filleted.

 

* a curve may be offset to produce a parallel curve  which runs along the

  original curve a constant distance away.

 

Treating all curve types as one type with these properties  eliminates the

need to have a separate function for each curve type  for each operation.

Instead, there is only one function for each  operation.

 

Curve Parameters

----------------

 

A curve parameter is simply a real number (often represented by the  symbol

t) that corresponds to a point on a curve. Each point  is associated with

only one parameter value, and any one parameter  value is associated with

only one point. This number has a particular  value at the start point of a

curve, and it increases continuously  as one moves along the curve towards

the end point.

 

The concept of a curve parameter is a key notion in the object- oriented

scheme that enables one general curve type to represent all  curve types.

 

Curve parameters have two very useful features:

 

* they unambigously specify positions on curves

 

* they imply relative positions of points on curves

 

The first feature is a convenient method for identifying the  location on a

curve where, for example, an intersection or a local  extremum occurs.  Also,

this feature can be used to specify where an  operation, such as the

evaluation of a tangent vector, should be  performed.

 

The second feature is useful for determining the order of points along  a

curve. For example, if point A has a parameter value less than point  B, then

point A is encountered first as one travels along the curve  from its start

point to its end point.

 

Parameter values corresponding to points on a curve can  be obtained from a

number of sources:

 

* CCDK/2D macros and routines which provide parameter values  of start and end

  points of curves

 

* curve intersection records, which report locations of  intersections in terms

  of curve parameter values as well as  cartesian coordinates

 

* curve extremum records, which report locations of  local extreme points in

  terms of curve parameters

 

* c2c_project, the function that projects a point  orthogonally onto a curve;

  it reports the location of the projection  in terms of a curve parameter;

  this function converts cartesian  coordinates of a location on a curve into

  its corresponding curve  parameter

 

A curve intersection is a point where two curves cross.   CCDK/2D

intersection functions report the curve parameters of  intersection points as

well as their coordinates and tangency  conditions.

 

A curve extremum is a point on a curve where the curve  changes direction

along either the x or y axes.  For example, a  circle has four extrema: two

'x' extrema (3 o'clock and 9 o'clock)  and two 'y' extrema (12 o'clock and 6

o'clock).

 

Unlike other curve properties of 2D curves, the extrema depend on  the

coordinate system.  Rotations change the locations of extrema.

 

Extrema have many uses, such as identifying points at which curves  must be

"broken".  An example of an application that requires curves  to be broken at

extrema is motion control; an extremum point denotes  a change in direction,

which, in motion control programs, must be  accompanied with "backlash

compensation". By breaking curves at extrema,  motion control programs can

insert the necessary backlash compensation  at these points.

 

2D Geometric Operations

-----------------------

 

This section presents the 2D geometric operations supported by  CCDK/2D

functions.  These operations fall into three main  categories:

 

* point and vector

 

* curve

 

* bounding box

 

* transform

 

Point and vector operations consist of:

 

* construction

 

* evaluation

 

* addition and multiplication

 

Construction operations create point and vector objects.

 

Evaluation operations compute properties of points and  vectors, such as

linear distances, lengths and angles.

 

Addition and multiplication operations consist of standard  vector

computations.

 

Curve operations consist of:

 

* construction

 

* copying

 

* modification

 

* evaluation

 

Construction operations create geometry from input information.  Creating an

arc passing through three points is one example of a construction  operation.

 

 

Copying operations create copies of curves.  Many of the  functions also

alter copies by trimming or transforming them.

 

Modification operations, which change existing  geometry,

include:

 

* trimming

 

* breaking

 

* rotation

 

* scaling

 

* mirroring

 

* translation

 

* offsetting

 

Evaluation operations compute information about geometry such  as: tangent

vectors, curvature, midpoints, endpoints and lengths. In  addition,

evaluation operations locate intersection and  extremum points.

 

Bounding box operations consist of:

 

* construction

 

* evaluation

 

Construction operations create and modify bounding boxes. 

 

Evaluation determines if bounding boxes overlap.

 

Transform operations are divided into:

 

* construction

 

* evaluation

 

Construction operations create and combine transforms. Transforms are

constructed from the axes of coordinate systems.

 

Evaluation consists of applying transforms to points and  vectors in one

coordinate system to obtain their coordinates in  another coordinate system.

 

Computational Accuracy

----------------------

 

The accuracy of the computations performed by routines in the CCDK  is

governed by three quantities: absolute tolerance,  relative tolerance and

world size.

 

The relationship between the two tolerances and the world size is  specified

by the following equation:

 

absolute_tolerance = relative_tolerance * world_size ;

Absolute tolerance is used to determine when lengths and  distances are small

enough to be treated as negligible; it is  dependent on the quantity, world

size, since "negligible" is  relative to how big your world is.

 

Relative tolerance is used to determine when quantities such  as angles are

small enough to be considered zero.  Another definition  for this quantity is

that it is equal to the absolute tolerance  when the world size is 1.0.

Unlike the absolute tolerance,  the relative tolerance is not dependent on

world size.

 

World size is simply a number that indicates the typical size  of the

geometry being processed. Geometry is not necessarily limited  to this size,

but computational accuracy may decrease if geometry  much larger than the

world size is used without adjusting the internal  world size parameter. The

initial value of world size is 10  units; this value may be changed by

calling the qgl_put_world_size  function.

 

The relative tolerance has an initial value of 1.0E-12, and  may be changed

with the qgl_put_tol function.

 

The absolute tolerance, which has an initial value of 1.0E-11,  may not be

set directly; instead it must be changed by resetting the  world size and/or

the relative tolerance.

 

The function qgl_is_small can be used to determine if the  absolute value of

a REAL is less than the absolute tolerance.  The function  qgl_is_zero can be

used to determine if the  absolute value of a REAL is less than the relative

tolerance. 

 

Object Types

============

 

Introduction

------------

 

This section presents programming information about the objects  defined in

CCDK/2D.  Use this section of the manual to locate the  names of object

types, and the macros that access the attributes of  these types.

 

Types Overview

--------------

 

CCDK/2D defines types, constants and macros for the  following categories:

 

* general types and constants

 

* point and vector

 

* bounding box

 

* parameter record

 

* curve

 

* intersection record

 

* extremum record

 

* transform

 

The general types and constants category consists of basic  types used

throughout CCDK. 

 

The point and vector, bounding box, parameter  record, curve, intersection

record, extremum  record, and transform categories provide types for each of

these objects, and macros which access attributes of these types.

 

General Types and Constants

---------------------------

 

The object types in this category are the "atoms" of CCDK  objects:

 

______________________________________________________________________________

| Type                                 | Meaning                             |

|----------------------------------------------------------------------------|

| INT                                  | integer                             |

| REAL                                 | real number                         |

| BOOLEAN                              | Boolean value; TRUE or FALSE        |

| STRING                               | string; pointer to a character      |

------------------------------------------------------------------------------

 

These types are defined in the header file qgldefs.h.

 

CCDK/2D also provides the following constants:

 

______________________________________________________________________________

| Constant                             | Meaning                             |

|----------------------------------------------------------------------------|

| TRUE                                 | true                                |

| FALSE                                | false                               |

| SQRT_2                               | square root of two                  |

| SQRT_3                               | square root of three                |

| TWO_PI                               | two pi                              |

| PI                                   | pi                                  |

| HALF_PI                              | one-half pi                         |

| PI_OVER_180                          | pi divided by 180; useful for       |

|                                      | converting between degrees  and     |

|                                      | radians                             |

------------------------------------------------------------------------------

 

Points and Vectors

------------------

 

Points and vectors are represented by the following  types:

 

______________________________________________________________________________

| Type                                 | Meaning                             |

|----------------------------------------------------------------------------|

| PT2                                  | a two-dimensional point or vector   |

| PT2                                  | a pointer to two-dimensional point  |

|                                      | or vector                           |

------------------------------------------------------------------------------

 

Declaring a variable of type PT2 allocates uninitialized space  for two

coordinate values.  The coordinates of a PT2 object are set  with the

function c2v_set. 

 

These types are defined in the header file c2defs.h.

 

The following macros access the coordinates of points and components  of

vectors:

 

______________________________________________________________________________

| Type                                 | Meaning                             |

|----------------------------------------------------------------------------|

| PT2_X(P)                             | the abscissa (x-coordinate) of      |

|                                      | point P, or the x component  of     |

|                                      | vector P                            |

| PT2_Y(P)                             | the ordinate (y-coordinate) of      |

|                                      | point P, or the y component  of     |

|                                      | vector P                            |

------------------------------------------------------------------------------

 

These macros are defined in the header file c2defs.h.

 

Bounding Box

------------

 

A bounding box is a rectangle that encloses a curve.  For lines, arcs, and

circles, this rectangle is the smallest possible  one; for ellipses and

splines, it is not necessarily the smallest  one, but it is nearly so.

 

Bounding boxes are represented by these types:

 

______________________________________________________________________________

| Type                                 | Meaning                             |

|----------------------------------------------------------------------------|

| C2_BOX_S                             | a bounding box structure            |

| C2_BOX                               | a pointer to a bounding box         |

------------------------------------------------------------------------------

 

These types are defined in the header file c2defs.h. 

 

The term "bounding box" refers to an object of type C2_BOX.  This object is a

pointer to a bounding box structure.

 

When a bounding box is used as working space or for output,  it must refer to

a bounding box structure that has been declared as  an automatic variable, or

has been allocated.

 

When declaring automatic storage, it is often convenient to declare  both a

structure and a pointer to the structure to avoid repetitive  evaluation of

the structure address:

 

C2_BOX_S box_s;

C2_BOX box = &box_s;

Alternatively, memory for a bounding box may be allocated with  c2a_box:

 

C2_BOX box = c2a_box ( NULL, NULL );

When an allocated bounding box is no longer needed, it must  be freed with

c2a_free_box.

 

The following macros access information in bounding  boxes:

 

______________________________________________________________________________

| Type                                 | Meaning                             |

|----------------------------------------------------------------------------|

| C2_MIN_PT(B)                         | a PT2 that represents the lower     |

|                                      | left corner of bounding box B       |

| C2_MAX_PT(B)                         | a PT2 that represents the upper     |

|                                      | right corner of bounding box B      |

| C2_MIN_X(B)                          | a REAL that specifies the x         |

|                                      | coordinate of the left edge of      |

|                                      | bounding box B                      |

| C2_MIN_Y(B)                          | a REAL that specifies the y         |

|                                      | coordinate of the bottom edge of    |

|                                      | bounding box B                      |

| C2_MAX_X(B)                          | a REAL that specifies the x         |

|                                      | coordinate of the right edge of     |

|                                      | bounding box B                      |

| C2_MAX_Y(B)                          | a REAL that specifies the y         |

|                                      | coordinate of the top edge of       |

|                                      | bounding box B                      |

------------------------------------------------------------------------------

 

These macros are defined in the header file c2defs.h.

 

Parameter Record

-----------------

 

A parameter record is a structure composed of a parameter value and  an

index.  Only the parameter value is a "public" quantity.   The index is used

internally, and should never be set by a CCDK  user.  To set a parameter

value, use the macro PARM_SET.

 

______________________________________________________________________________

| Type                                 | Meaning                             |

|----------------------------------------------------------------------------|

| PARM_S                               | a parameter record structure        |

| PARM                                 | a pointer to a parameter record     |

------------------------------------------------------------------------------

 

These types are defined in the header file qgldefs.h.

 

The term "parameter record" refers to an object of type PARM.  This object is

a pointer to a parameter record structure.

 

The term "parameter value" means the REAL value stored in a  parameter

record.  This value is usually represented with the symbol  t.

 

The prefix "C2_" is omitted from the curve parameter record type name

because curve parameters apply to three-dimensional curves as well  as

two-dimensional curves.

 

When calling a routine such as c2c_project which uses a  parameter record for

output, the parameter record supplied  must refer to a parameter record

structure that has been declared as  an automatic variable, or has been

allocated. 

 

When declaring automatic storage, it is often convenient to declare  both a

structure and a pointer to the structure to avoid repetitive  evaluation of

the structure address:

 

PARM_S parm_s;

PARM parm = &parm_s;

Alternatively, memory for a parameter record may be allocated with  ald_parm

or ald_parm_t:

 

PARM parm = ald_parm();

When an allocated parameter record is no longer needed, it  must be freed

with ald_parm_free.

 

The following macros read and set the parameter value  of parameter records:

 

______________________________________________________________________________

| Macro                                | Meaning                             |

|----------------------------------------------------------------------------|

| PARM_T(P)                            | a REAL which is the parameter       |

|                                      | value in parameter record P         |

| PARM_SET(T,P)                        | a macro that sets the parameter     |

|                                      | value of parameter record P  to     |

|                                      | REAL value T                        |

------------------------------------------------------------------------------

 

These macros are defined in the header file qgldefs.h. 

 

Curves

------

 

The following object type defines a curve:

 

______________________________________________________________________________

| Type                                 | Meaning                             |

|----------------------------------------------------------------------------|

| C2_CURVE                             | a curve                             |

------------------------------------------------------------------------------

 

An object of type C2_CURVE can represent a line, an arc, a  circle, an

ellipse, a polycurve, or a B-spline.  "Create" functions  are provided to

create each of these geometry types.

 

C2_CURVE is defined in the header file c2defs.h.

 

The following macros access start and end parameters of  a curve:

 

______________________________________________________________________________

| Macro                                | Meaning                             |

|----------------------------------------------------------------------------|

| C2_CURVE_PARM0(C)                    | a PARM which is the curve           |

|                                      | parameter record corresponding to   |

|                                      | the start point of curve C; the     |

|                                      | return value type of this macro is  |

|                                      |  PARM                               |

| C2_CURVE_PARM1(C)                    | a PARM which is the curve           |

|                                      | parameter record corresponding to   |

|                                      | the end point of curve C; the       |

|                                      | return value type of this macro is  |

|                                      |  PARM                               |

| C2_CURVE_T0(C)                       | a REAL which is the curve           |

|                                      | parameter t corresponding  to the   |

|                                      | start point of curve C; the return  |

|                                      | value type of this macro  is REAL   |

| C2_CURVE_T1(C)                       | a REAL which is the curve           |

|                                      | parameter t corresponding  to the   |

|                                      | end point of curve C; the return    |

|                                      | value type of this macro is  REAL   |

------------------------------------------------------------------------------

 

The following macros determine curve type:

 

______________________________________________________________________________

| Macro                                | Meaning                             |

|----------------------------------------------------------------------------|

| C2_CURVE_IS_LINE(C)                  | a BOOLEAN which is TRUE if curve C  |

|                                      | is a line; FALSE  otherwise         |

| C2_CURVE_IS_ARC(C)                   | a BOOLEAN which is TRUE if curve C  |

|                                      | is an arc or a circle;  FALSE       |

|                                      | otherwise                           |

| C2_CURVE_IS_PCURVE(C)                | a BOOLEAN which is TRUE if curve C  |

|                                      | is a polycurve; FALSE  otherwise    |

------------------------------------------------------------------------------

 

The following functions access curve bounding boxes:

 

______________________________________________________________________________

| Macro                                | Meaning                             |

|----------------------------------------------------------------------------|

| C2_CURVE_BOX(C)                      | a C2_BOX which is the bounding box  |

|                                      | of curve C                          |

| C2_CURVE_X_MIN(C)                    | a REAL which is the x coordinate    |

|                                      | of the left edge of the  bounding   |

|                                      | box of curve C                      |

| C2_CURVE_X_MAX(C)                    | a REAL which is the x coordinate    |

|                                      | of the right edge of the  bounding  |

|                                      | box of curve C                      |

| C2_CURVE_Y_MIN(C)                    | a REAL which is the y coordinate    |

|                                      | of the bottom edge of the           |

|                                      | bounding box of curve C             |

| C2_CURVE_Y_MAX(C)                    | a REAL which is the y coordinate    |

|                                      | of the top edge of the  bounding    |

|                                      | box of curve C                      |

------------------------------------------------------------------------------

 

Use these macros, defined in the header file c2defs.h, to obtain  curve

parameter, type and bounding box information.  Use routines  c2c_ept0 and

c2c_ept1 to compute start and end points  of curves.

 

The following macros are defined when the symbol  SPLINE is defined to enable

spline code. 

 

______________________________________________________________________________

| Type                                 | Meaning                             |

|----------------------------------------------------------------------------|

| C2_CURVE_IS_ELLIPSE(C)               | TRUE if curve C is an ellipse;      |

|                                      | FALSE otherwise                     |

| C2_CURVE_IS_SPLINE(C)                | TRUE if curve C is a spline; FALSE  |

|                                      | otherwise                           |

------------------------------------------------------------------------------

 

These macros are defined in the header file c2defs.h.

 

Intersection Record

-------------------

 

The point where two curves cross, termed a curve intersection,  is reported

by an object called an intersection record. 

 

This type of object is composed of:

 

* the coordinates of an intersection point

 

* two parameter records corresponding to the locations  where the intersection

  occurs

 

* a flag indicating whether the curves cross, touch  tangentially, or are

  collinear

 

Intersection records are usually returned on an intersection  result list.

 

The following type is used to represent an intersection  record:

 

______________________________________________________________________________

| Type                                 | Meaning                             |

|----------------------------------------------------------------------------|

| C2_INT_REC                           | an intersection record; this        |

|                                      | object consists of information      |

|                                      | about a point where two curves      |

|                                      | intersect                           |

------------------------------------------------------------------------------

 

Intersection records always reference two curves.  The terminology  "first

curve" and "second curve", used to distinguish between the  two curves,

denotes the first and the second of the two curve  arguments, respectively,

in the intersection function argument list.

 

Intersection records are created internally by intersection  routines, and

therefore CCDK/2D does not provide a "create" routine.  A free routine,

c2d_free_int_rec, is provided for disposing of  intersection records when

they are no longer needed.

 

C2_INT_REC is defined in the header file c2defs.h. 

 

The following macros access information in an  intersection record:

 

______________________________________________________________________________

| Type                                 | Meaning                             |

|----------------------------------------------------------------------------|

| C2_INT_REC_PARM1(R)                  | the curve parameter record in       |

|                                      | intersection record R               |

|                                      | corresponding to the location       |

|                                      | where an intersection occurs on     |

|                                      | the  first of two curves            |

|                                      | intersected                         |

| C2_INT_REC_T1(R)                     | the curve parameter value in        |

|                                      | intersection record R               |

|                                      | corresponding to the location       |

|                                      | where an intersection occurs on     |

|                                      | the  first of two curves            |

|                                      | intersected                         |

| C2_INT_REC_PARM2(R)                  | the curve parameter record in       |

|                                      | intersection record R               |

|                                      | corresponding to the location       |

|                                      | where an intersection occurs on     |

|                                      | the  second of two curves           |

|                                      | intersected                         |

| C2_INT_REC_T2(R)                     | the curve parameter value in        |

|                                      | intersection record R               |

|                                      | corresponding to the location       |

|                                      | where an intersection occurs on     |

|                                      | the  second of two curves           |

|                                      | intersected                         |

| C2_INT_REC_PARM(R,I)                 | the curve parameter record in       |

|                                      | intersection record R               |

|                                      | corresponding to the location       |

|                                      | where an intersection occurs on     |

|                                      | the  "I"th of two curves            |

|                                      | intersected; I may be either 1 or   |

|                                      | 2                                   |

| C2_INT_REC_T(R,I)                    | the curve parameter value in        |

|                                      | intersection record R               |

|                                      | corresponding to the location       |

|                                      | where an intersection occurs on     |

|                                      | the  "I"th of two curves            |

|                                      | intersected; I may be either 1 or   |

|                                      | 2                                   |

| C2_INT_REC_PT(R)                     | a record of type PT2 in             |

|                                      | intersection record R which         |

|                                      | contains  the coordinates of a      |

|                                      | point of intersection               |

| C2_INT_REC_TYPE(R)                   | a flag that specifies whether the   |

|                                      | intersection reported by            |

|                                      | intersection R is transverse,       |

|                                      | tangent or collinear                |

| C2_INT_REC_TRANS(R)                  | if the intersection reported in     |

|                                      | intersection record R is            |

|                                      | transverse,  this macro returns     |

|                                      | TRUE; it returns FALSE otherwise    |

| C2_INT_REC_TANGENT(R)                | if the intersection reported in     |

|                                      | intersection record R is  tangent,  |

|                                      | this macro returns TRUE; it         |

|                                      | returns FALSE otherwise             |

------------------------------------------------------------------------------

 

These macros are defined in the header file c2defs.h.

 

Extremum Record

---------------

 

The point where a curve reverses direction, along either the x or y  axes, is

termed a curve extremum. This point is reported by  an object called an

extremum record.  The CCDK/2D function  c2c_coord_extrs locates the extrema

of a curve and returns a  list of extremum records, one for each extremum.

Curve endpoints  are never considered curve extrema.

 

An extremum record is composed of:

 

* a parameter record representing the location of an curve  extremum

 

* the coordinate value of a curve extremum on the axis of  the extremum

 

* a flag indicating whether an extremum is a minimum or  a maximum.

 

The following type is used to represent an extremum  record:

 

______________________________________________________________________________

| Type                                 | Meaning                             |

|----------------------------------------------------------------------------|

| C2_EXTR_REC                          | an extremum record; this record     |

|                                      | consists of information  about a    |

|                                      | local x or y extremum point on a    |

|                                      | curve                               |

------------------------------------------------------------------------------

 

This type is defined in the header file c2defs.h. 

 

The following macros access information in extremum  records:

 

______________________________________________________________________________

| Type                                 | Meaning                             |

|----------------------------------------------------------------------------|

| C2_EXTR_REC_PARM(R)                  | the curve parameter record          |

|                                      | corresponding to the extremum       |

|                                      | point  on a curve reported by       |

|                                      | extremum record R                   |

| C2_EXTR_REC_T(R)                     | the curve parameter value           |

|                                      | corresponding to the extremum       |

|                                      | point  on a curve reported by       |

|                                      | extremum record R                   |

| C2_EXTR_REC_F(R)                     | the extremum coordinate value of    |

|                                      | the extremum point reported  by     |

|                                      | extremum record R                   |

| C2_EXTR_REC_TYPE(R)                  | a flag which indicates whether the  |

|                                      | extremum point reported  by         |

|                                      | extremum record R is a maximum or   |

|                                      | a minimum; the value 1 denotes  a   |

|                                      | maximum; -1 denotes a minimum       |

------------------------------------------------------------------------------

 

These macros are defined in the header file c2defs.h.

 

Transform

---------

 

2D transforms are represented by the type:

 

______________________________________________________________________________

| Type                                 | Meaning                             |

|----------------------------------------------------------------------------|

| C2_TRANSFORM                         | a 2D transform                      |

------------------------------------------------------------------------------

 

This type is defined in the header file c2defs.h. 

 

When a transform is used as working space or for output, it  must be declared

as an automatic variable, or it must be allocated  dynamically.

 

Declaring an automatic variable of type C2_TRANSFORM allocates space  for the

transform matrix.

 

To allocate dynamic memory for a transform, use c2t_create:

 

C2_TRANSFORM *t = c2t_create();

When an allocated transform is no longer needed, it must  be freed with

c2t_free.

 

Functions and Macros By Category

================================

 

Introduction

------------

 

This section presents CCDK/2D functions organized by the type of  operation

they perform.

 

Category Overview

-----------------

 

The functions in the CCDK/2D are organized into four  areas:

 

* general

 

* point/vector

 

* curve

 

* bounding box

 

* transform

 

General functions deal mostly with computational tolerance  and world size.

 

Point/vector functions perform computations with points and  vectors.

 

Curve functions create curves and perform computations with  them.

 

Bounding box functions build bounding boxes and determine if  bounding boxes

overlap.

 

Transform functions build transforms and apply them to points  and vectors.

 

Functions that perform point and vector operations are  divided into the

following groups:

 

* construction

 

* evaluation

 

* addition and multiplication

 

Construction functions create and initialize points and  vectors.  They also

construct points and vectors from other points  and vectors, and they rotate,

scale and mirror points and vectors.

 

Evaluation functions compute properties of points and  vectors.

 

Addition and multiplication functions perform vector  computations.

 

Functions that perform curve operations are  divided into the following

groups:

 

* construction

 

* copying

 

* modification

 

* evaluation

 

Construction create curves from input parameters.  They also  create curve

parameter objects.

 

Copying functions copy existing curves, in most cases  also altering the copy

by transforming, trimming or offsetting it.

 

Modification functions alter existing curves.  These  functions are similar

to copy functions, except that the curve that  is altered is the input curve,

not a copy.

 

Evaluation functions compute properties of curves, such as  end point

coordinates, tangent vectors and extremum points.  These  functions also

compute intersection points.

 

Functions that perform bounding box operations are  divided into the

following groups:

 

* construction

 

* evaluation

 

Construction functions create and modify bounding boxes.

 

Evaluation consists of one function, c2a_box_overlap,  that determines if two

bounding boxes interfere.

 

Function Prefixes

-----------------

 

CCDK functions are labelled with prefixes to indicate  the general type of

operation they perform.  Prefixes used in  CCDK/2D are:

 

______________________________________________________________________________

| Prefix                               | Meaning                             |

|----------------------------------------------------------------------------|

| qgl                                  | general                             |

| c2v                                  | point/vector                        |

| ald                                  | curve parameter                     |

| c2d                                  | curve construction and copying      |

| c2c                                  | curve modification and evaluation   |

| c2a                                  | bounding box                        |

| c2t                                  | transform                           |

------------------------------------------------------------------------------

 

General Functions

-----------------

 

______________________________________________________________________________

| Function                             | Use                                 |

|----------------------------------------------------------------------------|

| qgl_get_tol                          | to obtain the absolute tolerance    |

| qgl_put_tol                          | to set the absolute tolerance       |

| qgl_is_small                         | to test if a REAL number is less    |

|                                      | than the absolute  tolerance        |

| qgl_is_zero                          | to test if a REAL number is less    |

|                                      | than the relative  tolerance        |

| qgl_get_world_size                   | to obtain the world size parameter  |

| qgl_put_world_size                   | to set the world size parameter     |

------------------------------------------------------------------------------

 

When using functions from this group, include the header file  qgldefs.h. 

 

Point and Vector Construction

-----------------------------

 

The following functions create and initialize points  and vectors:

 

______________________________________________________________________________

| Function                             | Use                                 |

|----------------------------------------------------------------------------|

| c2d_point                            | to create a point                   |

| c2d_free_point                       | to free a point                     |

| c2v_set_zero                         | to set a vector to zero             |

| c2v_set                              | to set the coordinates of a vector  |

|                                      |                                     |

------------------------------------------------------------------------------

 

A point or vector may be created by declaring an automatic variable  of type

PT2 or by calling c2d_point.  If a point or  vector created by c2d_point is

no longer needed, it must be  freed with c2d_free_point.

 

When using functions from this group, include the header  file c2ddefs.h or

c2vdefs.h, depending on the prefix.

 

The following functions construct points and vectors  from other points and

vectors:

 

______________________________________________________________________________

| Function                             | Use                                 |

|----------------------------------------------------------------------------|

| c2v_copy                             | to copy a point or a vector         |

| c2v_negate                           | to construct a vector which has     |

|                                      | the reverse direction of a  vector  |

|                                      |                                     |

| c2v_mid_pt                           | to construct the midpoint between   |

|                                      | two points                          |

| c2v_normal                           | to compute the 90 degree            |

|                                      | counter-clockwise rotation of a     |

|                                      | vector                              |

| c2v_project_line                     | to project a point onto a line      |

|                                      | defined by two points               |

| c2v_offset                           | to construct the point at a given   |

|                                      | distance from a point in  a         |

|                                      | direction 90 degrees                |

|                                      | counter-clockwise to a given        |

|                                      | direction                           |

------------------------------------------------------------------------------

 

The following functions normalize vectors:

 

______________________________________________________________________________

| Function                             | Use                                 |

|----------------------------------------------------------------------------|

| c2v_normalize                        | to normalize a vector               |

| c2v_normalize_l1                     | to divide the components of a       |

|                                      | vector by its "Manhattan length";   |

|                                      | produces a vector that              |

|                                      | approximately has unit length       |

------------------------------------------------------------------------------

 

The following functions transform points and vectors:

 

______________________________________________________________________________

| Function                             | Use                                 |

|----------------------------------------------------------------------------|

| c2v_mirror                           | to mirror a point about a line      |

|                                      | defined by two points               |

| c2v_scale                            | to multiply a vector by a scalar    |

| c2v_rotate_vec                       | to rotate a vector about the        |

|                                      | origin                              |

| c2v_rotate_vec_cs                    | to rotate a vector about the        |

|                                      | origin given the cosine and sine    |

|                                      | of the rotation angle               |

| c2v_rotate_pt                        | to rotate a vector about a point    |

| c2v_rotate_pt_cs                     | to rotate a vector about a point    |

|                                      | given the cosine and the  sine of   |

|                                      | the rotation angle                  |

------------------------------------------------------------------------------

 

When using point and vector construction routines, include the  header file

c2vdefs.h.

 

Point and Vector Evaluation

---------------------------

 

The following functions compute distances between  points and lengths of

vectors:

 

______________________________________________________________________________

| Function                             | Use                                 |

|----------------------------------------------------------------------------|

| c2v_is_small                         | to determine if a vector has        |

|                                      | length less than absolute           |

|                                      | tolerance                           |

| c2v_ident_pts                        | to determine if two points are      |

|                                      | identical                           |

| c2v_norm                             | to determine the length of a        |

|                                      | vector                              |

| c2v_norm_squared                     | to determine the square of the      |

|                                      | length of a vector                  |

| c2v_norml1                           | to estimate the length of a         |

|                                      | vector; this length is often        |

|                                      | termed  the "Manhattan length"      |

| c2v_dist                             | to determine the distance between   |

|                                      | two points                          |

| c2v_distl1                           | to determine the "Manhattan         |

|                                      | distance" between two points        |

| c2v_dist_squared                     | to determine the square of the      |

|                                      | distance between two points         |

------------------------------------------------------------------------------

 

When using functions from this group, include the header file  c2vdefs.h.

 

The following functions compute angles related to  vectors:

 

______________________________________________________________________________

| Function                             | Use                                 |

|----------------------------------------------------------------------------|

| c2v_vecs_angle                       | to determine the angle between two  |

|                                      | vectors                             |

| c2v_vecs_cos                         | to determine the cosine of the      |

|                                      | angle between two vectors           |

| c2v_vecs_sin                         | to determine the sine of the angle  |

|                                      | between two vectors                 |

| c2v_vecs_parallel                    | to determine if two vectors are     |

|                                      | parallel                            |

------------------------------------------------------------------------------

 

When using functions from this group, include c2vdefs.h. 

 

Vector Addition and Multiplication

----------------------------------

 

The following functions perform vector addition:

 

______________________________________________________________________________

| Function                             | Use                                 |

|----------------------------------------------------------------------------|

| c2v_add                              | to add two vectors                  |

| c2v_addt                             | to compute the sum of a vector and  |

|                                      | a multiple of another  vector       |

| c2v_addw                             | to compute the weighted sum of two  |

|                                      | vectors                             |

| c2v_addu                             | to compute the convex combination   |

|                                      | of two vectors                      |

| c2v_sub                              | to subtract two vectors             |

------------------------------------------------------------------------------

 

The following functions perform vector multiplication:

 

______________________________________________________________________________

| Function                             | Use                                 |

|----------------------------------------------------------------------------|

| c2v_dot                              | to compute the dot product of two   |

|                                      | vectors                             |

| c2v_cross                            | to compute the cross product of     |

|                                      | two vectors                         |

------------------------------------------------------------------------------

 

When using functions from these groups, include the header  file c2vdefs.h.

 

Curve Construction

------------------

 

The following functions create single-segment curves:

 

______________________________________________________________________________

| Function                             | Use                                 |

|----------------------------------------------------------------------------|

| c2d_line                             | to construct a line defined by two  |

|                                      | points                              |

| c2d_line_dir                         | to construct a line defined by a    |

|                                      | point and a direction  vector       |

| c2d_ray                              | to construct a line defined by a    |

|                                      | point and an angle                  |

| c2d_arc                              | to construct an arc defined by a    |

|                                      | center, radius, start  angle,       |

|                                      | sweep angle and direction           |

| c2d_arc_3pts                         | to construct an arc passing         |

|                                      | through three points                |

| c2d_arc_ctr_2pts                     | to construct an arc with a given    |

|                                      | center, starting at one point,      |

|                                      | and ending at another               |

| c2d_circle                           | to construct a circle defined by a  |

|                                      | center point and a radius           |

| c2d_circle_ctr_pt                    | to construct a circle defined by a  |

|                                      | center point and a point  on the    |

|                                      | circle                              |

------------------------------------------------------------------------------

 

The following functions create polycurves:

 

______________________________________________________________________________

| Function                             | Use                                 |

|----------------------------------------------------------------------------|

| c2d_pcurve_init                      | to create an empty polycurve        |

| c2d_pcurve_through                   | to create a polycurve through a     |

|                                      | set of points                       |

| c2d_pcurve_add_arc_2pts              | to add an arc to the end of a       |

|                                      | polycurve starting at the end       |

|                                      | point, and passing through two      |

|                                      | given points                        |

| c2d_pcurve_add_arc_tan               | to add an arc to the end of a       |

|                                      | polycurve tangent to the  endpoint  |

|                                      | and ending at a specified point     |

| c2d_pcurve_add_line                  | to add a line segment to the end    |

|                                      | of a polyline                       |

| c2d_pcurve_add_line_tan              | to add a line to the end of a       |

|                                      | polycurve tangent to the  end       |

|                                      | point, and ending at a specified    |

|                                      | point                               |

| c2d_pcurve_remove_last               | to remove the last segment from a   |

|                                      | polycurve                           |

| c2d_pcurve_close                     | to add a segment to close a         |

|                                      | polycurve                           |

------------------------------------------------------------------------------

 

The function c2d_pcurve_segment creates a C2_CURVE object from  a specified

segment of a 2D polycurve.

 

The following functions, which create ellipses and  splines, are available

only when the symbol SPLINE is defined:

 

______________________________________________________________________________

| Function                             | Use                                 |

|----------------------------------------------------------------------------|

| c2d_ellipse                          | to construct an ellipse             |

| c2d_spline                           | to construct a spline               |

| c2d_spline_knots                     | to construct a spline with a        |

|                                      | specific parameterization           |

| c2d_spline_tan                       | to construct a spline with          |

|                                      | specific start and end tangent      |

|                                      | conditions                          |

| c2d_spline_clsd                      | to construct a closed spline        |

------------------------------------------------------------------------------

 

When curves are created, memory is allocated dynamically.   Accordingly, the

memory they occupy must be freed whey they are no  longer needed. The routine

c2d_free_curve is provided for this  purpose. Do not use the routine free to

free curves.

 

When using functions from this group, include the header  file c2ddefs.h.

 

The following functions create and initialize curve  parameter objects.

 

______________________________________________________________________________

| Function                             | Use                                 |

|----------------------------------------------------------------------------|

| ald_parm                             | to create a parameter record        |

| ald_parm_t                           | to create a parameter record        |

|                                      | initialized to parameter value  t   |

| ald_parm_copy                        | to copy a parameter record          |

| ald_parm_free                        | to free a parameter record          |

------------------------------------------------------------------------------

 

When using curve parameter functions, include the header file  alddefs.h.

 

Curve Copying

-------------

 

The following functions copy curves.  Most of the  functions also alter the

copy:

 

______________________________________________________________________________

| Function                             | Use                                 |

|----------------------------------------------------------------------------|

| c2d_copy                             | to create a copy of a curve         |

| c2d_translate                        | to create a translated copy a       |

|                                      | curve                               |

| c2d_rotate                           | to create a rotated copy of a       |

|                                      | curve                               |

| c2d_rotate_cs                        | to create a rotated copy of a       |

|                                      | curve; the rotation angle  is       |

|                                      | specified by the cosine and the     |

|                                      | sine of the rotation angle; use     |

|                                      | this  routine when rotating a       |

|                                      | number of curves by the same angle  |

|                                      | to avoid  unnecessary calls to the  |

|                                      | sin and cos functions               |

| c2d_scale                            | to create a scaled copy of a curve  |

| c2d_mirror_line                      | to create a curve which is the      |

|                                      | mirror image of a curve about  a    |

|                                      | line                                |

| c2d_mirror_dir                       | to create a curve which is the      |

|                                      | mirror image of a curve about  an   |

|                                      | axis defined by a point and a       |

|                                      | direction                           |

| c2d_transform                        | to create a transformed copy of a   |

|                                      | curve                               |

------------------------------------------------------------------------------

 

The following functions create offset curves:

 

______________________________________________________________________________

| Function                             | Use                                 |

|----------------------------------------------------------------------------|

| c2d_offset                           | to create a curve offset from a     |

|                                      | curve by a given distance           |

| c2d_offset_curve                     | to create a curve offset from a     |

|                                      | curve by a given distance;          |

|                                      | accepts only line and arc curves    |

| c2d_offset_through                   | to create a curve offset from a     |

|                                      | curve, passing through a  given     |

|                                      | point                               |

| c2d_offset_curve_through             | to create a curve offset from a     |

|                                      | curve, passing through a  given     |

|                                      | point ; accepts only line and arc   |

|                                      | curves                              |

------------------------------------------------------------------------------

 

The following functions create trimmed copies of  curves:

 

______________________________________________________________________________

| Function                             | Use                                 |

|----------------------------------------------------------------------------|

| c2d_trim0                            | to create a curve by copying a      |

|                                      | curve and trimming away the         |

|                                      | "start portion" of the copy; the    |

|                                      | portion of the copy from the        |

|                                      | trimming  point to the end point    |

|                                      | is retained; the trimming point is  |

|                                      | specified  with a parameter record  |

| c2d_trim1                            | to create a curve by copying a      |

|                                      | curve and trimming away the  "end   |

|                                      | portion" of the copy; the portion   |

|                                      | of the copy from the start  point   |

|                                      | to the trimming point is retained;  |

|                                      | the trimming point is specified     |

|                                      | with a parameter record             |

| c2d_trim                             | to create a curve by copying a      |

|                                      | curve and trimming away both  ends  |

|                                      | of the copy; the portion of the     |

|                                      | copy between the trimming  points   |

|                                      | is retained; the trimming points    |

|                                      | are specified with parameter        |

|                                      | records                             |

| c2d_trim_t0                          | to create a curve by copying a      |

|                                      | curve and trimming away the         |

|                                      | "start portion" of the copy; the    |

|                                      | portion of the copy from the        |

|                                      | trimming  point to the end point    |

|                                      | is retained; the trimming point is  |

|                                      | specified  with a parameter value   |

| c2d_trim_t1                          | to create a curve by copying a      |

|                                      | curve and trimming away the  "end   |

|                                      | portion" of the copy; the portion   |

|                                      | of the copy from the start  point   |

|                                      | to the trimming point is retained;  |

|                                      | the trimming point is specified     |

|                                      | with a parameter value              |

| c2d_trim_t                           | to create a curve by copying a      |

|                                      | curve and trimming away both  ends  |

|                                      | of the copy; the portion of the     |

|                                      | copy between the trimming  points   |

|                                      | is retained; the trimming points    |

|                                      | are specified with parameter        |

|                                      | values                              |

------------------------------------------------------------------------------

 

When using functions from these groups, include the header file  c2ddefs.h.

 

Curve Modification

------------------

 

Curve modification consists of transformation and trimming.

 

The following functions transform curves:

 

______________________________________________________________________________

| Function                             | Use                                 |

|----------------------------------------------------------------------------|

| c2c_translate                        | to translate a curve                |

| c2c_rotate                           | to rotate a curve                   |

| c2c_rotate_cs                        | to rotate a curve; a special        |

|                                      | version intended to make  multiple  |

|                                      | rotations of a curve more           |

|                                      | efficient                           |

| c2c_scale                            | to scale a curve                    |

| c2c_mirror_line                      | to mirror a curve about a line      |

| c2c_mirror_dir                       | to mirror a curve about an axis     |

|                                      | defined by a point and  a           |

|                                      | direction                           |

| c2c_transform                        | to transform a curve                |

------------------------------------------------------------------------------

 

The following functions trim a curve:

 

______________________________________________________________________________

| Function                             | Use                                 |

|----------------------------------------------------------------------------|

| c2c_trim0                            | to trim away the "start portion"    |

|                                      | of a curve; the portion of  the     |

|                                      | curve from the trimming point to    |

|                                      | the end point is retained; the      |

|                                      | trimming point is specified with a  |

|                                      | parameter record                    |

| c2c_trim1                            | to trim away the "end portion" of   |

|                                      | a curve; the portion of  the curve  |

|                                      | from the start point to the         |

|                                      | trimming point is retained; the     |

|                                      | trimming point is specified with a  |

|                                      | parameter record                    |

| c2c_trim                             | to trim away both ends of a curve;  |

|                                      | the portion of the curve  between   |

|                                      | the trimming points is retained;    |

|                                      | the trimming points are  specified  |

|                                      | with parameter records              |

| c2c_trim_t0                          | to trim away the "start portion"    |

|                                      | of a curve; the portion of  the     |

|                                      | curve from the trimming point to    |

|                                      | the end point is retained; the      |

|                                      | trimming point is specified with a  |

|                                      | parameter value                     |

| c2c_trim_t1                          | to trim away the "end portion" of   |

|                                      | a curve; the portion of  the curve  |

|                                      | from the start point to the         |

|                                      | trimming point is retained; the     |

|                                      | trimming point is specified with a  |

|                                      | parameter value                     |

| c2c_trim_t                           | to trim away both ends of a curve;  |

|                                      | the portion of the curve  between   |

|                                      | the trimming points is retained;    |

|                                      | the trimming points are  specified  |

|                                      | with parameter values               |

------------------------------------------------------------------------------

 

When using curve modification functions, include the header file  c2cdefs.h.

 

Curve Evaluation

----------------

 

The following functions compute points, tangent  vectors, and other

information about curves:

 

______________________________________________________________________________

| Function                             | Use                                 |

|----------------------------------------------------------------------------|

| c2c_eval                             | to compute the coordinates and a    |

|                                      | number of derivatives at a  point   |

| c2c_eval_pt                          | to compute or to evaluate the       |

|                                      | coordinates of a point on a  curve  |

|                                      | specified by a curve parameter      |

|                                      | record                              |

| c2c_eval_tan                         | to evaluate a tangent vector of a   |

|                                      | curve at a location  specified by   |

|                                      | a curve parameter record            |

| c2c_eval_pt_tan                      | to evaluate the coordinates and     |

|                                      | the tangent vector of a curve  at   |

|                                      | a location specified by a curve     |

|                                      | parameter record                    |

| c2c_ept0                             | to compute the coordinates of the   |

|                                      | start point of a curve              |

| c2c_etan0                            | to evaluate the tangent vector at   |

|                                      | the start point of a curve          |

| c2c_ept_tan0                         | to evaluate the coordinates and     |

|                                      | the tangent vector at the  start    |

|                                      | point of a curve                    |

| c2c_ept1                             | to evaluate the coordinates of the  |

|                                      | end point of a curve                |

| c2c_etan1                            | to evaluate the tangent vector at   |

|                                      | the end point of a curve            |

| c2c_ept_tan1                         | to evaluate the coordinates and     |

|                                      | the tangent vector at the  end      |

|                                      | point of a curve                    |

| c2c_closed                           | to determine if a curve is closed   |

| c2c_coord_extrs                      | to locate the coordinates of curve  |

|                                      | extrema                             |

| c2c_length                           | to compute the length of a curve    |

| c2c_curvature                        | to evaluate the curvature of a      |

|                                      | curve at a location specified  by   |

|                                      | a curve parameter record            |

| c2c_project                          | to project a point onto a curve;    |

|                                      | this routine should be used  to     |

|                                      | generate the curve parameter        |

|                                      | record corresponding to a  given    |

|                                      | point on a curve                    |

| c2c_select                           | to check if a point lies within a   |

|                                      | given distance from a curve         |

| c2c_info_curve                       | to print information about a curve  |

------------------------------------------------------------------------------

 

When using curve evaluation functions, include the header file  c2cdefs.h.

 

The following functions compute the center and contact  points of fillet

arcs:

 

arc and the curve paramters of the contact points on the filleted  curves

 

arc and the curve paramters of the contact points on the filleted  curves;

curves must form a sharp corner

 

The following functions compute information about curves  which are arcs,

circles and ellipses.

 

______________________________________________________________________________

| Function                             | Use                                 |

|----------------------------------------------------------------------------|

| c2c_get_arc_data                     | to obtain the center, radius,       |

|                                      | start angle, sweep and direction    |

|                                      | of an arc                           |

| c2c_get_arc_radius                   | to obtain the radius of an arc      |

| c2c_get_arc_center                   | to obtain the center point of an    |

|                                      | arc                                 |

| c2c_get_arc_start_angle              | to obtain the start angle of an     |

|                                      | arc; the result is in radians       |

| c2c_get_arc_sweep                    | to obtain the sweep of an arc; the  |

|                                      | result is in radians                |

| c2c_get_arc_dir                      | to obtain the direction of an arc;  |

|                                      | +1 is counter-clockwise;  -1 is     |

|                                      | clockwise                           |

| c2c_arc_angle                        | to obtain the angle on an arc       |

|                                      | corresponding to a parameter        |

| c2c_arc_parm                         | to obtain the parameter on an arc   |

|                                      | corresponding to an angle           |

| c2c_get_ellipse_data                 | to obtain the center, major and     |

|                                      | minor axes, start angle,  sweep     |

|                                      | and direction of an ellipse;        |

|                                      | available only if SPLINE  is        |

|                                      | defined                             |

| c2c_get_pcurve_data                  | to obtain information about a       |

|                                      | specified segment of a  polycurve   |

------------------------------------------------------------------------------

 

Include c2cdefs.h when using arc, ellipse and polycurve  information

routines.

 

The following functions create linear interpolations,  or "polygonal

approximations", of 2D curves.  The precision of  interpolation is controlled

by a specified maximum chordal deviation  from the exact mathematical

representation of the curve being  approximated:

 

______________________________________________________________________________

| Function                             | Use                                 |

|----------------------------------------------------------------------------|

| c2c_approx                           | to compute a linear approximation   |

|                                      | of a curve                          |

| c2c_approx_init                      | to initialize a linear              |

|                                      | approximation of a curve            |

------------------------------------------------------------------------------

 

The following function locate points where curves  intersect:

 

______________________________________________________________________________

| Function                             | Use                                 |

|----------------------------------------------------------------------------|

| c2c_intersect                        | to intersect two curves             |

| c2c_intersect_ext                    | to intersect two curves, treating   |

|                                      | lines as infinite lines  and arcs   |

|                                      | as full circles                     |

| c2c_self_intersect                   | to find self intersections;         |

|                                      | applies only to splines and         |

|                                      | polycurves                          |

| c2c_intersect_line_or_arc            | to intersect lines and arcs         |

| c2c_intersect_line_or_arc_ext        | to intersect infinite lines and     |

|                                      | full circles                        |

| c2d_free_int_rec                     | to free an intersection record      |

| c2c_info_int_rec                     | to print information about an       |

|                                      | intersection record.                |

------------------------------------------------------------------------------

 

Include c2ddefs.h when using c2d_free_int_rec. Include  c2cdefs.h when using

the other functions.

 

The routines c2c_intersect and c2c_intersect_ext  intersect curves of any

type. The results of intersections are  returned in intersection records that

are on an "intersection result  list". Intersection records contain:

 

* the coordinates of the intersection point

 

* the parameters on each of the intersecting curves where  the intersection

  occurred

 

* whether the intersection is transverse, tangent or collinear

 

The information in these records may be accessed by "walking" the

intersection result list and applying access macros to the  intersection

records. The function c2c_info_int_rec prints  information about an

intersection on the screen.

 

Routines c2c_intersect_line_or_arc and  c2c_intersect_line_or_arc_ext are a

departure from the CCDK/2D  object-oriented approach for the convenience of

programmers who are  using lines and arcs only.  These routines return

intersection  information directly as arguments rather than on an

intersection  result list, simplifying the process of obtaining information

about  intersections. 

 

Bounding Box Operations

-----------------------

 

These functions perform curve bounding box operations.

 

______________________________________________________________________________

| Function                             | Use                                 |

|----------------------------------------------------------------------------|

| c2a_box                              | to create a bounding box            |

| c2a_free_box                         | to free a bounding box              |

| c2a_box_append                       | to expand a bounding box to         |

|                                      | include another bounding box        |

| c2a_box_append_pt                    | to expand a bounding box to         |

|                                      | include a point                     |

| c2a_box_copy                         | to copy a bounding box              |

| c2a_box_init_pt                      | to initialize a bounding box to a   |

|                                      | point                               |

| c2a_box_poly                         | to build a bounding box that        |

|                                      | contains an array of points         |

| c2a_box_union                        | to create a bounding box that       |

|                                      | contains two bounding boxes         |

| c2a_box_overlap                      | to test if two bounding boxes       |

|                                      | overlap                             |

------------------------------------------------------------------------------

 

When using functions from this group, include the header  file c2adefs.h.

 

Transform Construction and Evaluation

-------------------------------------

 

The following functions create and modify 2D transforms:

 

______________________________________________________________________________

| Function                             | Use                                 |

|----------------------------------------------------------------------------|

| c2t_create                           | to create a identity transform      |

| c2t_lcs                              | to compute a transform for          |

|                                      | transforming objects from the       |

|                                      | global coordinate system to a       |

|                                      | local coordinate system             |

| c2t_mirror_line                      | to construct a 2D transform for     |

|                                      | mirroring                           |

| c2t_rotate                           | to construct a 2D transform for     |

|                                      | rotating                            |

| c2t_rotate_cs                        | to construct a 2D transform for     |

|                                      | rotating; the rotation angle  is    |

|                                      | specified with it cosine and sine   |

| c2t_scale                            | to construct a 2D transform for     |

|                                      | scaling                             |

| c2t_translate                        | to construct a 2D transform for     |

|                                      | translation                         |

| c2t_inverse                          | to compute the inverse of a         |

|                                      | transform                           |

| c2t_mult                             | to multiply two transforms          |

| c2t_orthogonal                       | to determine if a transform is      |

|                                      | orthogonal                          |

| c2t_free                             | to free a transform                 |

------------------------------------------------------------------------------

 

The following functions transform points and vectors:

 

______________________________________________________________________________

| Function                             | Use                                 |

|----------------------------------------------------------------------------|

| c2t_eval_pt                          | to transform a point                |

| c2t_eval_vec                         | to transform a vector               |

------------------------------------------------------------------------------

 

When using transform functions, include the header file  c2tdefs.h.

 

Alphabetized Reference

======================

 

***>> ald_parm <<***

 

****** Summary ******

 

#include <alddefs.h>

 

PARM ald_parm();

 

****** Description ******

 

This function creates an unitialized parameter record.

 

****** Return Value ******

 

The return value is a pointer to a parameter record.  If memory  could not be

allocated, NULL is returned.

 

****** Example ******

 

#include <alddefs.h>

 

void main()

{

      PARM parm = ald_parm();

      SET_PARM ( 0.5, parm );

      ald_parm_free ( parm );

}

This program creates and frees a parameter record.

 

***>> ald_parm_copy <<***

 

****** Summary ******

 

#include <alddefs.h>

 

PARM ald_parm_copy ( p1, p2 );

 

****** Description ******

 

This function copies the contents of one parameter record to another.

 

****** Input ******

 

------------------------------------------------------------------------------

| PARM                   | p1                 | parameter record to copy;    |

|                        |                    | source                       |

------------------------------------------------------------------------------

| PARM                   | p2                 | parameter record to copy     |

|                        |                    | into; target; must be        |

|                        |                    | allocated or  declared as an  |

|                        |                    | automatic variable structure  |

------------------------------------------------------------------------------

 

****** Example ******

 

#include <alddefs.h>

 

void main()

{

      PARM_S p1, p2;

      PARM_SET ( 0.1, &p1 );

      ald_parm_copy ( &p1, &p2 );

      printf ( "%lf\n", PARM_T(&p2) );

}

This program initializes a parameter record, and then copies it to  another

parameter record.

 

***>> ald_parm_free <<***

 

****** Summary ******

 

#include <alddefs.h>

 

void ald_parm_free ( parm );

 

****** Description ******

 

This function frees a parameter record.  Use this function to free  only

parameter record created with ald_parm or  ald_parm_t.

 

****** Input ******

 

------------------------------------------------------------------------------

| PARM                   | parm               | a parameter record           |

------------------------------------------------------------------------------

 

****** Example ******

 

#include <alddefs.h>

 

void main()

{

      PARM parm = ald_parm_t ( 0.5 );

      ald_parm_free ( parm );

}

This program creates and frees a parameter record.

 

***>> ald_parm_t <<***

 

****** Summary ******

 

#include <alddefs.h>

 

PARM ald_parm_t ( t );

 

****** Description ******

 

This function creates a parameter record initialized to a given  parameter

value.

 

****** Input ******

 

------------------------------------------------------------------------------

| REAL                   | t                  | a parameter value            |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a pointer to a parameter record initialized to  the given

parameter value.

 

****** Example ******

 

#include <alddefs.h>

 

void main()

{

      PARM parm = ald_parm_t ( 0.5 );

      ald_parm_free ( parm );

}

This program creates a parameter record initialized to 0.5, and then  frees

it.

 

***>> ATAN2 <<***

 

****** Summary ******

 

#include <qgldefs.h>

 

ATAN2 ( y, x );

 

****** Description ******

 

This macro computes the angle defined by the specified "rise" and  "run".

The returned value is between 0 and two pi.  The standard  C routine atan2

returns an angle between -pi and pi.

 

****** Input ******

 

------------------------------------------------------------------------------

| REAL                   | y, x               | the "rise" and "run" of the  |

|                        |                    | angle                        |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the angle in radians defined by the specified  "rise" and

"run".

 

****** Example ******

 

#include <qgldefs.h>

 

void main()

{

      REAL rise = 4.0, run = 7.0;

      printf ( "%lf\n", ATAN2(rise,run) );

}

This program computes the angle defined by a specified rise and run.

 

***>> c2a_box <<***

 

****** Summary ******

 

#include <c2adefs.h>

 

C2_BOX c2a_box ( min_pt, max_pt );

 

****** Description ******

 

This function creates a bounding box initialized to the rectangle

represented by two given points.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | min_pt, max_pt     | the lower left and upper     |

|                        |                    | right corner points of the   |

|                        |                    | bounding  box; if either is  |

|                        |                    | NULL, the bounding box is    |

|                        |                    | created, but not             |

|                        |                    | initialized                  |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a pointer to a bounding box.  If memory could  not be

allocated, NULL is returned.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2adefs.h>

 

void main()

{

      PT2 p0, p1;

      C2_BOX box;

      c2v_set ( 2.0, 3.0, p0 );

      c2v_set ( 5.0, 6.0, p1 );

      box = c2a_box ( p0, p1 );

      c2a_free_box ( box );

}

This program creates a bounding box with corners (2,3)  and (5,6).

 

***>> c2a_box_append  <<***

 

****** Summary ******

 

#include <c2adefs.h>

 

C2_BOX c2a_box_append ( box, append_box );

 

****** Description ******

 

This routine expands a bounding box to include another bounding box.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_BOX                 | box                | the box to expand            |

------------------------------------------------------------------------------

| C2_BOX                 | append_box         | the box fitted into the      |

|                        |                    | expanded box                 |

------------------------------------------------------------------------------

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2adefs.h>

 

void main()

{

      PT2 p0, p1;

      C2_BOX box0, box1;

      c2v_set ( 2.0, 3.0, p0 );

      c2v_set ( 5.0, 6.0, p1 );

      box0 = c2a_box ( p0, p1 );

      c2v_set ( 3.0, 4.0, p0 );

      c2v_set ( 7.0, 8.0, p1 );

      box1 = c2a_box ( p0, p1 );

      c2a_box_append ( box0, box1 );

}

This program creates two bounding boxes and then expands  the first to

include the second. 

 

***>> c2a_box_append_pt  <<***

 

****** Summary ******

 

#include <c2adefs.h>

 

C2_BOX c2a_box_append_pt ( box, pt );

 

****** Description ******

 

This function expands a bounding box to include a point.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_BOX                 | box                | the box to expand            |

------------------------------------------------------------------------------

| PT2                    | pt                 | a point                      |

------------------------------------------------------------------------------

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2adefs.h>

 

void main()

{

      PT2 p0, p1, p;

      C2_BOX box0;

      c2v_set ( 2.0, 3.0, p0 );

      c2v_set ( 5.0, 6.0, p1 );

      box0 = c2a_box ( p0, p1 );

      c2v_set ( 7.0, 8.0, p );

      c2a_box_append_pt ( box0, p );

}

This program expands a bounding box to include a point.

 

***>> c2a_box_copy  <<***

 

****** Summary ******

 

#include <c2adefs.h>

 

C2_BOX c2a_box_copy ( box0, box1 );

 

****** Description ******

 

This function copies a bounding box.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_BOX                 | box0               | the box to copy              |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| C2_BOX                 | box1               | the copy; this box must be   |

|                        |                    | created by the caller        |

------------------------------------------------------------------------------

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2adefs.h>

 

void main()

{

      PT2 p0, p1, origin;

      C2_BOX box0, box1 ;

      c2v_set ( 0.0, 0.0, origin );

      box1 = c2a_box ( origin, origin );

      c2v_set ( 2.0, 3.0, p0 );

      c2v_set ( 5.0, 6.0, p1 );

      box0 = c2a_box ( p0, p1 );

      c2a_box_copy ( box0, box1 );

}

This program makes box1 a copy of box0.

 

***>> c2a_box_init_pt  <<***

 

****** Summary ******

 

#include <c2adefs.h>

 

C2_BOX c2a_box_init_pt ( box, pt );

 

****** Description ******

 

This function initializes the lower left and upper right corners of  a

bounding box to the same point.  The result is a rectangle with  zero area.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_BOX                 | box                | the box to initialize        |

------------------------------------------------------------------------------

| PT2                    | pt                 | the point to initialize the  |

|                        |                    | box to                       |

------------------------------------------------------------------------------

 

****** Example ******

 

#include <c2adefs.h>

#include <c2vdefs.h>

 

void main()

{

      PT2 p;

      C2_BOX box = c2a_box ( NULL, NULL );

      c2v_set ( 2.0, 3.0, p );

      c2a_box_init_pt ( box, p );

      c2a_free_box ( box );

}

This program creates a bounding box with both corners  (2.0,3.0).

 

***>> c2a_box_overlap  <<***

 

****** Summary ******

 

#include <c2adefs.h>

 

BOOLEAN c2a_box_overlap ( box1, box2 );

 

****** Description ******

 

This routine determines if two bounding boxes overlap.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_BOX                 | box1, box2         | the bounding boxes to test   |

|                        |                    | for overlap                  |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is TRUE if the boxes overlap; it is FALSE  otherwise.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2adefs.h>

 

void main()

{

      PT2 p0, p1;

      C2_BOX box0, box1;

      c2v_set ( 2.0, 3.0, p0 );

      c2v_set ( 5.0, 6.0, p1 );

      box0 = c2a_box ( p0, p1 );

      c2v_set ( 3.0, 4.0, p0 );

      c2v_set ( 7.0, 8.0, p1 );

      box1 = c2a_box ( p0, p1 );

      if ( c2a_box_overlap ( box0, box1 ) )

            printf ( "boxes overlap\n" );

      c2a_free_box ( box0 );

      c2a_free_box ( box1 );

}

This program tests two bounding boxes to determine if  they overlap, and

returns TRUE in this particular example.

 

***>> c2a_box_poly  <<***

 

****** Summary ******

 

#include <c2adefs.h>

 

C2_BOX c2a_box_poly ( a, d, box );

 

****** Description ******

 

This function computes the bounding box that encloses an array of  points.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2 *                  | a                  | the array of points          |

------------------------------------------------------------------------------

| INT                    | d                  | the number of points in the  |

|                        |                    | array                        |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| C2_BOX                 | box                | the bounding box that        |

|                        |                    | contains all of the points   |

------------------------------------------------------------------------------

 

****** Example ******

 

#include <c2adefs.h>

#include <c2vdefs.h>

 

void main()

{

      PT2 p[4];

      C2_BOX box = c2a_box ( NULL, NULL );

      c2v_set ( 2.0, 3.0, p[0] );

      c2v_set ( 5.0, 6.0, p[1] );

      c2v_set ( 3.0, 4.0, p[2] );

      c2v_set ( 7.0, 8.0, p[3] );

      c2a_box_poly ( p, 4, box );

      c2a_free_box ( box );

}

This program creates a bounding box that encloses four  points.

 

***>> c2a_box_union  <<***

 

****** Summary ******

 

#include <c2adefs.h>

 

C2_BOX c2a_box_union ( box1, box2, box );

 

****** Description ******

 

This function computes the smallest bounding box that encloses two bounding

boxes.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_BOX                 | box1, box2         | the boxes to enclose         |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| C2_BOX                 | box                | the box that contains both   |

|                        |                    | input boxes                  |

------------------------------------------------------------------------------

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2adefs.h>

 

void main()

{

      PT2 p0, p1;

      C2_BOX box0, box1, box;

      c2v_set ( 2.0, 3.0, p0 );

      c2v_set ( 5.0, 6.0, p1 );

      box0 = c2a_box ( p0, p1 );

      c2v_set ( 3.0, 4.0, p0 );

      c2v_set ( 7.0, 8.0, p1 );

      box1 = c2a_box ( p0, p1 );

      box = c2a_box ( NULL, NULL );

      c2a_box_union ( box0, box1, box );

      c2a_free_box ( box );

      c2a_free_box ( box0 );

      c2a_free_box ( box1 );

}

This program computes the bounding box that encloses two  boxes.

 

***>> c2a_box_w_overlap  <<***

 

****** Summary ******

 

#include <c2adefs.h>

 

BOOLEAN c2a_box_w_overlap ( box1, box2, w );

 

****** Description ******

 

This function determines if two boxes are less than a given distance  apart.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_BOX                 | box1, box2         | the boxes to test            |

------------------------------------------------------------------------------

| REAL                   | w                  | the separation distance      |

------------------------------------------------------------------------------

 

****** Return Value ******

 

If the boxes overlap or are separated by a distance less than the  given

distance, the return value is TRUE; otherwise it is FALSE.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2adefs.h>

 

void main()

{

      PT2 p0, p1;

      C2_BOX box0, box1;

      REAL w = 1.0;

      c2v_set ( 2.0, 3.0, p0 );

      c2v_set ( 5.0, 6.0, p1 );

      box0 = c2a_box ( p0, p1 );

      c2v_set ( 5.5, 6.5, p0 );

      c2v_set ( 7.0, 8.0, p1 );

      box1 = c2a_box ( p0, p1 );

      if ( c2a_box_w_overlap ( box0, box1, w ) )

            printf ( "boxes overlap or are less than 1 unit apart\n" );

      c2a_free_box ( box0 );

      c2a_free_box ( box1 );

}

This program determines if two bounding boxes overlap or  are less than 1

unit apart.

 

***>> c2a_free_box <<***

 

****** Summary ******

 

#include <c2adefs.h>

 

void c2a_free_box ( box );

 

****** Description ******

 

This function frees a bounding box.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_BOX                 | box                | the box to free              |

------------------------------------------------------------------------------

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2adefs.h>

 

void main()

{

      PT2 p0, p1;

      C2_BOX box0;

      c2v_set ( 2.0, 3.0, p0 );

      c2v_set ( 5.0, 6.0, p1 );

      box0 = c2a_box ( p0, p1 );

      c2a_free_box ( box0 );

}

This program creates and frees a bounding box.

 

***>> c2c_approx <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

BOOLEAN c2c_approx ( curve, parm1, marker_parm,  gran, dir, pt_buffer,

parm_buffer, buf_size, index );

 

****** Description ******

 

This function computes the vertices of a polygon that approximates a  curve.

The polygon does not deviate from the curve by more than a  specified

distance. 

 

If dir is TRUE, the polygon follows the curve away from its  start point and

toward its end point; otherwise the polygon follows  the curve in the

opposite direction.

 

The vertices of the polygon are stored in a caller-supplied array of  points.

 

 

If the number of points required for an approximating polygon is  greater

than the number that will fit into the array, this function  fills the array,

marks the location of the last point with  marker_parm, and returns FALSE to

indicate that the entire  polygon was not computed.  The next call to this

function begins the  approximating polygon at the location specified by

marker_parm.  Thus, if a polygon cannot be generated with one  call, it can

be generated with a number of successive calls.

 

When a curve is approximated with a series of calls to this  function, the

first point in a set of points is the last point of  the previous set.

 

Prior to generating a polygon with this function, the argument  marker_parm

should be initialized with the  c2c_approx_init function.

 

This function optionally computes the curve parameters that  correspond to

the vertices of the polygon.

 

This routines is very useful for applications such as graphics and  motion

control, where curved shapes must be approximated with short  lines.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a curve                      |

------------------------------------------------------------------------------

| PARM                   | parm1              | ending parameter record;     |

|                        |                    | points will not be computed  |

|                        |                    | past  this curve parameter;  |

|                        |                    | if NULL is supplied, the     |

|                        |                    | polygon will end at  the     |

|                        |                    | curve end point              |

------------------------------------------------------------------------------

| PARM                   | marker_parm        | the curve parameter at which  |

|                        |                    | to begin the polygonal       |

|                        |                    | approximation;  when the     |

|                        |                    | point and parameter arrays   |

|                        |                    | are full, this parameter     |

|                        |                    | record  marks where the next  |

|                        |                    | call to this function should  |

|                        |                    | begin                        |

------------------------------------------------------------------------------

| REAL                   | gran               | the maximum distance allowed  |

|                        |                    | between the curve and any    |

|                        |                    | chord  of the polygonal      |

|                        |                    | approximation                |

------------------------------------------------------------------------------

| INT                    | buf_size           | the size of the point and    |

|                        |                    | parameter record arrays;     |

|                        |                    | both arrays  must be the     |

|                        |                    | same size                    |

------------------------------------------------------------------------------

| BOOLEAN                | dir                | the direction that the       |

|                        |                    | polygonal approximation      |

|                        |                    | follows along  the curve;    |

|                        |                    | TRUE denotes along its       |

|                        |                    | natural direction; FALSE     |

|                        |                    | denotes  against its natural  |

|                        |                    | direction                    |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | *pt_buffer         | an array of points supplied  |

|                        |                    | by the caller; if NULL, no   |

|                        |                    | points  are computed         |

------------------------------------------------------------------------------

| PARM                   | parm_buffer        | an array of parameter        |

|                        |                    | records supplied by the      |

|                        |                    | caller; if  NULL, no         |

|                        |                    | parameters are computed      |

------------------------------------------------------------------------------

| INT *                  | index              | the number of points         |

|                        |                    | actually computed; this      |

|                        |                    | number is less  than size if  |

|                        |                    | the curve can be             |

|                        |                    | approximated adequately with  |

|                        |                    | fewer than  size points      |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is FALSE if there are more points to compute on the  curve.

A return value of TRUE indicates that the polygonal approximation  has

covered the entire curve, or it has reached the ending parameter,  if

specified.

 

****** Example ******

 

#include <c2cdefs.h>

 

void polygonalize ( curve, acc, direction )

C2_CURVE curve ;

REAL acc ;

BOOLEAN direction ;

{

      PT2 pt[10] ;

      PARM_S parm ;

      BOOLEAN end_flag ;

      INT i0, i, index ;

 

      c2c_approx_init ( curve, NULL, &parm, direction ) ;

      i0 = 0 ;

      do {

            end_flag = c2c_approx ( curve, NULL, &parm,

                  acc, direction, pt, NULL, 10, &index ) ;

            for ( i=i0 ; i<index ; i++ )

                  printf ( "%lf\t%lf\n", PT2_X(pt[i]),PT2_Y(pt[i]));

            i0 = 1 ;

      } while ( !end_flag ) ;

}

This routine generates the vertices of a polygon approximating a given  curve

within a specified accuracy and in the specified direction.  The  vertices

are generated in groups of ten.

 

***>> c2c_approx_init <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

void c2c_approx_init ( curve, parm0, marker_parm,  dir );

 

****** Description ******

 

This function initializes the process which creates a polygonal

approximation of a curve.

 

Use this function with c2c_approx.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a curve                      |

------------------------------------------------------------------------------

| PARM                   | parm0              | the curve parameter at which  |

|                        |                    | to begin the polygonal       |

|                        |                    | approximation; if NULL, the  |

|                        |                    | approximation begins at the  |

|                        |                    | start or  end point of the   |

|                        |                    | curve, depending on dir      |

------------------------------------------------------------------------------

| BOOLEAN                | dir                | the direction that the       |

|                        |                    | polygonal approximation      |

|                        |                    | should follow  along the     |

|                        |                    | curve; TRUE denotes with the  |

|                        |                    | natural direction, and FALSE  |

|                        |                    |  denotes against             |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PARM                   | marker_parm        | the marker parameter         |

|                        |                    | initialized to the curve     |

|                        |                    | location where  the          |

|                        |                    | polygonal approximation      |

|                        |                    | should begin                 |

------------------------------------------------------------------------------

 

****** Example ******

 

See c2c_approx

 

***>> c2c_arc_angle <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

BOOLEAN c2c_arc_angle ( curve, parm, angle ) ;

 

****** Description ******

 

This function computes the arc angle that corresponds to a specified  curve

parameter.  The angle is expressed relative to the start of  the arc, and in

radians.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | an arc                       |

------------------------------------------------------------------------------

| PARM                   | parm               | a curve parameter            |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| REAL *                 | angle              | the angle in radians that    |

|                        |                    | corresponds to the curve     |

|                        |                    | parameter                    |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is TRUE if the input curve is an arc; it is FALSE

otherwise.

 

****** Example ******

 

#include <c2cdefs.h>

 

void pr_arc_angle ( arc, parm )

C2_CURVE arc ;

PARM parm ;

{

      REAL angle;

 

      if ( c2c_arc_angle ( arc, parm, &angle ) )

            printf ( "angle: %lf\n", angle );

      else printf ( "Curve is not an arc\n" ) ;

}

 

This subroutine prints the arc angle corresponding to a curve  parameter.

 

***>> c2c_arc_parm <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

BOOLEAN c2c_arc_parm ( curve, angle, parm ) ;

 

****** Description ******

 

This function computes the curve parameter that corresponds to an  arc angle.

 The arc angle is measured relative to the start of the  arc.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | an arc                       |

------------------------------------------------------------------------------

| REAL                   | angle              | an arc angle expressed in    |

|                        |                    | radians                      |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PARM                   | parm               | the curve parameter that     |

|                        |                    | corresponds to the angle     |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is TRUE if the input curve is an arc; it is FALSE

otherwise.

 

****** Example ******

 

#include <c2cdefs.h>

 

void pr_arc_parm ( arc, angle )

C2_CURVE arc ;

REAL angle ;

{

      PARM_S parm_s;

      PARM parm = &parm_s;

 

      if ( c2c_arc_parm ( arc, angle, parm ) )

            printf ( "parameter: %lf\n", PARM_T(parm) );

      else printf ( "Curve is not an arc\n" ) ;

}

 

This subroutine prints the curve parameter corresponding to an arc  angle.

 

***>> c2c_closed <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

BOOLEAN c2c_closed ( curve );

 

****** Description ******

 

This function determines if a curve is closed, i.e. if its  start and end

points are coincident.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a curve                      |

------------------------------------------------------------------------------

 

****** Return Value. ******

 

This function returns TRUE if the curve is closed. Otherwise it returns

FALSE.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

#include <c2cdefs.h>

 

void main ()

{

      C2_CURVE curve ;

      PT2 ctr ;

      REAL radius, start_angle, sweep, x, y ;

 

      printf ( "Enter coordinates of arc center: " ) ;

      scanf ( "%lf %lf", &x, &y ) ;

      c2v_set ( x, y, ctr ) ;

      printf ( "Enter radius & start angle of arc: " ) ;

      scanf ( "%lf %lf", &radius, &start_angle ) ;

      printf ( "Enter sweep of arc: " ) ;

      scanf ( "%lf", &sweep ) ;

      sweep *= PI_OVER_180 ;

      curve = c2d_arc ( ctr, radius, start_angle, sweep, 1 ) ;

      printf ( "The curve is " ) ;

      if ( c2c_closed ( curve ) )

            printf ( "closed.\n" ) ;

      else printf ( "not closed.\n" ) ;

}

 

This program creates an arc with user-specified parameters, and  tests it to

determine if it is closed (i.e. in this case, it is  closed if its sweep is

TWO_PI)

 

***>> c2c_coord_extrs  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

INT c2c_coord_extrs ( curve, coord, extr_list );

 

****** Description ******

 

This function locates the extrema of a specified curve along a  specified

coordinate direction.  The extrema are reported by  extremum records appended

to a specified list.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a curve                      |

------------------------------------------------------------------------------

| INT                    | coord              | the coordinate axis of the   |

|                        |                    | extrema to locate; 0         |

|                        |                    | indicates  'x' and 1         |

|                        |                    | indicates 'y'                |

------------------------------------------------------------------------------

| DML_LIST               | extr_list          | the list to which extrema    |

|                        |                    | records are appended; this   |

|                        |                    | list  must be created by the  |

|                        |                    | caller                       |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the number of extrema located on the specified  curve.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

#include <dmldefs.h>

#include <c2cdefs.h>

 

void main()

{

      INT n ;

      C2_CURVE arc ;

      PT2 p1, p2, p3 ;

      DML_LIST extr_list ;

      DML_ITEM item ;

      C2_EXTR_REC xrec ;

 

      c2v_set ( SQRT_2, -SQRT_2, p1 ) ;

      c2v_set ( 0.0, 2.0, p2 ) ;

      c2v_set ( -SQRT_2, -SQRT_2, p3 ) ;

 

      arc = c2d_arc_3pts ( p1, p2, p3 ) ;

      /* Create a 270-degree arc */

      extr_list = dml_create_list();

      n = c2c_coord_extrs ( arc, 0, extr_list ) ;

            /* compute extrema of the x coordinate */

            printf ( "Extrema %d", n );

 

      DML_WALK_LIST ( extr_list, item ) {

            xrec = DML_RECORD(item) ;

            if ( C2_EXTR_REC_TYPE(xrec) == 1 )

                  printf ( "Maximum       " ) ;

            else if ( C2_EXTR_REC_TYPE(xrec) == -1 )

                  printf ( "Maximum       " ) ;

            printf ( "t = %lf x = %lf\n",

                  C2_EXTR_REC_T(xrec), C2_EXTR_REC_F(xrec) ) ;

            free ( xrec ) ;

      }

      dml_free_list ( extr_list ) ;

}

This program locates the x extrema of 270-degree arc.

 

***>> c2c_curvature  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

BOOLEAN c2c_curvature ( curve, parm, curv_ptr );

 

****** Description ******

 

This function computes the curvature of a curve at the point on the  curve

specified by a parameter record. The curvature is the inverse  of the radius

of curvature, which is the radius of the osculating  arc at the evaluation

point.

 

The curvature is positive when the curve "arcs" in the counter-clockwise

direction, and negative when it "arcs" in the clockwise direction.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a curve                      |

------------------------------------------------------------------------------

| PARM                   | parm               | a curve parameter record     |

|                        |                    | specifying the location on   |

|                        |                    | the curve  where the         |

|                        |                    | curvature should be          |

|                        |                    | evaluated                    |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| REAL *                 | curv_ptr           | the curvature of the curve   |

|                        |                    | at the point specified       |

------------------------------------------------------------------------------

 

****** Return Value. ******

 

This function returns TRUE if the computation was successful. Otherwise  it

returns FALSE.

 

****** Example ******

 

#define SPLINE

#include <c2vdefs.h>

#include <c2ddefs.h>

#include <c2cdefs.h>

 

void main()

{

      REAL curvature ;

      PT2 p, a[4];

      PARM_S parm ;

      C2_CURVE curve ;

 

      c2v_set ( 1.0, 1.0, a[0] );

      c2v_set ( 2.0, 1.5, a[1] );

      c2v_set ( 3.0, 1.3, a[2] );

      c2v_set ( 4.0, 1.1, a[3] );

      curve = c2d_spline ( a, 4 );

      c2v_set ( 2.5, 2.0, p );

      if ( c2c_project ( curve, p, &parm, NULL ) )

      {

            if ( c2c_curvature( curve, &parm, &curvature))

                  printf ( "curvature: %lf\n", curvature );

      }

}

This program finds the location of the projection of a point onto  a spline,

and computes the curvature of the spline at that location.  The symbol SPLINE

must be defined when programs process spline  curves.

 

***>> c2c_ept0  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

BOOLEAN c2c_ept0 ( curve, ept0 );

 

****** Description ******

 

This function evaluates the start point of a curve.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a curve                      |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | ept0               | the start point of the input  |

|                        |                    | curve                        |

------------------------------------------------------------------------------

 

****** Return Value. ******

 

This function returns TRUE if the computation was successful. Otherwise  it

returns FALSE.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

#include <c2cdefs.h>

void main ()

{

      C2_CURVE curve ;

      PT2 center, p ;

 

      c2v_set ( 2.0, 2.0, center ) ;

      curve = c2d_arc ( center, 1.0, 0.3 * PI, PI, 1 ) ;

      if ( c2c_ept0 ( curve, p ) )

            printf ( "start : %lf %lf\n", PT2_X(p), PT2_Y(p) );

}

This program constructs an arc, and prints out the coordinates of  its start

point.

 

***>> c2c_ept1  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

BOOLEAN c2c_ept1 ( curve, ept1 );

 

****** Description ******

 

This function evaluates the end point of a curve.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a curve                      |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | ept1               | the end point of the curve   |

------------------------------------------------------------------------------

 

****** Return Value. ******

 

This function returns TRUE if the computation was successful. Otherwise  it

returns FALSE.

 

****** Example  ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

#include <c2cdefs.h>

void main ()

{

      C2_CURVE curve ;

      PT2 center, p ;

 

      c2v_set ( 2.0, 2.0, center ) ;

      curve = c2d_arc ( center, 1.0, 0.3 * PI, PI, 1 ) ;

      if ( c2c_ept1 ( curve, p ) )

            printf ( "end point: %lf %lf\n", PT2_X(p),

                  PT2_Y(p) );

}

 

This program constructs an arc, and prints out the coordinates of  its end

point.

 

***>> c2c_ept_tan0  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

BOOLEAN c2c_ept_tan0 ( curve, ept0, etan0 );

 

****** Description ******

 

This function evaluates the coordinates and the tangent  vector at the start

point of a curve.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a curve                      |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | ept0               | the start point of the input  |

|                        |                    | curve; if this argument is   |

|                        |                    | NULL,  the start point is    |

|                        |                    | not computed                 |

------------------------------------------------------------------------------

| PT2                    | etan0              | the tangent vector at the    |

|                        |                    | start point of the curve;    |

|                        |                    | this vector  is not          |

|                        |                    | necessarily a unit vector;   |

|                        |                    | if this argument is NULL,    |

|                        |                    | the tangent  vector is not   |

|                        |                    | computed.                    |

------------------------------------------------------------------------------

 

****** Return Value. ******

 

This function returns TRUE if the computation was successful. Otherwise  it

returns FALSE.

 

****** Example  ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

#include <c2cdefs.h>

void main ()

{

      C2_CURVE curve ;

      PT2 center, p, tan ;

 

      c2v_set ( 2.0, 2.0, center ) ;

      curve = c2d_arc ( center, 1.0, 0.3 * PI, PI, 1 ) ;

      if ( c2c_ept_tan0 ( curve, p, tan ) )

      {

            printf ( "start point: %lf %lf\n", PT2_X(p),

                  PT2_Y(p) );

            printf ( "tangent vector: %lf %lf\n",

                  PT2_X(tan), PT2_Y(tan) );

      }

}

 

This program constructs an arc, and prints out the coordinates of  its start

point and the tangent vector at the start point.

 

***>> c2c_ept_tan1  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

BOOLEAN c2c_ept_tan1 ( curve, ept1, etan1 );

 

****** Description ******

 

This function evaluates the coordinates and the tangent  vector at the

endpoint of a curve.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a curve                      |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | ept1               | the end point of the curve;  |

|                        |                    | if this argument is NULL,    |

|                        |                    | the  end point is not        |

|                        |                    | computed                     |

------------------------------------------------------------------------------

| PT2                    | etan1              | the tangent vector at the    |

|                        |                    | end point of the curve; the  |

|                        |                    | tangent  vector is not       |

|                        |                    | necessarily a unit vector;   |

|                        |                    | if this argument is NULL,    |

|                        |                    | the tangent vector is not    |

|                        |                    | computed                     |

------------------------------------------------------------------------------

 

****** Return Value. ******

 

This function returns TRUE if the computation was successful. Otherwise  it

returns FALSE.

 

****** Example  ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

#include <c2cdefs.h>

void main ()

{

      C2_CURVE curve ;

      PT2 center, p, tan ;

 

      c2v_set ( 2.0, 2.0, center ) ;

      curve = c2d_arc ( center, 1.0, 0.3 * PI,

            PI, 1 ) ;

      if ( c2c_ept_tan1 ( curve, p, tan ) )

      {

            printf ( "end point: %lf %lf\n", PT2_X(p),

                  PT2_Y(p) );

            printf ( "tangent vector: %lf %lf\n",

                  PT2_X(tan), PT2_Y(tan) );

      }

}

 

This program constructs an arc, and prints out the coordinates of  its end

point and the tangent vector at the end point.

 

***>> c2c_etan0  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

BOOLEAN c2c_etan0 ( curve, etan0 );

 

****** Description ******

 

This function evaluates the start tangent of a curve. This vector  is not

necessarily a unit vector.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a curve                      |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | etan0              | the tangent vector at the    |

|                        |                    | start point                  |

------------------------------------------------------------------------------

 

****** Return Value. ******

 

This function returns TRUE if the computation was successful. Otherwise  it

returns FALSE.

 

****** Example  ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

#include <c2cdefs.h>

void main ()

{

      C2_CURVE curve ;

      PT2 center, tan ;

      c2v_set ( 0.0, 0.0, center ) ;

      curve = c2d_arc ( center, 5.0, PI/4.0, PI/2.0, -1 ) ;

      if ( c2c_etan0 ( curve, tan ) ) {

            printf ( "The tangent vector at the start " );

            printf ( "point of this curve is %lf,%lf\n",

            PT2_X (tan), PT2_Y(tan) ) ;

      }

}

This program constructs an arc and computes the tangent vector at  its start

point.

 

***>> c2c_etan1  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

BOOLEAN c2c_etan1 ( curve, etan1 );

 

****** Description ******

 

This function evaluates the end tangent vector of a curve. This vector  is

not necessarily a unit normal.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a curve                      |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | etan1              | the tangent vector at the    |

|                        |                    | end point                    |

------------------------------------------------------------------------------

 

****** Return Value. ******

 

This function returns TRUE if the computation was successful. Otherwise  it

returns FALSE.

 

****** Example  ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

#include <c2cdefs.h>

void main ()

{

      C2_CURVE curve ;

      PT2 center, tan ;

      c2v_set ( 0.0, 0.0, center ) ;

      curve = c2d_arc ( center, 5.0, PI/4.0, PI/2.0, -1 );

      if ( c2c_etan1 ( curve, tan ) ) {

            printf ( "The tangent vector at the end " );

            printf ( "point of this curve is %lf,%lf\n",

            PT2_X (tan), PT2_Y(tan) ) ;

      }

}

This program constructs an arc and prints out the value of the tangent

vector at the end point.

 

***>> c2c_eval  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

BOOLEAN c2c_eval ( curve, parm, p, x );

 

****** Description ******

 

This routine evaluates a point on a curve, as well as the derivatives  of the

curve at that point of up to a given order p. The location  where the

evaluation should be performed is specified with a curve  parameter record.

The results of the computations are stored in an  array of points which has

dimension p+1 and is supplied by  the caller.

 

The derivatives are computed with respect to the parameterization  of the

curve and therefore are particularly useful for applications  based on

Newton-Raphson's method.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a curve                      |

------------------------------------------------------------------------------

| PARM                   | parm               | a curve parameter record     |

|                        |                    | specifying the location on   |

|                        |                    | the curve  where the         |

|                        |                    | evaluation should be         |

|                        |                    | performed                    |

------------------------------------------------------------------------------

| INT                    | p                  | the maximum derivative order  |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | x[0]               | the point on the curve       |

------------------------------------------------------------------------------

| PT2                    | x[1],...,x[p]      | the derivatives of the curve  |

|                        |                    | at x[0]                      |

------------------------------------------------------------------------------

 

****** Return Value. ******

 

This function returns TRUE if the computation was successful. Otherwise  it

returns FALSE.

 

****** Example  ******

 

#define SPLINE

#include <c2vdefs.h>

#include <c2ddefs.h>

#include <c2cdefs.h>

void main ()

{

      PT2 p, a[4], result[3];

      PARM_S parm ;

      C2_CURVE curve ;

 

      c2v_set ( 1.0, 1.0, a[0] );

      c2v_set ( 2.0, 1.5, a[1] );

      c2v_set ( 3.0, 1.3, a[2] );

      c2v_set ( 4.0, 1.1, a[3] );

      curve = c2d_spline ( a, 4 );

      c2v_set ( 2.5, 2.0, p );

      if ( c2c_project ( curve, p, &parm, NULL ) )

      {

            if ( c2c_eval( curve, &parm, 2, result ) )

            {

                  printf ( "point: %lf %lf\n",

                        PT2_X(result[0]), PT2_Y(result[0]) );

                  printf ( "first derivative: %lf %lf\n",

                        PT2_X(result[1]), PT2_Y(result[1]) );

                  printf ( "second derivative: %lf %lf\n",

                        PT2_X(result[2]), PT2_Y(result[2]) );

            }

      }

}

This program constructs a spline, projects a point onto the spline,  and

computes the coordinates and the first two derivatives of the  spline at the

point of projection.

 

***>> c2c_eval_pt  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

BOOLEAN c2c_eval_pt ( curve, parm, pt );

 

****** Description ******

 

This routine evaluates the point on a curve corresponding to a curve

parameter record.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a curve                      |

------------------------------------------------------------------------------

| PARM                   | parm               | a curve parameter record     |

|                        |                    | specifying the point on the  |

|                        |                    | curve  where the evaluation  |

|                        |                    | should be performed          |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | pt                 | the point on the curve       |

|                        |                    | corresponding to the curve   |

|                        |                    | parameter  record            |

------------------------------------------------------------------------------

 

****** Return Value. ******

 

This function returns TRUE if the computation was successful. Otherwise  it

returns FALSE.

 

****** Example  ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

#include <c2cdefs.h>

void main ()

{

      PARM_S parm ;

      C2_CURVE curve ;

      PT2 p, pp, center ;

 

      c2v_set ( 0.0, 0.0, center ) ;

      curve = c2d_arc ( center, 5.0, PI/4.0, PI/2.0, -1 );

      c2v_set ( 1.0, 2.0, pp ) ;

      if ( c2c_project ( curve, pp, &parm, NULL ) )

            if ( c2c_eval_pt ( curve, &parm, p ) )

                  printf ( "point: %lf,%lf\n", PT2_X(p), PT2_Y(p) ) ;

}

This program creates a curve, projects a point onto it, and evaluates  the

point referenced by the returned parameter value.

 

***>> c2c_eval_pt_tan  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

BOOLEAN c2c_eval_pt_tan ( curve, parm, pt, tan );

 

****** Description ******

 

This function evaluates the coordinates and the tangent  vector of a point on

a curve. The location of the point  is specified with a curve parameter

record.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a curve                      |

------------------------------------------------------------------------------

| PARM                   | parm               | a curve parameter record     |

|                        |                    | which specifies the location  |

|                        |                    | on the  curve where the      |

|                        |                    | evaluation should be         |

|                        |                    | performed                    |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | pt                 | the point on the curve       |

|                        |                    | corresponding to the curve   |

|                        |                    | parameter  record; if this   |

|                        |                    | argument is NULL, the point  |

|                        |                    | is not computed              |

------------------------------------------------------------------------------

| PT2                    | tan                | the tangent vector at the    |

|                        |                    | point corresponding to the   |

|                        |                    | curve  parameter record; the  |

|                        |                    | computed tangent vector is   |

|                        |                    | not necessarily a  unit      |

|                        |                    | vector; if this argument is  |

|                        |                    | NULL, the tangent vector is  |

|                        |                    | not computed                 |

------------------------------------------------------------------------------

 

****** Return Value. ******

 

This function returns TRUE if the computation was successful. Otherwise  it

returns FALSE.

 

****** Example  ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

#include <c2cdefs.h>

void main ()

{

      PARM_S parm ;

      C2_CURVE curve ;

      PT2 p, pp, center, tan ;

 

      c2v_set ( 0.0, 0.0, center ) ;

      curve = c2d_arc ( center, 5.0, PI/4.0, PI/2.0, -1 ) ;

      c2v_set ( 1.0, 2.0, pp ) ;

      if ( c2c_project ( curve, pp, &parm, NULL ) )

            if ( c2c_eval_pt_tan ( curve, &parm, p, tan ) )

            {

                  printf ( "Point at %lf,%lf\n", PT2_X(p),

                        PT2_Y(p) ) ;

                  printf ( "Tangent vector %lf,%lf\n",

                        PT2_X(tan), PT2_Y(tan) ) ;

            }

}

 

This program creates a curve, projects a point onto it, and evaluates  the

point referenced by the returned parameter value, and the tangent  at that

point.

 

***>> c2c_eval_tan  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

BOOLEAN c2c_eval_tan ( curve, parm, tan );

 

****** Description ******

 

This function evaluates the tangent vector of a curve at the location

specified by a curve parameter record. The computed tangent vector  is not

necessarily a unit vector.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a curve                      |

------------------------------------------------------------------------------

| PARM                   | parm               | a curve parameter record     |

|                        |                    | specifying the location  on  |

|                        |                    | the curve at which to        |

|                        |                    | evaluate the tangent vector   |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | tan                | the tangent vector at the    |

|                        |                    | point on the curve           |

|                        |                    | specified by the curve       |

|                        |                    | parameter record             |

------------------------------------------------------------------------------

 

****** Return Value. ******

 

This function returns TRUE if the computation was successful. Otherwise  it

returns FALSE.

 

****** Example  ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

#include <c2cdefs.h>

void main ()

{

      PARM_S parm ;

      C2_CURVE curve ;

      PT2 pp, center, tan ;

 

      c2v_set ( 0.0, 0.0, center ) ;

      curve = c2d_arc ( center, 5.0, PI/4.0, PI/2.0, -1 ) ;

      c2v_set ( 1.0, 2.0, pp ) ;

      if ( c2c_project ( curve, pp, &parm, NULL ) )

            if ( c2c_eval_tan ( curve, &parm, tan ) )

                  printf ( "Tangent vector %lf,%lf\n",

                        PT2_X(tan), PT2_Y(tan) ) ;

}

 

This program creates a curve, projects a point onto it, and evaluates  the

tangent at the point referenced by the returned parameter value.

 

***>> c2c_fillet <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

BOOLEAN c2c_fillet ( curve1, parm1, curve2, parm2, r, p1, p2,  ctr );

 

****** Description ******

 

This function computes the contact points and the center of a fillet  arc.

The contact points are reported both with coordinates and  curve parameters

on the two specified curves.

 

The arguments parm1 and parm2 must be initialized to  curve parameters near

the contact points.  Approximate curve  parameters can be computed by

projecting "pick" points onto the  curves with c2c_project.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve1, curve2     | the curves to fillet         |

------------------------------------------------------------------------------

| PARM                   | parm1, parm2       | curve parameters; when this  |

|                        |                    | routine is called, these     |

|                        |                    | arguments should contain     |

|                        |                    | approximate curve parameters  |

|                        |                    | that indicate  the           |

|                        |                    | approximate locations of the  |

|                        |                    | fillet contact points; when  |

|                        |                    | this  routine returns, these  |

|                        |                    | arguments contain the exact  |

|                        |                    | curve parameters  of the     |

|                        |                    | fillet contact points on c1  |

|                        |                    | and c2  respectively         |

------------------------------------------------------------------------------

| REAL                   | r                  | radius of the fillet         |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | p1, p2             | the coordinates of fillet    |

|                        |                    | contact points; not computed  |

|                        |                    | if  NULL is supplied         |

------------------------------------------------------------------------------

| PT2                    | ctr                | the coordinates of fillet    |

|                        |                    | arc center                   |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is TRUE if the fillet arc could be constructed.  It  returns

FALSE if the computation failed.

 

****** Example ******

 

#include <c2cdefs.h>

#include <c2ddefs.h>

C2_CURVE create_fillet ( c1, c2, r, pickp1, pickp2 )

C2_CURVE c1, c2;

REAL r;

PT2 pickp1, pickp2;

{

      PARM_S parm1, parm2;

      PT2 p1, p2, ctr;

      c2c_project ( c1, pickp1, &parm1, NULL );

      c2c_project ( c2, pickp2, &parm2, NULL );

      if ( c2c_fillet ( c1, &parm1, c2, &parm2, r, p1,

            p2, ctr ) )

      {

            return ( c2d_arc_ctr_2pts ( ctr, p1, p2, 1 ) );

      }

      else return ( NULL );

}

This function creates a fillet arc that contacts two curves near  "pick"

points.

 

***>> c2c_fillet_corner <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

BOOLEAN c2c_fillet_corner ( c1, c2, r, parm1, parm2,  p1, p2, ctr );

 

****** Description ******

 

This function computes the coordinates and the curve parameters of  the

contact points and the center of a fillet arc with a specified  radius.  If

the curves join to form a corner, the fillet is computed  for that corner.

If the curves do not have a pair of coincident  endpoints, the fillet is

computed for the closest pair of curve  endpoints.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | c1, c2             | the curves to fillet         |

------------------------------------------------------------------------------

| REAL                   | r                  | radius of the fillet         |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PARM                   | parm1, parm2       | the curve parameters of the  |

|                        |                    | fillet contact points; not   |

|                        |                    | computed if NULL             |

------------------------------------------------------------------------------

| PT2                    | p1, p2             | the coordinates of the       |

|                        |                    | fillet contact points; not   |

|                        |                    | computed  if NULL            |

------------------------------------------------------------------------------

| PT2                    | ctr                | the coordinates of fillet    |

|                        |                    | arc center                   |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is TRUE if the fillet arc could be constructed.  It  returns

FALSE if the computation failed.

 

****** Example ******

 

#include <c2cdefs.h>

#include <c2ddefs.h>

C2_CURVE create_fillet ( c1, c2, r )

C2_CURVE c1, c2;

REAL r;

{

      PARM_S parm1, parm2;

      PT2 p1, p2, ctr;

      if ( c2c_fillet_corner ( c1, c2, r, &parm1, &parm2,

            p1, p2, ctr ) )

            return ( c2d_arc_ctr_2pts ( ctr, p1, p2, 1 ) );

      else return ( NULL );

}

This program constructs a fillet at the junction of two curves.

 

***>> c2c_get_arc_center  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

BOOLEAN c2c_get_arc_center ( curve, ctr ) ;

 

****** Description ******

 

This function evaluates the center point of an arc. The input curve  must be

an arc.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | an arc                       |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | ctr                | the center of the arc        |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is TRUE if the input curve is an arc; it is FALSE

otherwise.

 

****** Example ******

 

#include <c2cdefs.h>

void pr_arc_ctr ( arc )

C2_CURVE arc ;

{

      PT2 center ;

 

      if ( c2c_get_arc_center ( arc, center ) )

            printf ( "Center at %lf,%lf\n", PT2_X(center),

                  PT2_Y(center) ) ;

      else printf ( "Curve is not an arc!\n" ) ;

}

 

This subroutine prints the coordinates of the center of an arc.

 

***>> c2c_get_arc_data  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

BOOLEAN c2c_get_arc_data ( curve, ctr, rad_ptr, st_angle_ptr,  sweep_ptr,

dir_ptr ) ;

 

****** Description ******

 

This routine evaluates the center, radius, start angle, sweep and  direction

of an arc. The input curve must be an arc.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | an arc                       |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | ctr                | the center of the arc; not   |

|                        |                    | computed if NULL             |

------------------------------------------------------------------------------

| REAL*                  | rad_ptr            | the radius of the arc; not   |

|                        |                    | computed if NULL             |

------------------------------------------------------------------------------

| REAL *                 | st_angle_ptr       | the start angle of the arc;  |

|                        |                    | the start angle is the       |

|                        |                    | angular  position of the     |

|                        |                    | start point of the arc       |

|                        |                    | relative to the 3 o'clock    |

|                        |                    | direction; not computed if   |

|                        |                    | NULL                         |

------------------------------------------------------------------------------

| REAL *                 | sweep_ptr          | the sweep of the arc; not    |

|                        |                    | computed if NULL             |

------------------------------------------------------------------------------

| INT *                  | dir_ptr            | direction of the arc; +1 if  |

|                        |                    | the arc is directed          |

|                        |                    | counterclockwise,  and -1,   |

|                        |                    | if the arc is directed       |

|                        |                    | clockwise; not computed if   |

|                        |                    | NULL                         |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is TRUE if the input curve is an arc; it is FALSE

otherwise.

 

****** Example ******

 

#include <c2cdefs.h>

void print_arc_data ( arc )

C2_CURVE arc ;

{

      PT2 center ;

      REAL radius, st_angle, sweep ;

      INT dir ;

 

      if ( c2c_get_arc_data ( arc, center, &radius,

            &st_angle, &sweep, &dir ) )

      {

            printf ( "center: %lf,%lf\n", PT2_X(center),

                  PT2_Y(center) ) ;

            printf ( "radius %lf\n", radius ) ;

            printf ( "start angle %lf\n", st_angle ) ;

            printf ( "sweep %lf\n", sweep ) ;

            printf ( "direction %d\n", dir ) ;

      }

      else printf ( "Curve is not an arc!\n" ) ;

}

 

This subroutine prints out information about an arc.

 

***>> c2c_get_arc_direction <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

BOOLEAN c2c_get_arc_direction ( curve, dir_ptr ) ;

 

****** Description ******

 

This function evaluates the direction of an arc. The input curve must  be an

arc.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | an arc                       |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| INT *                  | dir_ptr            | the arc direction; +1 if arc  |

|                        |                    | is oriented                  |

|                        |                    | counterclockwise,  and -1 if  |

|                        |                    | arc is oriented clockwise    |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is TRUE if the input curve is an arc; it is FALSE

otherwise.

 

****** Example ******

 

#include <c2cdefs.h>

void pr_arc_dir ( arc )

C2_CURVE arc ;

{

      INT dir ;

 

      if ( c2c_get_arc_direction ( arc, &dir ) )

      {

            printf ( "The arc direction is " ) ;

            if ( dir == 1 )

                  printf ( "Counter-clockwise\n" ) ;

            else printf ( "Clockwise\n" ) ;

      }

      else printf ( "Curve is not an arc!\n" ) ;

}

 

This subroutine prints the direction of an arc.

 

***>> c2c_get_arc_radius  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

BOOLEAN c2c_get_arc_radius ( curve, rad_ptr ) ;

 

****** Description ******

 

This function evaluates the radius of an arc.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | an arc                       |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| REAL *                 | rad_ptr            | radius of the arc            |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is TRUE if the input curve is an arc; it is FALSE

otherwise.

 

****** Example ******

 

#include <c2cdefs.h>

void pr_arc_radius ( arc )

C2_CURVE arc ;

{

      REAL radius ;

 

      if ( c2c_get_arc_radius ( arc, &radius ) )

            printf ( "The radius is %lf\n", radius ) ;

      else printf ( "Curve is not an arc!\n" ) ;

}

 

This subroutine prints the radius of an arc.

 

***>> c2c_get_arc_start_angle  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

BOOLEAN c2c_get_arc_start_angle ( curve, angle_ptr  ) ;

 

****** Description ******

 

This function evaluates the start angle of an arc. The start angle  of an arc

is the angular position of the start point relative to the  3 o'clock

direction. The angle is given in radians and its value falls  between 0 and

TWO_PI.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | an arc                       |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| REAL *                 | angle_ptr          | start angle of an arc        |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is TRUE if the input curve is an arc; it is FALSE

otherwise.

 

****** Example ******

 

#include <c2cdefs.h>

void pr_arc_st_angle ( arc )

C2_CURVE arc ;

{

      REAL st_angle ;

 

      if ( c2c_get_arc_start_angle ( arc, &st_angle ) )

            printf( "The start angle is %lf\n", st_angle);

      else printf ( "Curve is not an arc!\n" ) ;

}

 

This subroutine prints the start angle of an arc (in radians).

 

***>> c2c_get_arc_sweep  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

BOOLEAN c2c_get_arc_sweep ( curve, sweep_ptr ) ;

 

****** Description ******

 

This function evaluates the sweep of an arc. The angle is given in  radians

and its value falls between 0 and TWO_PI.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | an arc                       |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| REAL *                 | sweep_ptr          | the sweep angle of the arc   |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is TRUE if the input curve is an arc; it is FALSE

otherwise.

 

****** Example ******

 

#include <c2cdefs.h>

void pr_arc_sweep ( arc )

C2_CURVE arc ;

{

      REAL sweep ;

 

      if ( c2c_get_arc_sweep ( arc, &sweep ) )

            printf( "The sweep is %lf\n", sweep ) ;

      else printf ( "Curve is not an arc!\n" ) ;

}

 

This subroutine prints the sweep of an arc (in radians).

 

***>> c2c_get_ellipse_data  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

BOOLEAN c2c_get_ellipse_data ( curve, ctr,  major_axis, minor_axis, angle );

 

****** Description ******

 

This function computes the center, the lengths of the major and  minor axes,

and the angle of inclination of the major axis.  The  angle, expressed in

radians, is between 0 and two pi.

 

The start and end points of the ellipse may be obtained with the  functions

c2c_ept0 and c2c_ept1.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | an ellipse                   |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | ctr                | the center of the ellipse    |

------------------------------------------------------------------------------

| REAL *                 | major_axis,        | the lengths of the major and  |

|                        | minor_axis         | minor axes                   |

------------------------------------------------------------------------------

| REAL *                 | angle              | the angle of inclination of  |

|                        |                    | the major axis; this value   |

|                        |                    | is  expressed in radians     |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is TRUE if the input curve is an ellipse; it is  FALSE

otherwise.

 

****** Example ******

 

#include <c2cdefs.h>

void print_ellipse ( ellipse )

C2_CURVE ellipse ;

{

      PT2 c ;

      REAL major_axis, minor_axis, angle ;

 

      if ( c2c_get_ellipse_data ( ellipse, c,

            &major_axis, &minor_axis, &angle ) ) {

            printf ( "center of an ellipse is %lf\t%lf\n",

                  PT2_X(c), PT2_Y(c) ) ;

            printf ( "major and minor axes: %lf\t%lf\n",

                  major_axis, minor_axis ) ;

            printf ( "angle between major axis \n" ) ;

            printf ( "and x-axis is %lf\n", &angle ) ;

      }

      else

            printf ( "the curve is not an ellipse\n" ) ;

}

This program computes information about an ellipse.

 

***>> c2c_get_pcurve_data  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

BOOLEAN c2c_get_pcurve_data ( curve, i, is_arc, ctr,  ept1, rad_ptr,

st_angle_ptr, sweep_ptr, dir_ptr );

 

****** Description ******

 

This function computes information about the ith segment of a  polycurve.

 

If the segment is a line, the end point is computed.  If it is an  arc, the

center, the radius, the start angle, the sweep and the  direction are

computed in addition to the end point. Angles  expressed in radians, is

between 0 and two pi; the start angle is  measured relative to the positive

x-axis.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a polycurve                  |

------------------------------------------------------------------------------

| INT                    | i                  | the index of the segment to  |

|                        |                    | query; the index i           |

|                        |                    | corresponds  to the first    |

|                        |                    | segment                      |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| BOOLEAN *              | is_arc             | TRUE if the ith segment is   |

|                        |                    | an arc; FALSE if  ith        |

|                        |                    | segment is a line            |

------------------------------------------------------------------------------

| PT2                    | ctr                | the center point of the ith  |

|                        |                    | segment, if it is an arc;    |

|                        |                    | may be NULL                  |

------------------------------------------------------------------------------

| PT2                    | ept1               | the endpoint of the ith      |

|                        |                    | segment; may be NULL         |

------------------------------------------------------------------------------

| REAL *                 | rad_ptr            | the radius of the ith        |

|                        |                    | segment, if it is an arc;    |

|                        |                    | may  be NULL                 |

------------------------------------------------------------------------------

| REAL *                 | st_angle_ptr       | the start angle of the ith   |

|                        |                    | segment, if it is an arc;    |

|                        |                    | may be NULL                  |

------------------------------------------------------------------------------

| REAL *                 | sweep_ptr          | the sweep angle of the ith   |

|                        |                    | segment, if it is an arc;    |

|                        |                    | may be NULL                  |

------------------------------------------------------------------------------

| INT *                  | dir_ptr            | the direction of the ith     |

|                        |                    | segment, if it is an arc; a   |

|                        |                    | returned value of 1 denotes  |

|                        |                    | counter-clockwise; may be    |

|                        |                    | NULL                         |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is TRUE if the input curve is a polycurve, or if  the

segment queried is not the last segment in the polycurve; it is  FALSE

otherwise.

 

****** Example ******

 

#include <c2cdefs.h>

void print_pcurve ( pcurve )

C2_CURVE pcurve ;

{

INT i, dir ;

BOOLEAN is_arc ;

PT2 ctr, ept1 ;

REAL rad, st_angle, sweep ;

BOOLEAN more;

      c2c_ept0 ( pcurve, ept1 );

      printf ( "x: %lf  y: %lf\n", PT2_X(ept1), PT2_Y(ept1) );

      i = 0;

 

      do

      {

            more = c2c_get_pcurve_data ( pcurve, i, &is_arc, ctr,

                  ept1, &rad, &st_angle, &sweep, &dir );

            if ( is_arc == TRUE )

                  printf ( "arc segment\n" );

            printf ( "x: %lf  y: %lf\n", PT2_X(ept1), PT2_Y(ept1) );

            i++;

      }

      while ( more == TRUE );

}

This program computes information about a polycurve.

 

***>> c2c_info_curve  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

void c2c_info_curve ( curve, file );

 

****** Description ******

 

This function prints out information about a curve to a file. If the  file

parameter is NULL, the output is sent to stdout.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a curve                      |

------------------------------------------------------------------------------

| FILE *                 | file               | output file                  |

------------------------------------------------------------------------------

 

****** Example  ******

 

#include <dmldefs.h>

#include <c2cdefs.h>

void print_curvelist ( curves )

      DML_LIST curves ;

{

      DML_ITEM item ;

      C2_CURVE curve ;

 

      DML_FOR_LOOP ( dml_first ( curves ), item )

      {

            curve = ( C2_CURVE ) dml_record ( item ) ;

            c2c_info_curve ( curve, NULL ) ;

      }

}

 

This program prints information about curves on a list.

 

***>> c2c_info_int_rec  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

void c2c_info_int_rec ( int_rec, file );

 

****** Description ******

 

This routine prints out information about an intersection record to  a file.

If the file parameter is NULL, the output is sent to stdout.

 

An intersection record is a structure that contains the following

information about a point where two curves intersect:

 

* the coordinates of the intersection point

 

* the curve parameter record specifying where on the first  curve the

  intersection occurs

 

* the curve parameter record specifying where on the second  curve the

  intersection occurs

 

* the type of the intersection (i.e. transverse or tangent)

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_INT_REC             | int_rec            | intersection record          |

------------------------------------------------------------------------------

| FILE *                 | file               | output file                  |

------------------------------------------------------------------------------

 

****** Example  ******

 

#include <dmldefs.h>

#include <c2vdefs.h>

#include <c2ddefs.h>

#include <c2cdefs.h>

void main()

{

      C2_CURVE curve1, curve2 ;

      PT2 p1, p2 ;

      DML_LIST int_list = dml_create_list () ;

      DML_ITEM item ;

      C2_INT_REC int_rec ;

 

      c2v_set ( 1.0, 3.0, p1 ) ;

      c2v_set ( -1.5, 8.0, p2 ) ;

      curve1 = c2d_circle ( p1, 4.0 ) ;

      curve2 = c2d_line ( p1, p2 ) ;

      c2c_intersect_ext ( curve1, curve2, int_list ) ;

      DML_FOR_LOOP ( dml_first ( int_list ), item )

      {

            int_rec = ( C2_INT_REC ) dml_record ( item ) ;

            c2c_info_int_rec ( int_rec, NULL ) ;

      }

}

This program intersects a circle and a line passing through its center,  and

prints out information about the intersections that occur.

 

***>> c2c_intersect <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

INT c2c_intersect ( curve1, curve2, int_list );

 

****** Description ******

 

This function computes the intersections of two curves. Intersections  are

reported in intersection records that are appended to an "intersection

result" list.

 

The information about the intersections may be obtained by traversing

int_list and accessing the data in the intersection records  with the

C2_INT_REC access macros.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve1             | a curve                      |

------------------------------------------------------------------------------

| C2_CURVE               | curve2             | a curve                      |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| DML_LIST               | int_list           | the "intersection result"    |

|                        |                    | list; intersection records   |

|                        |                    | are appended  to this list;  |

|                        |                    | this routine expects the     |

|                        |                    | list to be created by the    |

|                        |                    | caller                       |

------------------------------------------------------------------------------

 

****** Return Value. ******

 

The return value is the number of intersection points. If the input  curves

are coincident, -1 is returned, and the interval of coincidence  is reported

as a pair of consecutive intersection records that correspond  to the start

and ends of the interval.

 

****** Example  ******

 

#include <dmldefs.h>

#include <c2cdefs.h>

#include <c2ddefs.h>

 

void pr_int_2curves ( curve1, curve2 )

C2_CURVE curve1, curve2 ;

{

      DML_LIST list = dml_create_list () ;

      C2_INT_REC int_rec;

      DML_ITEM item ;

 

      if ( c2c_intersect ( curve1, curve2, list ) != 0 )

      {

            DML_FOR_LOOP ( dml_first ( list ), item )

            {

                  int_rec = (C2_INT_REC) dml_record (item) ;

                  c2c_info_int_rec ( int_rec, NULL ) ;

            }

            dml_destroy_list ( list, ( PF_VOID ) c2d_free_int_rec );

      }

}

This function intersects two curves and prints out the results. The

intersection results are found on the "intersection results list",  the third

argument of the intersection routine.

 

***>> c2c_intersect_ext  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

INT c2c_intersect_ext ( curve1, curve2, inters_list  );

 

****** Description ******

 

This function finds the intersection points of two curves. If either  of the

curves is of type C2_LINE, then it is treated as an infinite  line.

Similarly, if either of the curves is of type C2_ARC, then it  is treated as

a full circle. This function is useful for finding  "invisible"

intersections, i.e. intersection points of lines or arcs  that do not visibly

cross.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve1             | a curve                      |

------------------------------------------------------------------------------

| C2_CURVE               | curve2             | a curve                      |

------------------------------------------------------------------------------

| DML_LIST               | inters_list        | the "intersection result"    |

|                        |                    | list to which intersection   |

|                        |                    | records  are appended; this  |

|                        |                    | list must be created by the  |

|                        |                    | caller                       |

------------------------------------------------------------------------------

 

****** Output ******

 

The results of the intersection are contained in intersection records  that

are appended to inters_list.

 

****** Return Value ******

 

The return value is the number of intersection points. If the input  curves

are coincident, -1 is returned.

 

****** Example ******

 

#include <dmldefs.h>

#include <c2vdefs.h>

#include <c2ddefs.h>

#include <c2cdefs.h>

void main()

{

      C2_CURVE curve1, curve2 ;

      PT2 p1, p2 ;

      DML_LIST int_list = dml_create_list () ;

      DML_ITEM item ;

      C2_INT_REC int_rec ;

 

      c2v_set ( 1.0, 3.0, p1 ) ;

      c2v_set ( -1.5, 8.0, p2 ) ;

      curve1 = c2d_circle ( p1, 4.0 ) ;

      curve2 = c2d_line ( p1, p2 ) ;

      c2c_intersect_ext ( curve1, curve2, int_list ) ;

      DML_FOR_LOOP ( dml_first ( int_list ), item )

      {

            int_rec = ( C2_INT_REC ) dml_record ( item ) ;

            c2c_info_int_rec ( int_rec, NULL ) ;

      }

}

 

This program intersects a circle and an infinite line, and prints  the

intersection information on the screen. Two intersection points  are

computed.

 

***>> c2c_intersect_line_or_arc  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

INT c2c_intersect_line_or_arc ( curve1, curve2, t1,  t2, int_pt, int_type,

near_tan );

 

****** Description ******

 

This routine finds intersection points of lines and arcs only. The  results

of intersection are returned in the argument list rather than  on an

"intersection result" list.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve1             | a curve representing a line  |

|                        |                    | or an arc                    |

------------------------------------------------------------------------------

| C2_CURVE               | curve2             | a curve representing a line  |

|                        |                    | or an arc                    |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| REAL *                 | t1                 | array of parameter values on  |

|                        |                    | the first curve              |

|                        |                    | corresponding  to the        |

|                        |                    | intersection points; the     |

|                        |                    | number of elements in this   |

|                        |                    | array should  be at least    |

|                        |                    | the number of intersections  |

|                        |                    | expected                     |

------------------------------------------------------------------------------

| REAL *                 | t2                 | array of parameter values on  |

|                        |                    | the second curve             |

|                        |                    | corresponding  to the        |

|                        |                    | intersection points; the     |

|                        |                    | number of elements in this   |

|                        |                    | array should  be at least    |

|                        |                    | the number of intersections  |

|                        |                    | expected                     |

------------------------------------------------------------------------------

| PT2 *                  | int_pt             | array of intersection        |

|                        |                    | points; the number of        |

|                        |                    | elements in this  array      |

|                        |                    | should be at least the       |

|                        |                    | number of intersections      |

|                        |                    | expected                     |

------------------------------------------------------------------------------

| INT *                  | int_type           | array of intersection types;  |

|                        |                    | the type of an intersection  |

|                        |                    | point  is 1 if the           |

|                        |                    | intersection is transverse,  |

|                        |                    | and 2 if the intersection    |

|                        |                    | is tangential ; the number   |

|                        |                    | of elements in this array    |

|                        |                    | should be at  least the      |

|                        |                    | number of intersections      |

|                        |                    | expected                     |

------------------------------------------------------------------------------

| BOOLEAN *              | near_tan           | array of BOOLEAN values;     |

|                        |                    | TRUE if intersection is near  |

|                        |                    |  tangent; FALSE otherwise    |

------------------------------------------------------------------------------

 

Each of the above output parameters is an array of values, in which  the

number of elements should be at least the number of  intersections expected.

 

near tangent intersection is defined as a tangent intersection where  the

curves are separated by less than the absolute tolerance, but  the

inersection points defining the tangent interval are separated  by more than

the absolute tolerance. For exemple: when a line  intersects a circle

tangently, the intersection is a near tangent  intersection when the maximum

distance between the circle and the  line over the tangent interval does not

exceed the absolute  tolerance while the distance between the points where

the circle and  line cross does exceed the absolute total.

 

****** Return Value ******

 

The return value is the number of intersection points (0, 1 or 2).  If curves

other than lines and arcs are passed to this routine, -4  is returned. If the

input curves are coincident, -1 is returned.

 

****** Example ******

 

#include <c2cdefs.h>

 

void pr_int_line_or_arc ( arc, line )

C2_CURVE arc, line ;

{

      INT inter_type[2], num_inter ;

      REAL param1[2], param2[2] ;

      PT2 int_pt[2] ;

      num_inter = c2c_intersect_line_or_arc ( arc, line,

            param1, param2, int_pt, inter_type ) ;

      switch ( num_inter )

      {

            case 0:

                  printf ( "no intersections found\n" );

                  break;

            case 1:

                  printf ( "one intersection found: %lf %lf\n",

                        PT2_X(int_pt[0]), PT2_Y(int_pt[0]) );

                  break;

            case 2:

                  printf ( "two intersections found: %lf %lf ",

                        PT2_X(int_pt[0]), PT2_Y(int_pt[0]) );

                  printf ( "%lf %lf\n", PT2_X(int_pt[1]),

                        PT2_Y(int_pt[1]) );

                  break;

            case -4:

                  printf ( "invalid curves\n" ) ;

                  break;

            default:

                  break;

      }

}

This subroutine finds the intersections of a line and an arc.

 

***>> c2c_intersect_line_or_arc_ext  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

INT c2c_intersect_line_or_arc_ext ( curve1, curve2,  t1, t2, int_pt, int_type

);

 

****** Description ******

 

This routine finds the intersection points of lines and arcs only.  Lines are

treated as infinite lines, and arcs are treated as full  circles. The results

of intersection are returned in the argument  list rather than on an

"intersection result" list.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve1             | a curve representing a line  |

|                        |                    | or an arc                    |

------------------------------------------------------------------------------

| C2_CURVE               | curve2             | a curve representing a line  |

|                        |                    | or an arc                    |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| REAL *                 | t1                 | array of parameter values on  |

|                        |                    | the first curve              |

|                        |                    | corresponding  to the        |

|                        |                    | intersection points; the     |

|                        |                    | number of elements in this   |

|                        |                    | array should  be at least    |

|                        |                    | the number of intersections  |

|                        |                    | expected                     |

------------------------------------------------------------------------------

| REAL *                 | t2                 | array of parameter values on  |

|                        |                    | the second curve             |

|                        |                    | corresponding  to the        |

|                        |                    | intersection points; the     |

|                        |                    | number of elements in this   |

|                        |                    | array should  be at least    |

|                        |                    | the number of intersections  |

|                        |                    | expected                     |

------------------------------------------------------------------------------

| PT2 *                  | int_pt             | array of intersection        |

|                        |                    | points; the number of        |

|                        |                    | elements in this  array      |

|                        |                    | should be at least the       |

|                        |                    | number of intersections      |

|                        |                    | expected                     |

------------------------------------------------------------------------------

| INT *                  | int_type           | array of intersection types;  |

|                        |                    | the type of an intersection  |

|                        |                    | point  is 1 if the           |

|                        |                    | intersection is transverse,  |

|                        |                    | and 2 if the intersection    |

|                        |                    | is tangential ; the number   |

|                        |                    | of elements in this array    |

|                        |                    | should be at  least the      |

|                        |                    | number of intersections      |

|                        |                    | expected                     |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the number of intersection points (0, 1 or 2).  If curves

other than lines and arcs are passed to this routine, -4  is returned. If the

input curves are coincident, -1 is returned.

 

****** Example ******

 

#include <c2cdefs.h>

 

void pr_int_line_or_arc ( arc, line )

C2_CURVE arc, line ;

{

      INT inter_type[2], num_inter ;

      REAL param1[2], param2[2] ;

      PT2 int_pt[2] ;

      num_inter = c2c_intersect_line_or_arc_ext ( arc, line,

            param1, param2, int_pt, inter_type ) ;

      switch ( num_inter )

      {

            case 0:

                  printf ( "no intersections found\n" );

                  break;

            case 1:

                  printf ( "one intersection found: %lf %lf\n",

                        PT2_X(int_pt[0]), PT2_Y(int_pt[0]) );

                  break;

            case 2:

                  printf ( "two intersections found: %lf %lf ",

                        PT2_X(int_pt[0]), PT2_Y(int_pt[0]) );

                  printf ( "%lf %lf\n", PT2_X(int_pt[1]),

                        PT2_Y(int_pt[1]) );

                  break;

            case -4:

                  printf ( "invalid curves\n" ) ;

                  break;

            default:

                  break;

      }

}

This subroutine finds the intersections of an infinite line and a  full

circle.

 

***>> c2c_length <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

REAL c2c_length (curve);

 

****** Description ******

 

This function computes the length of a curve.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a curve                      |

------------------------------------------------------------------------------

 

****** Return Value. ******

 

The return value of this function is the length of the input curve.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

#include <c2cdefs.h>

 

void main()

{

      REAL length, radius = 1.0, start_angle = 0.0,

      sweep = PI ;

      PT2 center;

      C2_CURVE arc;

 

      c2v_set ( 2.0, 3.0, center );

      arc = c2d_arc ( center, radius, start_angle,

            sweep, 1 );

      length = c2c_length ( arc );

      printf ( "length: %lf\n", length );

      c2d_free_curve ( arc );

}

This program constructs an arc and prints out its length.

 

***>> c2c_mirror_dir  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

C2_CURVE c2c_mirror_dir ( curve0, origin, direction );

 

****** Description ******

 

This function mirrors a curve about a line. The line is defined by  a point

and a vector which points in the mirroring direction.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve0             | input curve to be mirrored   |

------------------------------------------------------------------------------

| PT2                    | origin             | point on the mirror line     |

------------------------------------------------------------------------------

| PT2                    | direction          | mirroring direction vector   |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the input curve.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

#include <c2cdefs.h>

 

void main ()

{

      PT2 center, p1, dir ;

      C2_CURVE arc ;

 

      c2v_set ( 2.0, 1.0, center ) ;

      arc = c2d_arc ( center, 3.0, 0.0, PI, 1 ) ;

      c2v_set ( 0.0, 0.0, p1 ) ;

      c2v_set ( 0.0, 1.0, dir ) ;

      c2c_mirror_dir ( arc, p1, dir ) ;

      c2d_free_curve ( arc ) ;

}

This program creates an arc and mirrors it over the x axis.

 

***>> c2c_mirror_line  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

C2_CURVE c2c_mirror_line ( curve0, line );

 

****** Description ******

 

This function mirrors a curve about the line. The line is defined  by an

array of two points.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve0             | the input curve to be        |

|                        |                    | mirrored                     |

------------------------------------------------------------------------------

| PT2 *                  | line               | an array of two points       |

|                        |                    | defining the mirror line     |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the input curve.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

#include <c2cdefs.h>

 

void main ()

{

      PT2 center, pts[2] ;

      C2_CURVE arc ;

 

      c2v_set ( 2.0, 1.0, center ) ;

      arc = c2d_arc ( center, 3.0, 0.0, PI, 1 ) ;

      c2v_set ( 0.0, 0.0, pts[0] ) ;

      c2v_set ( 1.0, 1.5, pts[1] ) ;

      c2c_mirror_line ( arc, pts ) ;

      c2d_free_curve ( arc ) ;

}

 

This program creates an arc and mirrors it over the line passing through

(0.0,0.0) and (1.0,1.5).

 

***>> c2c_project  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

BOOLEAN c2c_project ( curve, pt, parm, pt_on_curve );

 

****** Description ******

 

This function computes the orthogonal projection of a point onto a  curve.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a curve                      |

------------------------------------------------------------------------------

| PT2                    | pt                 | the point to be projected    |

|                        |                    | onto the curve               |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PARM                   | parm               | the address of a curve       |

|                        |                    | parameter record identifying  |

|                        |                    | the orthogonal  projection   |

|                        |                    | of point pt onto the curve   |

------------------------------------------------------------------------------

| PT2                    | pt_on_curve        | the coordinates of the       |

|                        |                    | projection of point pt onto   |

|                        |                    | the curve; may be NULL       |

------------------------------------------------------------------------------

 

****** Return Value ******

 

This function returns TRUE if the computation was successful. Otherwise  it

returns FALSE.

 

Examples of situations where projection fails are: when the curve is  an arc,

and the point to be projected is at the center of the arc;  and when there is

no orthogonal projection of the given point onto  the specified curve.

 

****** Example  ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

#include <c2cdefs.h>

void main ()

{

      PT2 center, pt1, pt2 ;

      C2_CURVE circle ;

      PARM_S parm ;

 

      c2v_set ( 2.0, 2.0, center ) ;

      circle = c2d_circle ( center, 5.0 ) ;

      c2v_set ( 4.0, 3.5, pt1 ) ;

      if ( c2c_project ( circle, pt1, &parm, pt2 ) )

            printf ( "Point on circle : %lf,%lf\n",

                  PT2_X(pt2), PT2_Y(pt2) ) ;

      c2d_free_curve ( circle ) ;

}

This program projects the point (4.0,3.5) onto a circle, and prints  the

coordinates of the point on the circle nearest this point.

 

***>> c2c_rotate  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

C2_CURVE c2c_rotate ( curve0, origin, angle );

 

****** Description ******

 

This function rotates a curve about a point by a specified angle.  The angle

must be given in radians.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve0             | curve to be rotated          |

------------------------------------------------------------------------------

| PT2                    | origin             | the center of rotation       |

------------------------------------------------------------------------------

| REAL                   | angle              | rotation angle               |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the input curve.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2cdefs.h>

 

void rot_curve ( curve )

C2_CURVE curve ;

{

      REAL x, y, rot_angle ;

      PT2 rot_origin ;

 

      printf ( "Coordinates of rotation origin : " ) ;

      scanf ( "%lf%lf", &x, &y ) ;

      c2v_set ( x, y, rot_origin ) ;

      printf ( "Angle to rotate ( in degrees ) : " ) ;

      scanf ( "%lf", &rot_angle ) ;

      c2c_rotate ( curve, rot_origin,

            PI_OVER_180 * rot_angle ) ;

}

 

This subroutine rotates a curve according to the user input. The angle  has

been converted to radians.

 

***>> c2c_rotate_cs  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

C2_CURVE c2c_rotate_cs ( curve0, origin, c, s );

 

****** Description ******

 

This function rotates a curve about a point by an angle. The angle  is

specified by providing its cosine and sine, rather than the angle  itself.

 

This function should be used in loops within which many curves are  rotated

by the same angle.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve0             | curve to be rotated          |

------------------------------------------------------------------------------

| PT2                    | origin             | the center of rotation       |

------------------------------------------------------------------------------

| REAL                   | c, s               | cosine and sine of the       |

|                        |                    | rotation angle               |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the input curve.

 

****** Example ******

 

#include <c2vdefs.h>

#include <dmldefs.h>

#include <c2cdefs.h>

 

void rotate_curves ( curvelist )

DML_LIST curvelist ;

{

      REAL rot_angle = 50.0 * PI_OVER_180, rot_c, rot_s;

      PT2 rot_origin ;

      C2_CURVE curve;

      DML_ITEM item ;

      c2v_set ( 1., 2., rot_origin ) ;

      rot_c = cos ( rot_angle ) ;

      rot_s = sin ( rot_angle ) ;

      DML_WALK_LIST ( curvelist, item )

            curve = dml_record ( item );

            c2c_rotate_cs ( curve, rot_origin, rot_c, rot_s );

}

This subroutine rotates a collection of curves by 50 degrees.

 

***>> c2c_scale  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

C2_CURVE c2c_scale ( curve0, origin, factor );

 

****** Description ******

 

This function scales a curve by a scale factor. The center of scaling  is the

point origin.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve0             | the curve to be scaled       |

------------------------------------------------------------------------------

| REAL                   | factor             | scale factor                 |

------------------------------------------------------------------------------

| PT2                    | origin             | the center of scaling        |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the input curve.

 

****** Example ******

 

#include <c2cdefs.h>

 

BOOLEAN scale_arc ( curve )

C2_CURVE curve ;

{

      REAL scale_factor ;

      PT2 scale_origin ;

 

      if ( c2c_get_arc_center ( curve, scale_origin ) )

      {

            printf ( "Scale size : " ) ;

            scanf ( "%lf", &scale_factor ) ;

            c2c_scale ( curve, scale_origin,

                  scale_factor ) ;

            return ( TRUE ) ;

      }

      else return ( FALSE ) ;

}

 

This subroutine scales a curve by the user-supplied factor, with the  center

of the arc as the scaling origin. If the curve is not an arc,  it returns

FALSE without scaling.

 

***>> c2c_select <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

BOOLEAN c2c_select ( curve, pt, band_width, parm,  dist_ptr );

 

****** Description ******

 

This routine determines if a point lies within the given distance  from a

curve. This computation may be used to "select" geometry with  a point.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a curve                      |

------------------------------------------------------------------------------

| PT2                    | pt                 | a point near the curve       |

------------------------------------------------------------------------------

| REAL                   | band_width         | the width of the "select     |

|                        |                    | band" along the curve        |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PARM                   | parm               | the address of a curve       |

|                        |                    | parameter record; if the     |

|                        |                    | point is  inside the "select  |

|                        |                    | band" of the curve, the      |

|                        |                    | curve parameter record       |

|                        |                    | identifies the point on the  |

|                        |                    | curve corresponding to the   |

|                        |                    | orthogonal  projection of pt  |

|                        |                    | onto the curve; if NULL,     |

|                        |                    | this parameter is  not       |

|                        |                    | computed                     |

------------------------------------------------------------------------------

| REAL *                 | dist_ptr           | the address of a REAL which  |

|                        |                    | is set to the orthogonal     |

|                        |                    | distance between the select  |

|                        |                    | point and the curve; if      |

|                        |                    | NULL, this  parameter is not  |

|                        |                    | computed                     |

------------------------------------------------------------------------------

 

****** Return Value. ******

 

The return value is TRUE if the specified point is within the  "select band"

of the curve defined by the band width parameter.  Otherwise the return value

is FALSE.

 

****** Example ******

 

#include <c2vdefs.h>

#include <dmldefs.h>

#include <c2cdefs.h>

 

void select_curve ( curves )

      DML_LIST curves ;

{

      PT2 sel_pt ;

      C2_CURVE curve ;

      DML_ITEM item ;

      PARM_S sel_parm ;

      REAL dist;

 

      c2v_set ( 2.0, 2.0, sel_pt ) ;

      DML_WALK_LIST ( curves, item )

      {

            curve = ( C2_CURVE ) dml_record ( item ) ;

            if ( c2c_select ( curve, sel_pt, 0.01,

                  &sel_parm, &dist ) )

                  break ;

      }

      if ( item != NULL ) {

            printf ( "distance: %lf\n\n", dist );

            c2c_info_curve ( curve, NULL ) ;

      }

}

This program prints information about the first curve on a list  within 0.01

units of the point (2.0,2.0).

 

***>> c2c_self_intersect  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

INT c2c_self_intersect ( curve, inters_list );

 

****** Description ******

 

This function locates points where a curve crosses itself.  The only  types

of curves that can self-intersect are polycurves and B- splines.

 

Intersections are reported in intersection records that are appended  to an

"intersection result" list. The information about the intersections  may be

obtained by traversing int_list and accessing the data  in the intersection

records with the C2_INT_REC access macros.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a curve                      |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| DML_LIST               | inters_list        | the "intersection result"    |

|                        |                    | list; intersection records   |

|                        |                    | are appended  to this list;  |

|                        |                    | this routine expects the     |

|                        |                    | list to be created by the    |

|                        |                    | caller                       |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the number of self-intersection points.  The  coinciding

start and end points of a closed curve are not considered  self-intersection

points.

 

****** Example ******

 

#define SPLINE

#include <dmldefs.h>

#include <c2cdefs.h>

#include <c2ddefs.h>

 

void pr_int_spline ( spline )

C2_CURVE spline;

{

      DML_LIST list = dml_create_list () ;

      C2_INT_REC int_rec;

      DML_ITEM item ;

 

      if ( c2c_self_intersect ( spline, list ) != 0 )

      {

            DML_FOR_LOOP ( dml_first ( list ), item )

            {

                  int_rec = (C2_INT_REC) dml_record (item) ;

                  c2c_info_int_rec ( int_rec, NULL ) ;

            }

            dml_destroy_list ( list, ( PF_VOID ) c2d_free_int_rec );

      }

}

This function intersects a spline with itself and prints out the  results.

The intersection results are found on the "intersection  results list", the

third argument of the intersection routine.

 

***>> c2c_transform <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

C2_CURVE c2c_transform ( curve0, t );

 

****** Description ******

 

This function creates a transformed copy of a specified curve.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve0             | a 2D curve                   |

------------------------------------------------------------------------------

| C2_TRANSFORM           | t                  | a 2D transform               |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the input curve.  If the curve could not be  transformed,

NULL is returned.

 

****** Example ******

 

#include <c2tdefs.h>

#include <c2cdefs.h>

 

void transform_curve ( curve, c, x, y )

C2_CURVE curve ;

PT2 c, x, y;

{

      C2_TRANSFORM t;

 

      c2t_lcs ( c, x, y, t );

      c2c_transform ( curve, t ) ;

}

This subroutine transforms a curve into a given local coordinate  system.

 

***>> c2c_translate  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

C2_CURVE c2c_translate ( curve0, shift );

 

****** Description ******

 

This function translates a curve by a vector.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve0             | the input curve              |

------------------------------------------------------------------------------

| PT2                    | shift              | translation vector           |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the input curve.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2cdefs.h>

 

void move_curve ( curve )

C2_CURVE curve ;

{

      REAL x, y ;

      PT2 v ;

 

      printf ( "Enter translation vector : " ) ;

      scanf ( "%lf %lf", &x, &y ) ;

      c2v_set ( x, y, v ) ;

      c2c_translate ( curve, v ) ;

}

 

This subroutine translates a curve by a user-supplied translation  vector.

 

***>> c2c_trim <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

C2_CURVE c2c_trim ( curve, parm0, parm1 );

 

****** Description ******

 

This function trims away the portions of a specified curve outside  the

interval specified by a pair of curve parameters.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | curve to be trimmed          |

------------------------------------------------------------------------------

| PARM                   | parm0, parm1       | start and end curve          |

|                        |                    | parameters of the curve      |

|                        |                    | interval to keep;  if parm0  |

|                        |                    | is NULL, the start point is  |

|                        |                    | not changed; if parm1 is     |

|                        |                    | NULL, the end point is not   |

|                        |                    | changed                      |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the input curve.

 

****** Example ******

 

#include <c2cdefs.h>

 

void trim_at_points ( curve, p0, p1 )

C2_CURVE curve;

PT2 p0, p1;

{

      PARM_S parm0, parm1;

 

      c2c_project ( curve, p0, &parm0, NULL ) ;

      c2c_project ( curve, p1, &parm1, NULL ) ;

      c2c_trim ( curve, &parm0, &parm1 ) ;

}

This program trims off the portions of a curve that lies outside  the

interval between the projections of two given points.

 

***>> c2c_trim0  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

C2_CURVE c2c_trim0 ( curve, parm );

 

****** Description ******

 

This function trims away the portion of a specified curve between  its start

point and the point specified by a curve parameter.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | curve to be trimmed          |

------------------------------------------------------------------------------

| PARM                   | parm               | curve parameter record       |

|                        |                    | specifying the new position  |

|                        |                    | of the  start point          |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the input curve.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2cdefs.h>

 

void trim_at_point ( curve )

C2_CURVE curve;

{

      PT2 p ;

      PARM_S parm;

 

      c2v_set ( 1.0, 2.0, p ) ;

      c2c_project ( curve, p, &parm ) ;

      c2c_trim0 ( curve, &parm ) ;

}

This program trims off the portion of a curve that lies between the  start

point of the curve and the projection of the point p  onto the curve.

 

***>> c2c_trim1  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

C2_CURVE c2c_trim1 ( curve, parm );

 

****** Description ******

 

This function trims away the portion of a specified curve between  the point

specified by a curve parameter and its end point.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | curve to be trimmed          |

------------------------------------------------------------------------------

| PARM                   | parm               | curve parameter record       |

|                        |                    | specifying the new position  |

|                        |                    | of the  end point            |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the input curve.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2cdefs.h>

 

void trim_at_point ( curve )

C2_CURVE curve;

{

      PT2 p ;

      PARM_S parm;

 

      c2v_set ( 1.0, 2.0, p ) ;

      c2c_project ( curve, p, &parm ) ;

      c2c_trim1 ( curve, &parm ) ;

}

This program trims off the portion of a curve that lies between the

projection of the point p onto the curve and the end point  of the curve.

 

***>> c2c_trim_t <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

C2_CURVE c2c_trim_t ( curve, t0, t1 );

 

****** Description ******

 

This function trims away the portions of a specified curve outside  the

interval specified by a pair of curve parameter values.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | curve to be trimmed          |

------------------------------------------------------------------------------

| REAL                   | t0, t1             | start and end curve          |

|                        |                    | parameter values of the      |

|                        |                    | curve interval  to keep      |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the input curve.

 

****** Example ******

 

#include <c2cdefs.h>

 

void trim_off_ends ( curve )

C2_CURVE curve;

{

      c2c_trim_t ( curve, 0.3, 0.8 ) ;

}

This program trims off the portions of a curve that lie outside the

parameter values 0.3 and 0.8.

 

***>> c2c_trim_t0 <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

C2_CURVE c2c_trim_t0 ( curve, t );

 

****** Description ******

 

This function trims away the portion of a specified curve between  its start

point and the point specified by a curve parameter value.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | curve to be trimmed          |

------------------------------------------------------------------------------

| REAL                   | t                  | curve parameter value        |

|                        |                    | specifying the new position  |

|                        |                    | of the  start point          |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the input curve.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2cdefs.h>

 

void trim_off_start ( curve )

C2_CURVE curve;

{

      c2c_trim_t0 ( curve, 0.3 ) ;

}

This program trims off the portion of a curve that lies between the  start

point of the curve and the parameter value 0.3.

 

***>> c2c_trim_t1  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

C2_CURVE c2c_trim_t1 ( curve, t );

 

****** Description ******

 

This function trims away the portion of a specified curve between  the point

specified by a curve parameter value and its end point.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | curve to be trimmed          |

------------------------------------------------------------------------------

| REAL                   | t                  | curve parameter record       |

|                        |                    | specifying the new position  |

|                        |                    | of the  end point            |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the input curve.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2cdefs.h>

void trim_off_end ( curve )

C2_CURVE curve;

{

      c2c_trim_t1 ( curve, 0.8 ) ;

}

This program trims off the portion of a curve that lies between the

parameter value 0.8 and the end point of the curve.

 

***>> c2d_arc  <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_arc ( ctr, rad, st_angle, sweep,  dir);

 

****** Description ******

 

This function creates an arc given its center, radius, start angle,  sweep

and direction. The angular parameters must be given in radians.  Quantities

in degrees must be converted to radians by multiplying  them by PI_OVER_180.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | ctr                | center of the arc            |

------------------------------------------------------------------------------

| REAL                   | rad                | radius of the arc            |

------------------------------------------------------------------------------

| REAL                   | st_angle           | start angle of the arc; the  |

|                        |                    | start angle is the angular   |

|                        |                    | position  of the start point  |

|                        |                    | of the arc relative to the 3  |

|                        |                    | o'clock direction            |

------------------------------------------------------------------------------

| REAL                   | sweep              | sweep angle of the arc; this  |

|                        |                    | value must be between 0 and  |

|                        |                    | TWO_PI                       |

------------------------------------------------------------------------------

| INT                    | dir                | arc direction; if this value  |

|                        |                    | is 1, the direction of the   |

|                        |                    | created  arc is              |

|                        |                    | counter-clockwise; if this   |

|                        |                    | value is -1, the direction   |

|                        |                    | is clockwise.                |

------------------------------------------------------------------------------

 

****** Return Value. ******

 

The return value is the created curve. If memory could not be allocated  to

create the curve, NULL is returned.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

 

void main ()

{

      C2_CURVE curve ;

      PT2 ctr ;

      REAL radius = 1.5, start_angle = PI, sweep = HALF_PI ;

 

      c2v_set ( 10.0, 10.0, ctr ) ;

      curve = c2d_arc ( ctr, radius, start_angle,

            sweep, 1 ) ;

      if ( curve == NULL )

            printf ( "Error creating arc.\n" ) ;

      c2d_free_curve ( curve );

}

This program creates an arc with center at (10,10), radius 1.5, and  sweeping

from PI to 1.5*PI radians.

 

***>> c2d_arc_3pts  <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_arc_3pts ( pt1, pt2, pt3 );

 

****** Description ******

 

This function creates an arc that passes through the three points.  The arc

starts at pt1, passes through pt2, and ends  at pt3.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | pt1                | first point on the arc       |

------------------------------------------------------------------------------

| PT2                    | pt2                | second point on the arc      |

------------------------------------------------------------------------------

| PT2                    | pt3                | third point on the arc       |

------------------------------------------------------------------------------

 

****** Return Value. ******

 

The return value is the created curve. If memory could not be allocated  to

create the curve, or if the three points are coincident or colinear,  NULL is

returned.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

void main ()

{

      C2_CURVE arc ;

      PT2 pt1, pt2, pt3 ;

      REAL x, y ;

      printf ( "Coordinates of first point : " ) ;

      scanf ( "%lf %lf", &x, &y ) ;

      c2v_set ( x, y, pt1 ) ;

      printf ( "Coordinates of second point : " ) ;

      scanf ( "%lf %lf", &x, &y ) ;

      c2v_set ( x, y, pt2 ) ;

      printf ( "Coordinates of third point : " ) ;

      scanf ( "%lf %lf", &x, &y ) ;

      c2v_set ( x, y, pt3 ) ;

      arc = c2d_arc_3pts ( pt1, pt2, pt3 ) ;

      if ( arc == NULL )

            printf ( "Error creating arc.\n" ) ;

      c2d_free_curve ( arc );

}

This program inputs three points and creates an arc through these  points.

 

***>> c2d_arc_ctr_2pts  <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_arc_ctr_2pts ( ctr, pt1, pt2, dir );

 

****** Description ******

 

This function creates an arc with a specifed center, starting at the  first

point, ending at the second point, and following a specified  direction.  The

distances between the center and each of the two  circumferential points must

not differ by more than the absolute  tolerance.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | ctr                | center point                 |

------------------------------------------------------------------------------

| PT2                    | pt1                | start point                  |

------------------------------------------------------------------------------

| PT2                    | pt2                | end point                    |

------------------------------------------------------------------------------

| INT                    | dir                | direction; +1 denotes        |

|                        |                    | counter-clockwise, -1        |

|                        |                    | denotes  clockwise           |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is an arc centered on the given point with the  given start

point, end point and direction.  If the arc could not be  created, NULL is

returned.

 

****** Example ******

 

#include <c2ddefs.h>

 

C2_CURVE create_arc_2pts ()

{

      C2_CURVE arc ;

      PT2 c, p0, p1 ;

 

      printf ( "enter the arc center\n" ) ;

      scanf ( "%lf%lf", c, c+1 ) ;

      printf ( "enter arc start point\n" ) ;

      scanf ( "%lf%lf", p0, p0+1 ) ;

      printf ( "enter the arc end point\n" ) ;

      scanf ( "%lf%lf", p1, p1+1 ) ;

 

      arc = c2d_arc_ctr_2pts ( c, p0, p1, +1 ) ;

      if ( arc == NULL )

            printf ( "Cannot construct an arc\n" ) ;

      RETURN ( arc ) ;

}

This routine constructs an arc with the user-supplied center, start point and

end point.  If the distances between center and the start and end points

differ by more than the absolute tolerance, the arc is not constructed.

 

***>> c2d_circle  <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_circle ( ctr, rad );

 

****** Description ******

 

This function creates a circle defined by a center point and a radius.  The

start and end points of the circle are at the 3 o'clock position,  and its

direction is always counter-clockwise.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | ctr                | center of the circle         |

------------------------------------------------------------------------------

| REAL                   | rad                | radius of the circle         |

------------------------------------------------------------------------------

 

****** Return Value. ******

 

The return value is the created curve. If memory could not be allocated  to

create the curve, NULL is returned.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

 

void main ()

{

      C2_CURVE circle ;

      PT2 center ;

      REAL x, y, radius ;

 

      printf ( "Enter center x and y, and radius: " ) ;

      scanf ( "%lf %lf %lf", &x, &y, &radius ) ;

      c2v_set ( x, y, center ) ;

      circle = c2d_circle ( center, radius ) ;

      c2d_free_curve ( circle ) ;

}

 

This program inputs a center point and radius and creates a circle.

 

***>> c2d_circle_ctr_pt  <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_circle_ctr_pt ( ctr, pt );

 

****** Description ******

 

This function creates a circle defined by a center point and a through

point. The start and end points of the circle are at the through point,  and

its direction is always counter-clockwise.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | ctr                | the center of the circle     |

------------------------------------------------------------------------------

| PT2                    | pt                 | a point on the circle        |

------------------------------------------------------------------------------

 

****** Return Value. ******

 

The return value is the created curve. If memory could not be allocated  to

create the curve, NULL is returned.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

 

void main ()

{

      C2_CURVE circle ;

      PT2 center, pt ;

      REAL x = 1.0, y = 2.0;

 

      c2v_set ( x, y, center ) ;

      printf ( "Coordinates of a point on circle : " ) ;

      scanf ( "%lf %lf", &x, &y ) ;

      c2v_set ( x, y, pt) ;

      circle = c2d_circle_ctr_pt ( center, pt ) ;

      c2d_free_curve ( circle ) ;

}

<%-2>This program creates a circle with center point (1,2), passing  through

an input point. <%0>

 

***>> c2d_copy  <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_copy ( curve0 );

 

****** Description ******

 

This function creates a copy of a curve.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve0             | a curve                      |

------------------------------------------------------------------------------

 

****** Return Value. ******

 

The return value is the copy. If memory could not be allocated to  create the

copy, NULL is returned.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

 

void main ()

{

      C2_CURVE curve, curve_copy ;

      PT2 ctr ;

 

      c2v_set ( 2.0, 3.0, ctr ) ;

      curve = c2d_circle ( ctr, 5.0 ) ;

      curve_copy = c2d_copy ( curve ) ;

      c2d_free_curve ( curve_copy ) ;

}

This program creates a circle with center at (2,3) with radius 5,  and makes

a copy of the circle.

 

***>> c2d_ellipse <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_ellipse ( ctr, major_axis, minor_axis,  angle );

 

****** Description ******

 

This function creates an ellipse defined by its center, its major  axis and

minor axis and its angle of inclination. The angle of  inclination must be

specified in radians; multiply quantities in  degrees by PI_OVER_180 to

obtain the radian equivalent.

 

All source code of programs that call this function must be  compiled with

the symbol SPLINE defined.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | ctr                | the center of the ellipse    |

------------------------------------------------------------------------------

| REAL                   | major_axis         | the length of the major axis  |

------------------------------------------------------------------------------

| REAL                   | minor_axis         | the length of the minor axis  |

------------------------------------------------------------------------------

| REAL                   | angle              | the angle of inclination of  |

|                        |                    | the major axis with respect  |

|                        |                    | to  the 3 o'clock direction  |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the created curve. If memory could not be allocated  to

create the curve, NULL is returned.

 

****** Example ******

 

#define SPLINE

#include <c2vdefs.h>

#include <c2ddefs.h>

void main ()

{

      PT2 c ;

      REAL maj_axis=4.0, min_axis=2.0, angle = 45.0*PI_OVER_180;

      C2_CURVE ellipse ;

      c2v_set ( 0.0, 0.0, c ) ;

      ellipse = c2d_ellipse ( c, maj_axis, min_axis, angle );

      if ( ellipse == NULL ) printf ( "Error creating curve.\n" );

}

This program creates an ellipse with center (0,0), major axis of 4,  minor

axis of 2, and angle of inclination of 45 degrees.

 

***>> c2d_free_curve  <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

void c2d_free_curve ( curve );

 

****** Description ******

 

This function frees a curve.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | the curve to free; it is a   |

|                        |                    | good practice to set this    |

|                        |                    | parameter  to NULL after     |

|                        |                    | calling this routine         |

------------------------------------------------------------------------------

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

#include <c2cdefs.h>

 

void main ()

{

      C2_CURVE curve ;

      PT2 ctr ;

 

      c2v_set ( 0.0, 0.0, ctr ) ;

      curve = c2d_circle ( ctr, 3.0 ) ;

      if ( curve == NULL )

            printf ( "Can't create curve.\n" ) ;

      else

      {

            c2c_info_curve ( curve, NULL ) ;

            c2d_free_curve ( curve ) ;

      }

}

 

This program creates a circle, prints information about the circle  to the

screen, and then frees the memory used by it.

 

***>> c2d_free_int_rec  <<***

 

****** Summary ******

 

#include <c2cdefs.h>

 

void c2d_free_int_rec ( int_rec );

 

****** Description ******

 

This function frees an intersection record.  Typically, this routine  is used

with dml_destroy_list to dispose of a list of  intersection records.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_INT_REC             | int_rec            | an intersection record       |

------------------------------------------------------------------------------

 

****** Example ******

 

See c2c_intersect.

 

***>> c2d_free_point <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

void c2d_free_point ( point );

 

****** Description ******

 

This function frees a point created with c2d_point.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2 *                  | point              | the point to free; it is a   |

|                        |                    | good practice to set this    |

|                        |                    | parameter  to NULL after     |

|                        |                    | calling this routine         |

------------------------------------------------------------------------------

 

****** Example ******

 

See c2d_point.

 

***>> c2d_line  <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_line ( ept0, ept1 );

 

****** Description ******

 

This function creates a line between two points.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | ept0               | the start point of the line  |

------------------------------------------------------------------------------

| PT2                    | ept1               | the end point of the line    |

------------------------------------------------------------------------------

 

****** Return Value. ******

 

The return value is the created curve. If memory could not be allocated  to

create the curve, NULL is returned.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

void main ()

{

      PT2 endpt1, endpt2 ;

      REAL x, y ;

      C2_CURVE line ;

 

      printf ( "Coordinates of first point : " ) ;

      scanf ( "%lf %lf", &x, &y ) ;

      c2v_set ( x, y, endpt1 ) ;

      printf ( "Coordinates of second point : " ) ;

      scanf ( "%lf %lf", &x, &y ) ;

      c2v_set ( x, y, endpt2 ) ;

      line = c2d_line ( endpt1, endpt2 ) ;

      c2d_free_curve ( line );

}

This program creates a line passing through two points.

 

***>> c2d_line_dir  <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_line_dir ( ept0, dir_vec );

 

****** Description ******

 

This function creates a line defined by a point and a direction vector.  The

length of the line is the same as the length of the vector.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | ept0               | the start point of the line  |

------------------------------------------------------------------------------

| PT2                    | dir_vec            | direction vector of the      |

|                        |                    | line; the vector sum of the  |

|                        |                    | start  point and this vector  |

|                        |                    | is the end point of the line  |

------------------------------------------------------------------------------

 

****** Return Value. ******

 

The return value is the created curve. If memory could not be allocated  to

create the curve, NULL is returned.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

void main ()

{

      PT2 endpt1, dir_vec ;

      REAL x, y ;

      C2_CURVE line ;

      printf ( "Coordinates of first point : " ) ;

      scanf ( "%lf %lf", &x, &y ) ;

      c2v_set ( x, y, endpt1 ) ;

      printf ( "Coordinates of direction vector : " ) ;

      scanf ( "%lf %lf", &x, &y ) ;

      c2v_set ( x, y, dir_vec ) ;

      line = c2d_line_dir ( endpt1, dir_vec ) ;

      c2d_free_curve ( line );

}

This program inputs a point and a direction vector and creates a line

segment starting at the point and having the given direction.

 

***>> c2d_mirror_dir  <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_mirror_dir ( curve0, origin, direction  );

 

****** Description ******

 

This function creates a curve which is the mirror image of the input  curve

about a line. The line is defined by point and a direction vector  which

points in the mirroring direction.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve0             | a curve; this curve is not   |

|                        |                    | modified by this operation   |

------------------------------------------------------------------------------

| PT2                    | origin             | a point on the mirror line   |

------------------------------------------------------------------------------

| PT2                    | direction          | vector normal to the mirror  |

|                        |                    | line                         |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a curve which is the mirror image of the input  curve.

NULL is returned if the curve could not be created.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

 

void main ()

{

      PT2 center, p1, dir ;

      C2_CURVE arc, arc1 ;

      c2v_set ( 2.0, 1.0, center ) ;

      arc = c2d_arc ( center, 3.0, 0.0, PI, 1 ) ;

      c2v_set ( 0.0, 0.0, p1 ) ;

      c2v_set ( 1.0, 1.5, dir ) ;

      arc1 = c2d_mirror_dir ( arc, p1, dir ) ;

      c2d_free_curve ( arc );

      c2d_free_curve ( arc1 );

}

This program creates an arc and its mirror image (arc1) over a line  passing

through (0,0) and perpendicular to the direction (1,1.5).

 

***>> c2d_mirror_line  <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_mirror_line ( curve0, line );

 

****** Description ******

 

This function creates a curve which is the mirror image of the input  curve

about a line. The line is defined by an array of two points.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve0             | a curve; this curve is not   |

|                        |                    | modified                     |

------------------------------------------------------------------------------

| PT2                    | line[2]            | the points defining the      |

|                        |                    | mirror line                  |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a curve which is the mirror image of the input  curve.

NULL is returned if the curve could not be created.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

 

void main ()

{

      PT2 center, pts[2] ;

      C2_CURVE arc, arc1 ;

      c2v_set ( 2.0, 1.0, center ) ;

      arc = c2d_arc ( center, 3.0, 0.0, PI, 1 ) ;

      c2v_set ( 0.0, 0.0, pts[0] ) ;

      c2v_set ( 1.0, 1.5, pts[1] ) ;

      arc1 = c2d_mirror_line ( arc, pts ) ;

      c2d_free_curve ( arc );

      c2d_free_curve ( arc1 );

}

This program creates an arc and its mirror image arc1 over  the line passing

through (0.0,0.0) and (1.0,1.5).

 

***>> c2d_offset  <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

INT c2d_offset ( curve, offset, offset_list ) ;

 

****** Description ******

 

This function creates the offset or "parallel" curve of a curve. The  offset

curve is the curve which runs a constant distance w  to the right of the

input curve as it is traversed from its  start point towards its end point.

To obtain the leftward offset,  specify w as a negative number.

 

The offset curve is appended to offset_list. If curve0  is a polycurve or a

B-spline, the result may consist of several  curves, or no curve at all.

Also, if an arc is offset inward by a  distance greater than its radius, no

curve is produced.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a curve                      |

------------------------------------------------------------------------------

| REAL                   | offset             | the offset distance          |

------------------------------------------------------------------------------

| DML_LIST               | offset_list        | the list to which the offset  |

|                        |                    | curve(s) are appended        |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the number of curves created by the offset  operation.

Offsets of splines may result in either one curve,  several curves, or no

curve at all.

 

This value is 0 if the offset does not exist. For example, this is  the case

when a circular arc is offset inwards by a distance greater  than its radius.

 

****** Example ******

 

#include <dmldefs.h>

#include <c2vdefs.h>

#include <c2ddefs.h>

#include <c2cdefs.h>

 

void main ()

{

      DML_LIST offset_curves = dml_create_list () ;

      DML_ITEM item ;

      C2_CURVE curve ;

      REAL offset_d ;

      PT2 ctr ;

 

      c2v_set ( 0.0, 0.0, ctr ) ;

      curve = c2d_circle ( ctr, 3.0 ) ;

      printf ( "Enter offset distance : " ) ;

      scanf ( "%lf", &offset_d ) ;

      (void)c2d_offset ( curve, offset_d, offset_curves ) ;

      DML_WALK_LIST ( offset_curves, item )

            c2c_info_curve ( dml_record ( item ), NULL ) ;

      dml_destroy_list ( offset_curves,

            ( PF_VOID ) c2d_free_curve ) ;

      c2d_free_curve ( curve );

}

This program creates a circle and offsets it by an input distance.

 

***>> c2d_offset_curve <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_offset_curve ( curve, offset ) ;

 

****** Description ******

 

This function creates the offset or "parallel" curve of a curve. The  offset

curve is the curve which runs a constant distance w  to the right of the

input curve as it is traversed from its  start point towards its end point.

To obtain the leftward offset,  specify w as a negative number.

 

This function accepts only line and arc curves.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a curve                      |

------------------------------------------------------------------------------

| REAL                   | offset             | the offset distance          |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the offset curve.  NULL is returned if the input  curve

could not be offset, which is the case when an arc is offset  inward by a

distance greater than its radius.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

#include <c2cdefs.h>

 

void main ()

{

      C2_CURVE curve, curve1 ;

      REAL offset_d ;

      PT2 ctr ;

      c2v_set ( 0.0, 0.0, ctr ) ;

      curve = c2d_circle ( ctr, 3.0 ) ;

      printf ( "Enter offset distance : " ) ;

      scanf ( "%lf", &offset_d ) ;

      curve1 = c2d_offset_curve ( curve, offset_d ) ;

      c2c_info_curve ( curve1, NULL ) ;

      c2d_free_curve ( curve1 ) ;

      c2d_free_curve ( curve ) ;

}

This program creates a circle and offsets it by an input distance.

 

***>> c2d_offset_curve_through <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_offset_curve_through ( curve, pt );

 

****** Description ******

 

This function creates the offset or "parallel" curve of a curve. The  offset

curve is the curve which runs a constant distance from the  original curve

through the point pt.

 

This function accepts only line and arc curves.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | the original curve           |

------------------------------------------------------------------------------

| PT2                    | pt                 | the point through which the  |

|                        |                    | offset must pass             |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the offset curve.  NULL is returned if the curve  could

not be offset, which is the case if the curve is an arc, and  the point is at

the center of the arc.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

#include <c2cdefs.h>

 

void main ()

{

      C2_CURVE curve, curve1 ;

      REAL x, y ;

      PT2 offset_pt, ctr ;

      c2v_set ( 0.0, 0.0, ctr ) ;

      curve = c2d_circle ( ctr, 3.0 ) ;

      printf ( "Coordinates to offset through : " ) ;

      scanf ( "%lf %lf", &x, &y ) ;

      c2v_set ( x, y, offset_pt ) ;

      curve1 = c2d_offset_curve_through ( curve, offset_pt );

      c2c_info_curve ( curve1, NULL );

      c2d_free_curve ( curve1 );

      c2d_free_curve ( curve );

}

This program creates a circle and offsets it through the input point.

 

***>> c2d_offset_through  <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

INT c2d_offset_through ( curve, pt, offset_list );

 

****** Description ******

 

This function creates the offset or "parallel" curve of a curve. The  offset

curve is the curve which runs a constant distance from the  original curve

through the point pt.

 

The offset curve is appended to offset_list. If the input curve  is a spline,

the offset may consist of several curves, or no curve  at all.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | the original curve           |

------------------------------------------------------------------------------

| PT2                    | pt                 | the point through which the  |

|                        |                    | offset must pass             |

------------------------------------------------------------------------------

| DML_LIST               | offset_list        | the list the offset curve(s)  |

|                        |                    | are appended                 |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the number of curves created by the offset operation.

Offsets of splines may result in more than one curve.

 

****** Example ******

 

#include <dmldefs.h>

#include <c2vdefs.h>

#include <c2ddefs.h>

#include <c2cdefs.h>

 

void main ()

{

      DML_LIST offset_curves = dml_create_list () ;

      DML_ITEM item ;

      C2_CURVE curve ;

      REAL x, y ;

      PT2 offset_pt, ctr ;

 

      c2v_set ( 0.0, 0.0, ctr ) ;

      curve = c2d_circle ( ctr, 3.0 ) ;

      printf ( "Coordinates to offset through : " );

      scanf ( "%lf %lf", &x, &y ) ;

      c2v_set ( x, y, offset_pt ) ;

      c2d_offset_through ( curve, offset_pt, offset_curves );

      DML_WALK_LIST ( offset_curves, item )

            c2c_info_curve ( ( C2_CURVE )dml_record(item), NULL );

}

This program creates a circle and offsets it through the input point.

 

***>> c2d_pcurve_add_arc_2pts <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_pcurve_add_arc_2pts ( curve, a0, a1 );

 

****** Description ******

 

This function adds an arc segment to a polycurve.  The arc segment  is

defined by three points: the end point of the polycurve, and two  additional

points.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a polycurve                  |

------------------------------------------------------------------------------

| PT2                    | a0, a1             | the second and third through  |

|                        |                    | points for the arc segment   |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the polycurve.  If the arc could not be  constructed,

NULL is returned.

 

****** Example ******

 

See c2d_pcurve_init.

 

***>> c2d_pcurve_add_arc_ctr_pt <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_pcurve_add_arc_ctr_pt ( curve, ctr, pt );

 

****** Description ******

 

This function adds an arc to the end of a polycurve.  The arc ends  at a

specified point, and has a specified center.  The distances  between the

center and each of the two circumferential points must  not differ by more

than the absolute tolerance.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a polycurve                  |

------------------------------------------------------------------------------

| PT2                    | ctr, pt            | the center and the end point  |

|                        |                    | of the arc segment           |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the polycurve.  If the arc segment could not be

constructed, NULL is returned.

 

****** Example ******

 

See c2d_pcurve_init.

 

***>> c2d_pcurve_add_arc_tan <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_pcurve_add_arc_tan ( curve, a );

 

****** Description ******

 

This function adds an arc segment to the end of a polycurve.  The  arc is

tangent to the end of the polycurve, and ends at a specified  point.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a polycurve                  |

------------------------------------------------------------------------------

| PT2                    | a                  | the end point of the arc     |

|                        |                    | segment                      |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the polycurve.  If the arc could not be  constructed,

NULL is returned.

 

****** Example ******

 

See c2d_pcurve_init.

 

***>> c2d_pcurve_add_line <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_pcurve_add_line ( curve, a );

 

****** Description ******

 

This function adds a line segment to a polycurve. The line segment  ends at a

specified point.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a polycurve                  |

------------------------------------------------------------------------------

| PT2                    | a                  | the end point of the line    |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the polycurve.  If the line could not be  constructed,

NULL is returned.

 

****** Example ******

 

See c2d_pcurve_init.

 

***>> c2d_pcurve_add_line_tan <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_pcurve_add_line_tan ( curve, a );

 

****** Description ******

 

This function adds a line segment to the end of a polycurve.  The  line

segment is tangent to the end of the polycurve, and ends at a  specified

point.  If the specified point does not lie on the ray  tangent to the end of

the polycurve, the line segment ends at the  projection of the specified

point onto the ray.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a polycurve                  |

------------------------------------------------------------------------------

| PT2                    | a                  | the end point of the line    |

|                        |                    | segment                      |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the polycurve.  If the line could not be  constructed,

NULL is returned.

 

****** Example ******

 

See c2d_pcurve_init.

 

***>> c2d_pcurve_close <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_pcurve_close ( curve );

 

****** Description ******

 

This function adds a line segment to close a polycurve.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a polycurve                  |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the polycurve.  If the line could not be  constructed,

NULL is returned.

 

****** Example ******

 

See c2d_pcurve_init.

 

***>> c2d_pcurve_init <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_pcurve_init ( a );

 

****** Description ******

 

This function begins a polycurve at a specified point.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | the starting point for the   |

|                        |                    | polycurve                    |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a polycurve.  If memory could not be allocated  for the

polycurve, NULL is returned.

 

****** Example ******

 

#include <c2ddefs.h>

 

C2_CURVE build_pcurve ( p1, p2, p31, p32, p4,

      p5, ctr5, p6, p7 )

PT2 p1, p2, p31, p32, p4, p5, ctr5, p6, p7;

{

      C2_CURVE pc;

 

      pc = c2d_pcurve_init ( p1 );

      c2d_pcurve_add_line ( pc, p2 );

      c2d_pcurve_add_arc_2pts ( pc, p31, p32 );

      c2d_pcurve_add_arc_tan ( pc, p4 );

      c2d_pcurve_add_arc_ctr_pt ( pc, p5, ctr5 );

      c2d_pcurve_add_line_tan ( pc, p6 );

      c2d_pcurve_add_line ( pc, p7 );

      c2d_pcurve_remove_last ( pc );

      c2d_pcurve_close ( pc );

 

      return ( pc );

}

This function constructs a polycurve that contains both lines and  arcs.

 

***>> c2d_pcurve_remove_last <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_pcurve_remove_last ( curve );

 

****** Description ******

 

This function removes the last segment from a polycurve.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a polycurve                  |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the polycurve.  If the segment could not be  removed,

NULL is returned.

 

****** Example ******

 

See c2d_pcurve_init.

 

***>> c2d_pcurve_segment <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_pcurve_segment ( curve, i );

 

****** Description ******

 

This function creates a C2_CURVE from the ith segment of a  polycurve.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a polycurve                  |

------------------------------------------------------------------------------

| INT                    | i                  | an index of a segment; a     |

|                        |                    | value of 0 denotes the first  |

|                        |                    |  segment                     |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the polycurve.  If the segment could not be  created,

NULL is returned.

 

****** Example ******

 

#include <c2ddefs.h>

#include <dmldefs.h>

 

DML_LIST pcurve_segments ( pcurve )

C2_CURVE pcurve;

{

      DML_LIST list = dml_create_list();

      INT i = 0;

      C2_CURVE curve;

      for ( curve = c2d_pcurve_segment ( pcurve, i++ );

            curve != NULL;

            curve = c2d_pcurve_segment ( pcurve, i++ ) )

            dml_append_data ( list, curve );

      return ( list );

}

This function creates a curve for each of the segments of a  polycurve.

 

***>> c2d_pcurve_through <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_pcurve_through ( a, n );

 

****** Description ******

 

This function creates a polycurve through a set of points.  All  segments of

the polycurve are linear.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a[]                | an array of n through points  |

------------------------------------------------------------------------------

| INT                    | n                  | the number of points in the  |

|                        |                    | array                        |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the polycurve.  If memory could not be allocated  for the

polycurve, NULL is returned.

 

****** Example ******

 

#include <c2ddefs.h>

#include <c2vdefs.h>

C2_CURVE build_pcurve ( a, n )

 

PT2 a[];

INT n;

{

      C2_CURVE pc = c2d_pcurve_through ( a, n );

      if ( !c2v_ident_pts ( a[0], a[n-1] ) )

            c2d_pcurve_close ( pc );

      return ( pc );

}

This function builds a closed polycurve through a set of points.

 

***>> c2d_point <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

PT2 *c2d_point ( x, y );

 

****** Description ******

 

This function creates a point with specified coordinates.

 

****** Input ******

 

------------------------------------------------------------------------------

| REAL                   | x, y               | the coordinates of the point  |

------------------------------------------------------------------------------

 

****** Return Value. ******

 

The return value is the created point.  If memory could not be allocated  to

create the point, NULL is returned.

 

****** Example ******

 

#include <c2ddefs.h>

 

void main ()

{

      PT2 *p ;

 

      p = c2d_point ( 4.0, 3.0 ) ;

      c2d_free_point ( p ) ;

}

 

This program creates a point, and then frees it.

 

***>> c2d_ray  <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_ray ( origin, angle );

 

****** Description ******

 

This function creates a line defined by a start point and a  direction angle.

 The length of the list is the world size. The  angle must be expressed in

radians.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | origin             | start point                  |

------------------------------------------------------------------------------

| REAL                   | angle              | direction angle; must be     |

|                        |                    | expressed in radians         |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a pointer to a curve that is a line starting at  the

given point and running in the direction specified by the angle.  If  memory

could not be allocated for the curve, NULL is returned.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

 

void main()

{

      PT2 p;

      REAL t = PI / 5.0;

      C2_CURVE ray;

      c2v_set ( 1.0, 2.0, p );

      ray = c2d_ray ( p, t );

      c2d_free_curve ( ray );

}

This program creates a line that begins at (1,2) and runs in the direction

corresponding to PI / 5.

 

***>> c2d_rotate  <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_rotate ( curve0, origin, angle );

 

****** Description ******

 

This function creates a curve which is the rotation of the input curve  about

a point by an angle. The angle must be given in radians.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve0             | curve to be rotated; this    |

|                        |                    | curve is not modified by     |

|                        |                    | this operation               |

------------------------------------------------------------------------------

| PT2                    | origin             | the center of rotation       |

------------------------------------------------------------------------------

| REAL                   | angle              | the rotation angle           |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a curve that is the rotation of the input curve.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

 

C2_CURVE rot_curve ( curve )

C2_CURVE curve ;

{

      REAL x, y, angle ;

      PT2 rot_origin ;

      C2_CURVE curve1 ;

      printf ( "Coordinates of rotation origin : " ) ;

      scanf ( "%lf %lf", &x, &y ) ;

      c2v_set ( x, y, rot_origin ) ;

      printf ( "Angle to rotate ( in degrees ) : " ) ;

      scanf ( "%lf", &angle ) ;

      curve1 = c2d_rotate ( curve, rot_origin, PI_OVER_180 *

            angle ) ;

      return ( curve1 ) ;

}

This subroutine returns a curve which is the rotation of the input  curve.

 

***>> c2d_rotate_cs  <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_rotate_cs ( curve0, origin, c, s );

 

****** Description ******

 

This function creates a curve which is the rotation of the input curve  about

a point by an angle. The angle is specified by its cosine and  sine, rather

than the angle itself.

 

This function improves the efficiency of loops in which many curves  are

rotated by the same angle.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve0             | curve to be rotated; this    |

|                        |                    | curve is not modified by     |

|                        |                    | this operation               |

------------------------------------------------------------------------------

| PT2                    | origin             | rotation origin              |

------------------------------------------------------------------------------

| REAL                   | c, s               | cosine and sine of the       |

|                        |                    | rotation angle               |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a curve that is the rotation of the input curve.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

 

C2_CURVE rot_curve ( curve )

C2_CURVE curve ;

{

      REAL x, y, angle, c, s ;

      PT2 origin ;

 

      printf ( "Coordinates of rotation origin : " ) ;

      scanf ( "%lf %lf", &x, &y ) ;

      c2v_set ( x, y, origin ) ;

      printf ( "Angle to rotate ( in degrees ) : " ) ;

      scanf ( "%lf", &angle ) ;

      angle *= PI_OVER_180 ;

      c = cos ( angle ) ;

      s = sin ( angle ) ;

      return ( c2d_rotate_cs ( curve, origin, c, s ) );

}

 

This subroutine takes a curve and returns a curve which is the original

curve rotated according to the input conditions. The angle must be  converted

to radians.

 

***>> c2d_scale  <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_scale ( curve0, origin, factor );

 

****** Description ******

 

This function creates a curve by scaling the input curve by a scale  factor

about given origin.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve0             | the curve to be scaled; this  |

|                        |                    | curve is not modified by the  |

|                        |                    |  routine                     |

------------------------------------------------------------------------------

| REAL                   | factor             | scale factor                 |

------------------------------------------------------------------------------

| PT2                    | origin             | the center of scaling        |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a scaled copy of the input curve.

 

****** Example ******

 

#include <c2cdefs.h>

#include <c2ddefs.h>

 

C2_CURVE scale_arc ( curve )

C2_CURVE curve;

{

      PT2 scale_origin ;

      C2_CURVE curve1 = NULL;

      if ( c2c_get_arc_center ( curve, scale_origin ) )

            curve1 = c2d_scale ( curve, scale_origin, 0.5 );

      return ( curve1 ) ;

}

This subroutine returns a scaled copy of the input curve if it is  an arc.

The scaling origin is the center of the arc.

 

***>> c2d_spline <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_spline ( a, n );

 

****** Description ******

 

This function creates a spline that passes through a set of points.

 

All source code of a program that calls this function must be  compiled with

the symbol SPLINE defined.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a[n]               | the array of through points  |

------------------------------------------------------------------------------

| INT                    | n                  | the number of through points  |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the created curve. If memory could not be allocated  to

create the curve, NULL is returned.

 

****** Example ******

 

#define SPLINE

#include <dmldefs.h>

#include <c2ddefs.h>

 

void make_spline ( ptlist )

DML_LIST ptlist;

{

      C2_CURVE spline ;

      PT2 *points ;

      INT size ;

 

      size = dml_length ( ptlist ) ;

      points = (PT2 *) dml_create_list_to_array (ptlist, 

            sizeof (PT2) ) ;

      spline = c2d_spline ( points, size ) ;

      if ( spline == NULL )

            printf ( "Error creating spline.\n" ) ;

}

 

This program creates a spline through a set of points on a list.

 

***>> c2d_spline_clsd  <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_spline_clsd ( a, n, knot_options );

 

****** Description ******

 

This function creates a closed spline passing through a set of points.  The

end point of the spline, which will have the same coordinates  as the start

point, should not be included in the set of through points.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a[n]               | array of through points      |

------------------------------------------------------------------------------

| INT                    | n                  | number of through points     |

------------------------------------------------------------------------------

| C2_KNOT_OPTIONS        | knot_options       | the parametrization option;  |

|                        |                    | in general, use C2_DEFAULT   |

------------------------------------------------------------------------------

 

Valid parameterization options are:

 

______________________________________________________________________________

| Option                               | Meaning                             |

|----------------------------------------------------------------------------|

| C2_DEFAULT                           | non-uniform parameterization based  |

|                                      | on the square root of the           |

|                                      | distance between through points     |

| C2_UNIFORM                           | uniform parameterization            |

| C2_CLSC_UNI                          | uniform parameterization with       |

|                                      | coalesced start and end knots       |

| C2_NONUNI                            | non-uniform parameterization based  |

|                                      | on the distance between  through    |

|                                      | points; corresponds approximately   |

|                                      | to the parameterization  based on   |

|                                      | the spline arc length               |

|                                      | value is the created curve. If      |

|                                      | memory could not be allocated  to   |

|                                      | create the curve, NULL is           |

|                                      | returned.                           |

------------------------------------------------------------------------------

 

****** Example ******

 

#define SPLINE

#include <dmldefs.h>

#include <c2vdefs.h>

#include <c2ddefs.h>

 

void make_spline ( ptlist )

DML_LIST ptlist ;

{

      C2_CURVE spline ;

      PT2 *points ;

      INT size ;

 

      size = dml_length ( ptlist ) ;

      points = (PT2 *) dml_create_list_to_array (ptlist, 

            sizeof (PT2) ) ;

            if ( c2v_ident_pts ( points[0], points[size-1] ) )

            size-- ;

      spline = c2d_spline_clsd ( points, size,

            C2_DEFAULT ) ;

      if ( spline == NULL )

            printf ( "Error creating spline.\n" ) ;

}

 

This program creates a closed spline passing through points on a  list. If

the last point is the same as the first, it is discarded.

 

***>> c2d_spline_knots <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_spline_knots ( a, n, knot_options   );

 

****** Description ******

 

This function creates a spline that passes through a set of points  and is

parametrized according to a particular convention. The parametrization

convention is specified with the knot_options parameter.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2 *                  | a                  | the array of through points  |

------------------------------------------------------------------------------

| INT                    | n                  | the number through points    |

------------------------------------------------------------------------------

| C2_KNOT_OPTIONS        | knot_options       | the parametrization          |

|                        |                    | convention; generally        |

|                        |                    | C2_DEFAULT should  be used   |

------------------------------------------------------------------------------

 

Valid parameterization options are:

 

______________________________________________________________________________

| Option                               | Meaning                             |

|----------------------------------------------------------------------------|

| C2_DEFAULT                           | non-uniform parameterization based  |

|                                      | on the square root of the           |

|                                      | distance between through points     |

| C2_UNIFORM                           | uniform parameterization            |

| C2_CLSC_UNI                          | uniform parameterization with       |

|                                      | coalesced start and end knots       |

| C2_NONUNI                            | non-uniform parameterization based  |

|                                      | on the distance between  through    |

|                                      | points; corresponds approximately   |

|                                      | to the parameterization  based on   |

|                                      | the spline arc length               |

|                                      | value is the created curve. If      |

|                                      | memory could not be allocated  to   |

|                                      | create the curve, NULL is           |

|                                      | returned.                           |

------------------------------------------------------------------------------

 

****** Example ******

 

#define SPLINE

#include <dmldefs.h>

#include <c2ddefs.h>

 

void make_spline ( ptlist )

DML_LIST ptlist ;

{

      C2_CURVE spline ;

      PT2 *points ;

      INT size ;

 

      size = dml_length ( ptlist ) ;

      points = (PT2 *) dml_create_list_to_array (ptlist, 

            sizeof (PT2) ) ;

      spline = c2d_spline_knots ( points, size,

            C2_NONUNI ) ;

      if ( spline == NULL )

            printf ( "Error creating spline.\n" ) ;

}

 

This program creates a spline passing through the points on a list.  The

spline is parametrized using the C2_NONUNI convention.

 

***>> c2d_spline_tan  <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_spline_tan ( a, n, knot_opts, tan0, tan0_opts,  tan1,      tan1_opts

);

 

****** Description ******

 

This function creates a spline that passes through a given set of  points and

has optionally-specified start and end tangents.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2 *                  | a                  | array of through points      |

------------------------------------------------------------------------------

| INT                    | n                  | number of through points     |

------------------------------------------------------------------------------

| C2_KNOT_OPTIONS        | knot_opts          | the parametrization          |

|                        |                    | convention; in general, use  |

|                        |                    | C2_DEFAULT                   |

------------------------------------------------------------------------------

| PT2                    | tan0               | the start tangent vector     |

------------------------------------------------------------------------------

| C2_TAN_OPTIONS         | tan0_opts          | the start tangent convention  |

------------------------------------------------------------------------------

| PT2                    | tan1               | the end tangent vector       |

------------------------------------------------------------------------------

| C2_TAN_OPTIONS         | tan1_opts          | the end tangent convention   |

------------------------------------------------------------------------------

 

Valid parameterization options are:

 

______________________________________________________________________________

| Option                               | Meaning                             |

|----------------------------------------------------------------------------|

| C2_DEFAULT                           | non-uniform parameterization based  |

|                                      | on the square root of the           |

|                                      | distance between through points     |

| C2_UNIFORM                           | uniform parameterization            |

| C2_CLSC_UNI                          | uniform parameterization with       |

|                                      | coalesced start and end knots       |

| C2_NONUNI                            | non-uniform parameterization based  |

|                                      | on the distance between  through    |

|                                      | points; corresponds approximately   |

|                                      | to the parameterization  based on   |

|                                      | the spline arc length               |

| ngent                                | on     Meaning                          |

------------------------------------------------------------------------------

 

the input vector

 

vector

 

****** Return Value ******

 

The return value is the created curve. If memory is could not be allocated

to create the curve, NULL is returned.

 

****** Example ******

 

#define SPLINE

#include <dmldefs.h>

#include <c2vdefs.h>

#include <c2ddefs.h>

 

void make_spline ( ptlist )

DML_LIST ptlist ;

{

      C2_CURVE spline ;

      PT2 *points, tan0, tan1 ;

      INT size ;

 

      size = dml_length ( ptlist ) ;

      points = (PT2 *) dml_create_list_to_array (ptlist, 

            sizeof (PT2) ) ;

      c2v_set ( -1.0, 0.0, tan0 ) ;

      c2v_set ( 1.0, 0.0, tan1 ) ;

      spline = c2d_spline_tan ( points, size,

      C2_DEFAULT, tan0, C2_DEF_TAN, tan1, C2_DEF_TAN );

      if ( spline == NULL )

            printf ( "Error creating spline.\n" ) ;

}

 

This program creates a spline through the points on a list, with the

endpoints having the corresponding tangent vectors.

 

***>> c2d_transform <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_transform ( curve0, t );

 

****** Description ******

 

This function creates a transformed copy of a specified curve.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve0             | a 2D curve                   |

------------------------------------------------------------------------------

| C2_TRANSFORM           | t                  | a 2D transform               |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the transformed copy of the specified curve.  If  memory

could not be allocated to create the copy, or the curve could  not be

transformed, NULL is returned.

 

****** Example ******

 

#include <c2tdefs.h>

#include <c2ddefs.h>

 

C2_CURVE transform_curve ( curve, c, x, y )

C2_CURVE curve ;

PT2 c, x, y;

{

      C2_TRANSFORM t;

      C2_CURVE transformed_curve ;

 

      c2t_lcs ( c, x, y, t );

      transformed_curve = c2d_transform ( curve, t ) ;

      return ( transformed_curve ) ;

}

This subroutine creates a curve which is a copy of the given curve

transformed into a given local coordinate system. It returns the  created

curve.

 

***>> c2d_translate  <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_translate ( curve0, shift );

 

****** Description ******

 

This function creates a new curve which is a translation of the input  curve.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve0             | the input curve; this curve  |

|                        |                    | is not modified by the       |

|                        |                    | routine                      |

------------------------------------------------------------------------------

| PT2                    | shift              | the translation vector       |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a curve that is the translation of the input curve.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2ddefs.h>

 

C2_CURVE move_curve ( curve )

C2_CURVE curve ;

{

      REAL x, y ;

      PT2 v ;

      C2_CURVE curve1 ;

 

      printf ( "Enter translation vector : " ) ;

      scanf ( "%lf %lf", &x, &y ) ;

      c2v_set ( x, y, v ) ;

      curve1 = c2d_translate ( curve, v ) ;

      return ( curve1 ) ;

}

This subroutine translates a given curve by a user-specified translation

vector, and returns the translated curve.

 

***>> c2d_trim  <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_trim ( curve, parm0, parm1 );

 

****** Description ******

 

This function creates a copy of a specified curve, and trims away  the start

and end portions of the copy, leaving only that part which  is between two

specified curve parameters.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | a curve; it is not altered   |

|                        |                    | by the trimming operation    |

------------------------------------------------------------------------------

| PARM                   | parm0, parm1       | two curve parameter records  |

|                        |                    | that define the curve        |

|                        |                    | interval  to keep; if parm0  |

|                        |                    | is NULL, the start point is  |

|                        |                    | not changed; if  parm1 is    |

|                        |                    | NULL, the end point is not   |

|                        |                    | changed                      |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a copy of the specified curve trimmed to the specified

curve parameter interval.  If the copy could not be created, NULL  is

returned.

 

****** Example ******

 

#include <c2cdefs.h>

#include <c2ddefs.h>

C2_CURVE trim_at_points ( curve, p0, p1 )

C2_CURVE curve;

PT2 p0, p1;

{

      PARM_S parm0, parm1;

      c2c_project ( curve, p0, &parm0, NULL ) ;

      c2c_project ( curve, p1, &parm1, NULL ) ;

      return ( c2d_trim ( curve, &parm0, &parm1 ) );

}

This program creates a copy of a curve that is trimmed to the projections  of

two given points.

 

***>> c2d_trim0  <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_trim0 ( curve, parm );

 

****** Description ******

 

This function creates a copy of a curve, and trims away the portion  of the

copy between its start point and the point specified  by a curve parameter.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | curve to be trimmed          |

------------------------------------------------------------------------------

| PARM                   | parm               | curve parameter record       |

|                        |                    | specifying the new position  |

|                        |                    | of the  start point          |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a copy of the specified curve trimmed to the specified

curve parameter interval.  If the copy could not be created, NULL  is

returned.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2cdefs.h>

#include <c2ddefs.h>

 

C2_CURVE trim_at_point ( curve )

C2_CURVE curve;

{

      PT2 p ;

      PARM_S parm;

 

      c2v_set ( 1.0, 2.0, p ) ;

      c2c_project ( curve, p, &parm, NULL ) ;

      return ( c2d_trim0 ( curve, &parm ) ) ;

}

This program trims off the portion of a curve that lies between the  start

point of the curve and the projection of the point p  onto the curve.

 

***>> c2d_trim1  <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_trim1 ( curve, parm );

 

****** Description ******

 

This function creates a copy of a curve, and trims away the portion  of the

copy between the point specified by a curve parameter and the  end point of

the copy.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | curve to be trimmed          |

------------------------------------------------------------------------------

| PARM                   | parm               | curve parameter record       |

|                        |                    | specifying the new position  |

|                        |                    | of the  end point            |

------------------------------------------------------------------------------

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2cdefs.h>

#include <c2ddefs.h>

 

C2_CURVE trim_at_point ( curve )

C2_CURVE curve;

{

      PT2 p ;

      PARM_S parm;

 

      c2v_set ( 1.0, 2.0, p ) ;

      c2c_project ( curve, p, &parm, NULL ) ;

      return ( c2d_trim1 ( curve, &parm ) ) ;

}

This program trims off the portion of a curve that lies between the

projection of the point p onto the curve and the end point  of the curve.

 

***>> c2d_trim_t <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_trim_t ( curve, t0, t1 );

 

****** Description ******

 

This function creates a copy of a curve, and trims away the portions  of the

copy outside the interval specified by a pair of curve  parameter values.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | curve to be trimmed          |

------------------------------------------------------------------------------

| REAL                   | t0, t1             | start and end curve          |

|                        |                    | parameter values of the      |

|                        |                    | curve interval  to keep      |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a copy of the specified curve trimmed to the specified

curve parameter interval.  If the copy could not be created, NULL  is

returned.

 

****** Example ******

 

#include <c2cdefs.h>

#include <c2ddefs.h>

 

C2_CURVE trim_off_ends ( curve )

C2_CURVE curve;

{

      return ( c2d_trim_t ( curve, 0.3, 0.8 );

}

This program trims off the portions of a curve that lies between the

parameter values 0.3 and 0.8.

 

***>> c2d_trim_t0 <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_trim_t0 ( curve, t );

 

****** Description ******

 

This function creates a copy of a curve, and trims away the portion  of the

copy between its start point and the point specified by a  curve parameter

value.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | curve to be trimmed          |

------------------------------------------------------------------------------

| REAL                   | t                  | curve parameter value        |

|                        |                    | specifying the new position  |

|                        |                    | of the  start point          |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a copy of the specified curve trimmed to the specified

curve parameter interval.  If the copy could not be created, NULL  is

returned.

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2cdefs.h>

#include <c2ddefs.h>

 

C2_CURVE trim_off_start ( curve )

C2_CURVE curve;

{

      return ( c2d_trim_t0 ( curve, 0.3 ) ) ;

}

This program trims off the portion of a curve that lies between the  start

point of the curve and the parameter value 0.3.

 

***>> c2d_trim_t1  <<***

 

****** Summary ******

 

#include <c2ddefs.h>

 

C2_CURVE c2d_trim_t1 ( curve, t );

 

****** Description ******

 

This function create a copy of a curve, and trims away the portion  of the

copy between the point specified by a curve parameter value  and the end

point of the copy.

 

****** Input ******

 

------------------------------------------------------------------------------

| C2_CURVE               | curve              | curve to be trimmed          |

------------------------------------------------------------------------------

| REAL                   | t                  | curve parameter record       |

|                        |                    | specifying the new position  |

|                        |                    | of the  end point            |

------------------------------------------------------------------------------

 

****** Example ******

 

#include <c2vdefs.h>

#include <c2cdefs.h>

#include <c2ddefs.h>

C2_CURVE trim_off_end ( curve )

C2_CURVE curve;

{

      return ( c2d_trim_t1 ( curve, 0.8 ) ) ;

}

This program trims off the portion of a curve that lies between the

parameter value 0.8 and the end point of the curve.

 

***>> c2t_create  <<***

 

****** Summary  ******

 

#include <c2tdefs.h>

 

C2_TRANSFORM * c2t_create ();

 

****** Description  ******

 

This function creates a 2D identity transform.

 

****** Return Value  ******

 

The return value is the created transform.  If the transform could  not be

created, NULL is returned.

 

****** Example  ******

 

#include <c2tdefs.h>

#include <c2vdefs.h>

void main (void)

{

      PT2 c, x, y, a, b;

      C2_TRANSFORM t1, t2, *t = c2t_create();

      c2v_set ( 1., 1., c );

      c2v_set ( 3./5., 4./5., x );

      c2v_normal ( x, y );

      c2t_lcs ( c, x, y, t1 );

      c2v_set ( 5., 6., a );

      c2t_eval_pt ( a, t1, b );

      c2v_set ( 1., 1., c );

      c2v_set ( 4./5., 3./5., x );

      c2v_normal ( x, y );

      c2t_lcs ( c, x, y, t2 );

      c2t_mult ( t1, t2, *t );

      c2t_eval_vec ( a, *t, b );

      c2t_inverse ( t1, *t );

      c2t_eval_pt ( a, *t, b );

      c2t_free ( *t );

}

This program creates transforms for 2D coordinate systems, and  converts

points and vectors between coordinate systems using the  transforms.

 

***>> c2t_eval_pt  <<***

 

****** Summary  ******

 

#include <c2tdefs.h>

 

REAL *c2t_eval_pt ( a, t, b );

 

****** Description  ******

 

This function transforms a 2D point by a 2D transform.

 

****** Input  ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | a 2D point                   |

------------------------------------------------------------------------------

| C2_TRANSFORM           | t                  | a 2D transform               |

------------------------------------------------------------------------------

 

****** Output  ******

 

------------------------------------------------------------------------------

| PT2                    | b                  | the transformed 2D point     |

------------------------------------------------------------------------------

 

****** Return Value  ******

 

The return value is the output point.

 

****** Example  ******

 

See c2t_create.

 

***>> c2t_eval_vec  <<***

 

****** Summary  ******

 

#include <c2tdefs.h>

 

REAL *c2t_eval_vec ( a, t, b );

 

****** Description  ******

 

This function transforms a 2D vector by a 2D transform.

 

****** Input  ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | a 2D vector in the local     |

|                        |                    | coordinate system            |

------------------------------------------------------------------------------

| C2_TRANSFORM           | t                  | a 2D transform               |

------------------------------------------------------------------------------

 

****** Output  ******

 

------------------------------------------------------------------------------

| PT2                    | b                  | the point in the global      |

|                        |                    | coordinate system            |

|                        |                    | corresponding to  the input  |

|                        |                    | point                        |

------------------------------------------------------------------------------

 

****** Return Value  ******

 

The return value is the output point.

 

****** Example  ******

 

See c2t_create.

 

***>> c2t_free  <<***

 

****** Summary  ******

 

#include <c2tdefs.h>

 

void c2t_free ( t );

 

****** Description  ******

 

This function frees a 2D transform.

 

****** Input  ******

 

------------------------------------------------------------------------------

| C2_TRANSFORM           | t                  | a 2D transform               |

------------------------------------------------------------------------------

 

****** Example  ******

 

See c2t_create.

 

***>> c2t_inverse  <<***

 

****** Summary  ******

 

#include <c2tdefs.h>

 

REAL *c2t_inverse ( t, ti );

 

****** Description  ******

 

This function inverts a 2D transform.

 

****** Input  ******

 

------------------------------------------------------------------------------

| C2_TRANSFORM           | t                  | a 2D transform               |

------------------------------------------------------------------------------

 

****** Output  ******

 

------------------------------------------------------------------------------

| C2_TRANSFORM           | ti                 | the inverted transform       |

------------------------------------------------------------------------------

 

****** Return Value  ******

 

The return value is the output transform if the input transform was

successfully inverted. It is NULL otherwise.

 

****** Example  ******

 

See c2t_create.

 

***>> c2t_lcs  <<***

 

****** Summary  ******

 

#include <c2tdefs.h>

 

REAL *c2t_lcs ( c, x, y, t );

 

****** Description  ******

 

This function computes a 2D transform for a local coordinate system  defined

by an origin, x-axis and y-axis.  This transform converts  points from the

local coordinate system to the global coordinate  system.

 

****** Input  ******

 

------------------------------------------------------------------------------

| PT2                    | c, x, y            | the origin, x-axis and       |

|                        |                    | y-axis of the local          |

|                        |                    | coordinate  system.          |

------------------------------------------------------------------------------

 

****** Output  ******

 

------------------------------------------------------------------------------

| C2_TRANSFORM           | t                  | the computed transform       |

------------------------------------------------------------------------------

 

****** Return Value  ******

 

The return value is the transform if it was successfully computed.   It is

NULL otherwise.

 

****** Example  ******

 

See c2t_create.

 

***>> c2t_mirror_line  <<***

 

****** Summary  ******

 

#include <c2tdefs.h>

 

REAL *c2t_mirror_line ( line, t );

 

****** Description  ******

 

This function constructs a transform that mirrors 2D objects about a  line.

 

****** Input  ******

 

------------------------------------------------------------------------------

| PT2                    | line[2]            | a line defined by two points  |

|                        |                    |                              |

------------------------------------------------------------------------------

 

****** Output  ******

 

------------------------------------------------------------------------------

| C2_TRANSFORM           | t                  | a 2D transform               |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the transform if it was constructed  successfully.

Otherwise it is NULL.

 

****** Example  ******

 

#include <c2tdefs.h>

 

void main()

{

      C2_TRANSFORM *c2t;

      PT2 l[2];

      c2t = c2t_create();

      printf ( "Enter mirror line pts:" );

      scanf ( "%lf%lf%lf%lf", l[0], l[0]+1, l[1], l[1]+1 );

      c2t_mirror_line ( l, *c2t );

      c2t_free ( *c2t );

}

This program creates a 2D transform for mirroring about a line.

 

***>> c2t_mult  <<***

 

****** Summary  ******

 

#include <c2tdefs.h>

 

REAL *c2t_mult ( t1, t2, t );

 

****** Description  ******

 

This function multiplies two transform to make a third transform.

 

****** Input  ******

 

------------------------------------------------------------------------------

| C2_TRANSFORM           | t1, t2             | two 2D transforms            |

------------------------------------------------------------------------------

 

****** Output  ******

 

------------------------------------------------------------------------------

| C2_TRANSFORM           | t                  | the product of the two       |

|                        |                    | transforms                   |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the output transform.

 

****** Example  ******

 

See c2t_create.

 

***>> c2t_orthogonal  <<***

 

****** Summary  ******

 

#include <c2tdefs.h>

 

BOOLEAN c2t_orthogonal ( t );

 

****** Description  ******

 

This function determines if the transformation performed by a  transform is

orthogonal.  If the transform is not orthogonal,  circles become ellipses.

 

****** Input  ******

 

------------------------------------------------------------------------------

| C2_TRANSFORM           | t                  | a 2D transform               |

------------------------------------------------------------------------------

 

****** Return Value  ******

 

The return value is TRUE if the transformation is orthogonal.  It is  FALSE

otherwise.

 

****** Example  ******

 

#include <c2tdefs.h>

 

C2_TRANSFORM *create_orth_lcs ( c, x, y )

 

PT2 c, x, y;

{

      C2_TRANSFORM *c2t;

 

      c2t = c2t_create();

      c2t_lcs ( c, x, y, *c2t );

      if ( c2t_orthogonal ( *c2t ) )

            return ( c2t );

      else

      {

            c2t_free ( *c2t );

            return ( NULL );

      }

}

This function creates a transform for a local coordinate system if  the

transformation is orthogonal.

 

***>> c2t_rotate  <<***

 

****** Summary  ******

 

#include <c2tdefs.h>

 

REAL *c2t_rotate ( origin, angle, t );

 

****** Description  ******

 

This function constructs a transform that rotates 2D objects about a  point.

 

****** Input  ******

 

------------------------------------------------------------------------------

| PT2                    | origin             | center of rotation           |

------------------------------------------------------------------------------

| REAL                   | angle              | rotation angle; must be      |

|                        |                    | specified in radians         |

------------------------------------------------------------------------------

 

****** Output  ******

 

------------------------------------------------------------------------------

| C2_TRANSFORM           | t                  | a 2D transform               |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the transform if it was constructed  successfully.

Otherwise it is NULL.

 

****** Example  ******

 

#include <c2tdefs.h>

 

void main()

{

      C2_TRANSFORM *c2t;

      PT2 c;

      REAL theta;

      c2t = c2t_create();

      printf ( "Enter rotation center and angle" );

      scanf ( "%lf%lf%lf", c, c+1, &theta );

      c2t_rotate ( c, theta, *c2t );

      c2t_free ( *c2t );

}

This program creates a transform for rotation.

 

***>> c2t_rotate_cs  <<***

 

****** Summary  ******

 

#include <c2tdefs.h>

 

REAL *c2t_rotate_cs ( origin, c, s, t );

 

****** Description  ******

 

This function constructs a transform for rotating objects about a  point.

The rotation angle is specified with its sine and cosine.

 

****** Input  ******

 

------------------------------------------------------------------------------

| PT2                    | origin             | the center of rotation       |

------------------------------------------------------------------------------

| REAL                   | c, s               | the cosine and sine of the   |

|                        |                    | rotation angle               |

------------------------------------------------------------------------------

 

****** Output  ******

 

------------------------------------------------------------------------------

| C2_TRANSFORM           | t                  | a 2D transform               |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the transform if it was constructed  successfully.

Otherwise it is NULL.

 

****** Example  ******

 

#include <c2tdefs.h>

 

void main()

{

      C2_TRANSFORM *c2t;

      PT2 p;

      REAL theta, c, s;

 

      c2t = c2t_create();

      printf ( "Enter rotation center and angle" );

      scanf ( "%lf%lf%lf", p, p+1, &theta );

      c = cos ( theta );

      s = sin ( theta );

      c2t_rotate_cs ( p, c, s, *c2t );

      c2t_free ( *c2t );

}

This program creates a transform for rotation.  The rotation angle  is

specified with its sine and cosine.

 

***>> c2t_scale  <<***

 

****** Summary ******

 

#include <c2tdefs.h>

 

REAL *c2t_scale ( origin, f0, f1, t );

 

****** Description ******

 

This function constructs a transform for scaling 2D objects about a  point.

The horizontal scale may differ from the vertical scale.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | origin             | the center of scaling        |

------------------------------------------------------------------------------

| REAL                   | f0, f1             | the horizontal and vertical  |

|                        |                    | scale factors                |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| C2_TRANSFORM           | t                  | a 2D transform               |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the transform if it was constructed  successfully.

Otherwise it is NULL.

 

****** Example ******

 

#include <c2tdefs.h>

 

void main()

{

      C2_TRANSFORM *c2t;

      PT2 c;

      REAL f1, f2;

      c2t = c2t_create();

      printf ( "Enter scaling center and factors" );

      scanf ( "%lf%lf%lf%lf", c, c+1, &f1, &f2 );

      c2t_scale ( c, f1, f2, *c2t );

      c2t_free ( *c2t );

}

This program creates a transform for scaling 2D objects.

 

***>> c2t_translate <<***

 

****** Summary ******

 

#include <c2tdefs.h>

 

REAL *c2t_translate ( shift, t );

 

****** Description ******

 

This function constructs a transform for translating 2D objects.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | shift              | translation vector           |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| C2_TRANSFORM           | t                  | a 2D transform               |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the transform if it was constructed  successfully.

Otherwise it is NULL.

 

****** Example ******

 

#include <c2tdefs.h>

 

void main()

{

      C2_TRANSFORM *c2t;

      PT2 v;

 

      c2t = c2t_create();

      printf ( "Enter translation vector: " );

      scanf ( "%lf%lf", v, v+1 );

      c2t_translate ( v, *c2t );

      c2t_free ( *c2t );

}

This program creates a transform for translating 2D objects.

 

***>> c2v_add  <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL * c2v_add ( a, b, c );

 

****** Description ******

 

This function adds two vectors. This operation is defined by the following

expression:

 

      c = a + b.

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | first vector                 |

------------------------------------------------------------------------------

| PT2                    | b                  | second vector                |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | c                  | sum of two vectors           |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a pointer to the output vector.

 

****** Example ******

 

 

#include <c2vdefs.h>

 

void main()

{

      PT2 p1, p2, p3;

 

      c2v_set ( 1., 2., p1 );

      c2v_set ( 3., 4., p2 );

      c2v_add ( p1, p2, p3 ) ;

}

This program adds two vectors.

 

***>> c2v_addt  <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL * c2v_addt ( a, b, t, c );

 

****** Description ******

 

This function computes the sum of a vector and a multiple  of another vector.

This sum is defined by the following  expression:

 

      c = a + t * b.

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | first vector                 |

------------------------------------------------------------------------------

| PT2                    | b                  | second vector                |

------------------------------------------------------------------------------

| REAL                   | t                  | multiplier of the second     |

|                        |                    | vector                       |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | c                  | the sum of the first vector  |

|                        |                    | and the multiple of  the     |

|                        |                    | second vector                |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a pointer to the output vector.

 

****** Example ******

 

 

#include <c2vdefs.h>

 

void main()

{

      PT2 p0, p1, v;

      REAL t = 1. / 3. ;

      c2v_set ( 1., 2., p0 );

      c2v_set ( 3., 4., v );

      c2v_addt ( p0, v, t, p1 ) ;

}

This program computes the sum of the point (1,2) and one third of  the vector

(3,4).

 

***>> c2v_addu  <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL * c2v_addu ( a, b, u, c );

 

****** Description ******

 

This function computes the convex combination of two vectors. This  sum is

defined by the following expression:

 

      c = ( 1 - u ) * a + u * b.

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | first vector                 |

------------------------------------------------------------------------------

| PT2                    | b                  | second vector                |

------------------------------------------------------------------------------

| REAL                   | u                  | weighting fraction           |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | c                  | convex sum of two vectors    |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a pointer to the output vector.

 

****** Example ******

 

 

#include <c2vdefs.h>

 

void main()

{

      PT2 p1, p2, p3;

      REAL u = 1. / 3. ;

      c2v_set ( 1., 2., p1 );

      c2v_set ( 3., 4., p2 );

      c2v_addu ( p1, p2, u, p3 ) ;

}

This program creates a vector which is the sum of 2/3 of the first  vector

and 1/3 of the second vector.

 

***>> c2v_addw  <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL * c2v_addw ( a, p, b, q, c );

 

****** Description  ******

 

This function computes the weighted sum of two vectors.  This sum is defined

by the following expression:

 

      c = p * a + q * b.

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | first vector                 |

------------------------------------------------------------------------------

| REAL                   | p                  | coefficient of the first     |

|                        |                    | vector                       |

------------------------------------------------------------------------------

| PT2                    | b                  | second vector                |

------------------------------------------------------------------------------

| REAL                   | q                  | coefficient of the second    |

|                        |                    | vector                       |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | c                  | weighted sum of two vectors  |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a pointer to the output vector.

 

****** Example ******

 

 

#include <c2vdefs.h>

void compute_new_position ( old_pos, wind_dir,

      our_dir, our_vel, del_time, wind_vel, new_pos )

PT2 old_pos, wind_dir, our_dir, new_pos ;

REAL wind_vel, our_vel, del_time ;

{

      PT2 offset;

      REAL wind_dist, our_dist ;

      wind_dist = del_time * wind_vel ;

      our_dist = del_time * our_vel ;

      c2v_addw ( wind_dir, wind_dist, our_dir,

            our_dist, offset);

      c2v_add ( old_pos, offset, new_pos );

}

This subroutine computes the position of a plane flying across an  airstream.

 

***>> c2v_area  <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL c2v_area ( a, b, c );

 

****** Description ******

 

This function computes the area of a triangle defined by three  points.  If

the order of the points is counter-clockwise, the result  is positive; if it

is clockwise, the result is negative; if the  points are colinear, the result

is zero.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a, b, c            | three points                 |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the area of the triangle defined by the given  points. If

the order of the points is counter-clockwise, the result  is positive; if it

is clockwise, the result is negative; if the  points are colinear, the result

is zero.

 

****** Example ******

 

#include <c2vdefs.h>

 

REAL polygon_area ( p, n )

PT2 *p ;

INT n ;

{

      INT i ;

      REAL area = 0.0 ;

 

      for ( i=2 ; i<n ; i++ )

            area += c2v_area ( p[0], p[i-1], p[i] ) ;

      RETURN ( area ) ;

}

This routine computes an area of a closed polygon p[0],...,p[n-1], p[0]  as

the sum of areas of all triangles with the vertex at p[0].  To generate a

polygon, use c2c_polygon.

 

***>> c2v_copy <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL * c2v_copy(a,b);

 

****** Description ******

 

This function copies one point to another.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | the point(vector) to be      |

|                        |                    | copied                       |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | b                  | the copy                     |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a pointer to the output vector.

 

****** Example ******

 

 

#include <c2vdefs.h>

 

void main()

{

      PT2 point, copy ;

      c2v_set ( 10.0, 5.0, point ) ;

      c2v_copy ( point, copy ) ;

}

This program copies one point to another.

 

***>> c2v_cross  <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL c2v_cross ( a, b);

 

****** Description ******

 

This function computes the cross product of two vectors. This quantity  is

defined by the following expression:

 

      cross = a[0] * b[1] - a[1] * b[0].

Since two-dimensional vectors can be viewed as three-dimensional vectors

with the third coordinate being zero, their three-dimensional cross-product

is a vector normal to the x-y plane. The quantity which this routine

computes is the third coordinate of this three-dimensional cross product.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | first vector                 |

------------------------------------------------------------------------------

| PT2                    | b                  | second vector                |

------------------------------------------------------------------------------

 

****** Return value ******

 

The return value is the cross product of the two vectors.

 

****** Example ******

 

 

#include <c2vdefs.h>

 

void print_cross_product ( vec1, vec2 )

 

PT2 vec1, vec2;

{

      REAL cross_prod ;

      cross_prod = c2v_cross ( vec1, vec2 ) ;

      printf ( "The cross product of vec1 and vec2 is " ) ;

      printf ( "%lf.\n", cross_prod );

}

This subroutine prints out the cross product of two vectors.

 

***>> c2v_dist  <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL c2v_dist ( a, b );

 

****** Description ******

 

This function computes the distance between two points. This quantity  is

defined by the following expression:

 

      dist = sqrt ( ( a[0]-b[0] )*( a[0]-b[0] ) +

            ( a[1]-b[1] )*( a[1]-b[1] ) ).

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | first point                  |

------------------------------------------------------------------------------

| PT2                    | b                  | second point                 |

------------------------------------------------------------------------------

 

****** Return value ******

 

The return value is the distance between the two points.

 

****** Example ******

 

 

#include <c2vdefs.h>

 

void

print_distance ( pt1, pt2 )

 

PT2 pt1, pt2;

{

      REAL dist ;

      dist = c2v_dist ( pt1, pt2 ) ;

      printf ( "The distance between pt1 and pt2 is " ) ;

      printf ( "%lf.\n", dist );

}

This subroutine prints out the distance between two points.

 

***>> c2v_dist_squared  <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL c2v_dist_squared ( a, b );

 

Description

 

This function computes the square of the distance between two points.  This

quantity is defined by the following expression:

 

      dist = ( a[0]-b[0] )*( a[0]-b[0] ) +

            ( a[1]-b[1] )*( a[1]-b[1] ).

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | first point                  |

------------------------------------------------------------------------------

| PT2                    | b                  | second point                 |

------------------------------------------------------------------------------

 

****** Return value ******

 

The return value is the distance between the two points squared.

 

****** Example ******

 

 

#include <c2vdefs.h>

 

void

print_distance_squared ( pt1, pt2 )

 

PT2 pt1, pt2;

{

      REAL dist_sqr ;

      dist_sqr = c2v_dist_squared ( pt1, pt2 ) ;

      printf ( "The distance squared between pt1 " ) ;

      printf ( "and pt2 is %lf.\n", dist_sqr );

}

This subroutine prints out the distance between two points.

 

***>> c2v_distl1 <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL c2v_distl1 ( a, b );

 

****** Description ******

 

This function computes the "L1" or "Manhattan" distance between two  points.

This quantity is defined by the following expression:

 

      dist_l1 = fabs ( a[0]-b[0] ) + fabs ( a[1]-b[1] ).

This value is a good estimate of the distance between two  points, and is

computed much more efficiently than the exact  Euclidean distance.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | first point                  |

------------------------------------------------------------------------------

| PT2                    | b                  | second point                 |

------------------------------------------------------------------------------

 

****** Return value ******

 

The return value is the "L1" distance between the two points.

 

****** Example ******

 

 

#include <c2vdefs.h>

 

void print_manhattan_distance ( pt1, pt2 )

 

PT2 pt1, pt2;

{

      REAL dist ;

      dist = c2v_distl1 ( pt1, pt2 ) ;

      printf ( "The Manhattan distance between " ) ;

      printf ( "pt1 and pt2 is %lf.\n", dist );

}

This subroutine prints out the distance between two points.

 

***>> c2v_dot  <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL c2v_dot ( a, b );

 

****** Description ******

 

This function computes the dot product of two vectors. This quantity  is

defined by the following expression:

 

      dot = a[0] * b[0] + a[1] * b[1].

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | first vector                 |

------------------------------------------------------------------------------

| PT2                    | b                  | second vector                |

------------------------------------------------------------------------------

 

****** Return value ******

 

The return value is the dot product of the specified vectors.

 

****** Example ******

 

 

#include <c2vdefs.h>

 

void print_dot_product ( vec1, vec2 )

PT2 vec1, vec2 ;

{

      REAL dot_prod ;

      dot_prod = c2v_dot ( vec1, vec2 ) ;

      printf ( "The dot product of vec1 and vec2 is %lf.\n",

            dot_prod );

}

This subroutines prints out the dot product of two vectors.

 

***>> c2v_ident_pts <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

BOOLEAN c2v_ident_pts(a, b);

 

****** Description ******

 

This function determines if two points coincide within the  absolute

tolerance.  This tolerance may be reset by changing  either the world size or

the relative tolerance.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | first point                  |

------------------------------------------------------------------------------

| PT2                    | b                  | second point                 |

------------------------------------------------------------------------------

 

****** Return value ******

 

This function returns TRUE if the points coincide within the defined

absolute tolerance, and it returns FALSE if the points are separated  by a

distance greater than that value. This tolerance may be reset  by changing

either the world size or the relative tolerance.

 

****** Example ******

 

 

#include <c2vdefs.h>

 

void

coincidence_check ( pt0, pt1 )

PT2 pt0, pt1 ;

{

      if ( !c2v_ident_pts ( pt0, pt1 ) )

            printf ( "points are distinct\n" );

      else

            printf ( "points coincide\n" );

}

This subroutine checks if two points are coincident and prints out  the

appropriate message.

 

***>> c2v_is_small <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

BOOLEAN c2v_is_small ( a );

 

****** Description ******

 

This function determines if absolute values of both coordinates of  the input

vector are less than the absolute tolerance. This  tolerance may be reset by

changing either the world size or the  relative tolerance.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | a vector                     |

------------------------------------------------------------------------------

 

****** Return value ******

 

This function returns TRUE if absolute values of both coordinates  of the

vector are less than or equal to the absolute tolerance, and  it returns

FALSE if at least one of the absolute values of the coordinates  of the

vector a is greater than that value.

 

****** Example ******

 

 

#include <c2vdefs.h>

 

void

check_zerolength ( v )

PT2 v;

{

      if ( c2v_is_small ( v ) )

            printf ( "vector has zero length" );

}

This subroutine checks to see if a vector has zero length.

 

***>> c2v_mid_pt  <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL * c2v_mid_pt ( a, b, c );

 

****** Description ******

 

This function computes the point halfway between two points. This  operation

is defined by the following expression:

 

      c = ( a + b ) / 2.

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | first point                  |

------------------------------------------------------------------------------

| PT2                    | b                  | second point                 |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | c                  | midpoint between the two     |

|                        |                    | points                       |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a pointer to the output vector.

 

****** Example ******

 

 

#include <c2vdefs.h>

 

void main()

{

      PT2 pt1, pt2, mid_pt ;

      c2v_set ( 1.0, 2.0, pt1 ) ;

      c2v_set ( 3.0, 4.0, pt2 ) ;

      c2v_mid_pt ( pt1, pt2, mid_pt ) ;

}

This program computes the midpoint between (1,2) and (3,4).  The  result is

(2,3).

 

***>> c2v_mirror_pt  <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL * c2v_mirror_pt ( a, origin, normal, b );

 

****** Description ******

 

This function mirrors a point across a line passing through an  origin and

perpendicular to a given vector.  The normal vector  specifies the mirroring

direction.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | the point to mirror          |

------------------------------------------------------------------------------

| PT2                    | origin             | point through which          |

|                        |                    | mirroring line passes        |

------------------------------------------------------------------------------

| PT2                    | normal             | mirroring direction; this    |

|                        |                    | vector is normal to the      |

|                        |                    | mirroring  line              |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | b                  | the mirror image of a        |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a pointer to the output vector.

 

****** Example ******

 

#include <c2vdefs.h>

 

void mirror_pt_around_xy ( a, b )

PT2 a, b ;

{

      PT2 origin, normal ;

      c2v_set_zero ( origin ) ;

      c2v_set ( 1.0/SQRT_2, -1.0/SQRT_2, normal ) ;

      c2v_mirror_pt ( a, origin, normal, b ) ;

}

This routine mirrors an input point a across the line  x = y.

 

***>> c2v_mirror_vec  <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL * c2v_mirror_vec ( a, dir, b );

 

****** Description ******

 

This function mirrors a vector in the given direction. The normal  vector

specifies the mirroring direction.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | the vector to mirror         |

------------------------------------------------------------------------------

| PT2                    | dir                | mirroring direction; this    |

|                        |                    | vector is normal to the      |

|                        |                    | mirroring  line              |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | b                  | the mirror image of a        |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a pointer to the output vector.

 

****** Example ******

 

#include <c2vdefs.h>

 

void mirror_vec_around_xy ( a, b )

PT2 a, b ;

{

      PT2 normal ;

      c2v_set ( 1.0/SQRT_2, -1.0/SQRT_2, normal ) ;

      c2v_mirror_vec ( a, normal, b ) ;

}

This routine mirrors an input vector a across the line  x = y.

 

***>> c2v_negate  <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL * c2v_negate ( a, b );

 

****** Description ******

 

This function negates or reverses a vector. This  operation is defined by the

expression:

 

      b = -a.

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | vector                       |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | b                  | vector with direction        |

|                        |                    | reversed                     |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a pointer to the output vector.

 

****** Example ******

 

 

#include <c2vdefs.h>

 

void main()

{

      PT2 vec, vec1 ;

      REAL x = 15.0, y = 15.0 ;

      c2v_set ( x, y, vec ) ;

      c2v_negate ( vec, vec1 ) ;

}

This program reverses a vector. The result is (-15,-15).

 

***>> c2v_norm  <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL c2v_norm ( a );

 

****** Description  ******

 

This function computes the length of a vector. This quantity is defined  by

the following expression:

 

      norm = sqrt ( a[0]*a[0] + a[1]*a[1] ).

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | a vector                     |

------------------------------------------------------------------------------

 

****** Return value ******

 

The return value is the length or "norm" of the vector.

 

****** Example ******

 

 

#include <c2vdefs.h>

 

void main()

{

      PT2 vec1 ;

      REAL length ;

      c2v_set ( 1., 2., vec1 );

      length = c2v_norm ( vec1 ) ;

      printf ( "vector length: %lf\n", length );

}

This program computes the length of the vector (1,2), which is the  square

root of 5.

 

***>> c2v_norm_squared  <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL c2v_norm_squared ( a );

 

****** Description ******

 

This function computes the square of the length of a vector. This  quantity

is defined by the following expression:

 

      norm_sqr = a[0]*a[0] + a[1]*a[1].

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | vector                       |

------------------------------------------------------------------------------

 

****** Return value ******

 

The return value is the length or norm of the vector squared.

 

****** Example ******

 

 

#include <c2vdefs.h>

 

void main()

{

      PT2 vec1 ;

      REAL length_sqr ;

      c2v_set ( 1., 2., vec1 );

      length_sqr = c2v_norm_squared ( vec1 ) ;

      printf ( "vector length squared: %lf\n", length_sqr );

}

This program computes the squared length of the vector (1,2).

 

***>> c2v_normal  <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL * c2v_normal ( a, b );

 

****** Description ******

 

This function constructs the PI / 2 radian counter-clockwise  rotation of a

vector.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | the vector to rotate         |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | b                  | a vector normal to a,        |

|                        |                    | rotated in the counter-      |

|                        |                    | clockwise direction by an    |

|                        |                    | angle of PI / 2.             |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a pointer to the output vector.

 

****** Example ******

 

#include <c2vdefs.h>

 

void normal_vector ( )

{

      PT2 a, b ;

      printf ( "enter the vector\n" ) ;

      scanf ( "%lf%lf", a, a+1 ) ;

      c2v_normal ( a, b ) ;

      printf ( "normal to the input vector is %lf\t%lf\n", b[0], b[1] ) ;

}

This routine computes a normal to the user-supplied vector.

 

***>> c2v_normalize  <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

BOOLEAN c2v_normalize ( a, b );

 

****** Description ******

 

This function normalizes a vector to produce a unit  vector. This operation

is defined by the following  expression:

 

      b = a / c2v_norm(a).

The vector must have non-zero length to be normalized.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | vector                       |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | b                  | normalized vector; its       |

|                        |                    | coordinates are valid only   |

|                        |                    | if the returned value is     |

|                        |                    | TRUE                         |

------------------------------------------------------------------------------

 

****** Return value ******

 

The return value is TRUE if the length of the input  vector is not zero and

the normalization was successfully  performed. Otherwise the return value is

FALSE; in this  case the coordinates of the output vector are invalid.

 

****** Example ******

 

#include <c2vdefs.h>

 

void main()

{

      PT2 v, v1;

      c2v_set ( 3., 4., v );

      c2v_normalize ( v, v1 );

}

This program normalizes the vector (3,4).  The resulting vector is  (0.6,

0.8).

 

***>> c2v_normalize_l1  <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

BOOLEAN c2v_normalize_l1 ( a, b );

 

****** Description ******

 

This function scales a vector to make it approximately of  unit length. The

scale factor is the reciprocal of the  "L1" length of the vector (see

c2v_norml1).

 

This operation is defined by the following expression:

 

      b = a / c2v_norml1(a).

If the "L1" length of the vector is zero, this function  returns FALSE, and

the output vector b is invalid.

 

This normalization is performed much more quickly than  the precise

normalization, and consequently should be  used when a vector with

approximately unit length will  suffice.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | a vector                     |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | b                  | a vector with the same       |

|                        |                    | direction as a, but  with    |

|                        |                    | approximately unit length    |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is TRUE if the "L1" length of the input  vector is not zero

and the normalization was successfully  performed. Otherwise the return value

is FALSE; in this  case the coordinates of the output vector are invalid.

 

****** Example ******

 

#include <c2vdefs.h>

 

void main()

{

      PT2 v, v1;

      c2v_set ( 3., 4., v );

      c2v_normalize_l1 ( v, v1 );

}

 

This program normalizes the vector (3,4) using its "Manhattan  length".  The

resulting vector is (3/7, 4/7).

 

***>> c2v_norml1  <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL c2v_norml1 ( a );

 

****** Description ******

 

This function computes the "Manhattan" norm of a vector. This  quantity is

defined by the following expression:

 

      norm_l1 = fabs ( a[0] ) + fabs ( a[1] ).

This norm is computed much more quickly than the true  length, and

consequently should be used as an estimate  when the exact length of a vector

is not needed.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | vector                       |

------------------------------------------------------------------------------

 

****** Return value ******

 

The return value is the "L1" norm of the vector.

 

****** Example ******

 

 

#include <c2vdefs.h>

 

void main()

{

      PT2 v;

      REAL length;

      c2v_set ( 1., 2., v );

      length = c2v_norml1 ( v );

      printf ( "L1 length: %lf\n", length );

}

This program prints out the "L1" length of the vector (1,2).

 

***>> c2v_offset  <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL * c2v_offset ( a, tan, w, b );

 

****** Description ******

 

This function computes the sum of a vector and a weighted perpendicular  of

another vector. This operation is expressed as:

 

      b = a + w * normal

where normal is the rotation of tan by the angle PI/2  in the clockwise

direction.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | a point                      |

------------------------------------------------------------------------------

| PT2                    | tan                | a direction vector           |

------------------------------------------------------------------------------

| REAL                   | w                  | the weight applied to normal  |

|                        |                    | of the direction vector      |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | b                  | the sum of the first vector  |

|                        |                    | and the scaled normal of the  |

|                        |                    | second  vector               |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a pointer to the output vector.

 

****** Example ******

 

#include <c2vdefs.h>

void offset_point ( )

{

      PT2 a, tan, b ;

      REAL w = 1.0;

      c2v_set ( 3.0, 4.0, a );

      c2v_set ( 1.0, 1.0, tan );

c2v_offset ( a, tan, w, b );

      printf ( "offset is %lf\t%lf\n", b[0], b[1] ) ;

}

This routine computes an offset to a given point in a given normal

direction.

 

***>> c2v_project_line  <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL c2v_project_line ( a, b, c, p );

 

****** Description ******

 

This function projects a point onto a line defined by two other points.  The

result is the curve parameter value of the projection on the line.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a, b               | two points that define a     |

|                        |                    | line                         |

------------------------------------------------------------------------------

| PT2                    | c                  | the point to project         |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | p                  | the projection of c onto the  |

|                        |                    | line; not computed if  NULL  |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is the curve parameter value of the projection on  the line.

 

 

****** Example ******

 

#include <c2vdefs.h>

 

void project_pt ( )

{

      PT2 a, b, c, p ;

      REAL t ;

 

      printf ( "Enter endpoints of the line\n" ) ;

      scanf ( "%lf%lf%lf%lf", a, a+1, b, b+1 ) ;

      printf ( "Enter point to be projected\n" ) ;

      scanf ( "%lf%lf", c, c+1 ) ;

      t = c2v_project_line ( a, b, c, p ) ;

      printf ( "Projection parameter is %lf\n", t ) ;

      printf ( "Projection point is %lf %lf\n",

            PT2_X(p), PT2_Y(p) ) ;

}

This function projects a point onto a line defined by two points.

 

***>> c2v_rotate_pt <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL * c2v_rotate_pt( a, pt, angle, b );

 

****** Description ******

 

This function rotates a point by an angle about another point.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | point to be rotated          |

------------------------------------------------------------------------------

| PT2                    | pt                 | rotation origin              |

------------------------------------------------------------------------------

| REAL                   | angle              | rotation angle               |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | b                  | rotated point                |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a pointer to the output vector.

 

****** Example ******

 

 

#include <c2vdefs.h>

 

void main()

{

      PT2 p, origin ;

      REAL theta = PI / 5;

      c2v_set ( 3., 4., p );

      c2v_set ( 1., 2., origin );

      c2v_rotate_pt ( p, origin, theta, p ) ;

}

This program rotates the point (3,4) about the point (1,2) by an angle  of PI

/ 5.

 

***>> c2v_rotate_pt_cs  <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL * c2v_rotate_pt_cs ( a, pt, c, s, b );

 

****** Description ******

 

This function rotates a point about another point by an angle. The  rotation

angle is given implicitly through the cosine and sine of  the angle.

 

This function is intended for programs that rotate many points by  the same

angle. By avoiding the recomputation of the cosine and sine  of the angle,

the efficiency of such programs is increased significantly.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | point to be rotated          |

------------------------------------------------------------------------------

| PT2                    | pt                 | rotation origin              |

------------------------------------------------------------------------------

| REAL                   | c                  | cosine of the rotation angle  |

------------------------------------------------------------------------------

| REAL                   | s                  | sine of the rotation angle   |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | b                  | rotated point                |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a pointer to the output vector.

 

****** Example ******

 

 

#include <c2vdefs.h>

 

void

rotate_figure_about ( figure, center, n )

 

PT2 figure[], center;

INT n;

{

      INT i ;

      REAL angle, c, s, x, y ;

 

      printf ( "Enter angle to rotate figure (in degrees):");

      scanf ( "%lf", &angle ) ;

 

      c = cos ( angle * PI_OVER_180 ) ;

      s = sin ( angle * PI_OVER_180 ) ;

 

      printf ( "Enter coordinates of rotation origin: " );

      scanf ( "%lf %lf", &x, &y ) ;

 

      for ( i = 0 ; i <= n ; i++ )

      {

            c2v_rotate_pt_cs ( figure[i], center, c, s, figure[i] );

      }

}

This subroutine rotates a polygon about a point.

 

***>> c2v_rotate_vec <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL * c2v_rotate_vec( a, angle, b );

 

****** Description ******

 

This function rotates a point by an angle about the origin.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | point to be rotated          |

------------------------------------------------------------------------------

| REAL                   | angle              | rotation angle               |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | b                  | rotated point                |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a pointer to the output vector.

 

****** Example ******

 

 

#include <c2vdefs.h>

 

void main()

{

      PT2 sweep ;

      REAL theta = PI / 8 ;

      c2v_set ( 1.0, 0.0, sweep ) ;

      c2v_rotate_vec ( sweep, theta, sweep ) ;

}

This program rotates a vector by an angle of PI / 8.

 

***>> c2v_rotate_vec_cs <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL * c2v_rotate_vec_cs( a, c, s, b );

 

****** Description ******

 

This function rotates a point about the origin by a given angle. The  angle

is specified by providing its cosine and sine rather than the  angle itself.

 

This function is intended for programs that rotate many vectors by  the same

angle. By avoiding the recomputation of the cosine and sine  of the angle,

the efficiency of such programs is increased significantly.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | point to be rotated          |

------------------------------------------------------------------------------

| REAL                   | c                  | cosine of the rotation angle  |

------------------------------------------------------------------------------

| REAL                   | s                  | sine of the rotation angle   |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | b                  | rotated point                |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a pointer to the output vector.

 

****** Example ******

 

 

#include <c2vdefs.h>

 

void

rotate_vectors ( vectors, n )

 

PT2 vectors[];

INT n;

{

      INT i ;

      REAL angle, c, s ;

 

      printf ( "Enter angle to rotate vectors (in degrees): ");

      scanf ( "%lf", &angle ) ;

      c = cos ( angle * PI_OVER_180 ) ;

      s = sin ( angle * PI_OVER_180 ) ;

 

      for ( i = 0 ; i <= n ; i++ )

      {

            c2v_rotate_vec_cs ( vectors[i], c, s, vectors[i] ) ;

      }

}

This subroutine rotates a set of vectors.

 

***>> c2v_scale  <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL * c2v_scale ( a, t, b );

 

****** Description ******

 

This function multiplies a vector by a scalar. This operation is defined  by

the following expression:

 

      b = t * a.

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | vector                       |

------------------------------------------------------------------------------

| REAL                   | t                  | scalar                       |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | b                  | product of scalar and vector  |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a pointer to the output vector.

 

****** Example ******

 

 

#include <c2vdefs.h>

 

void main()

{

      PT2 vec;

      REAL scale = 1, x = 10.0, y = 10.0 ;

      c2v_set ( x, y, vec ) ;

      printf ( "Enter scale factor: " ) ;

      scanf ( "%lf", &scale ) ;

      c2v_scale ( vec, scale, vec ) ;

}

This program scales a vector by a scale factor.

 

***>> c2v_set  <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL * c2v_set ( x, y, a );

 

****** Description ******

 

This function sets the coordinate values of a vector.

 

****** Input ******

 

------------------------------------------------------------------------------

| REAL                   | x                  | the x coordinate             |

------------------------------------------------------------------------------

| REAL                   | y                  | the y coordinate             |

------------------------------------------------------------------------------

| PT2                    | a                  | the vector                   |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a pointer to the output vector.

 

****** Example ******

 

 

#include <c2vdefs.h>

 

void main()

{

      PT2 p;

      c2v_set ( 1., 2., p) ;

}

This program sets a point to the coordinates (1,2).

 

***>> c2v_set_zero <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL * c2v_set_zero(a);

 

****** Description ******

 

This function sets both coordinates of a vector to zero.

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | vector whose coordinates are  |

|                        |                    | set to zero                  |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a pointer to the output vector.

 

****** Example ******

 

 

#include <c2vdefs.h>

 

void main()

{

      PT2 v ;

      c2v_set_zero ( v ) ;

}

This program sets the vector v to (0,0).

 

***>> c2v_sub  <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL * c2v_sub ( a, b, c );

 

****** Description ******

 

This function computes the difference of two vectors. This operation  is

defined by the following expression:

 

      c = a - b.

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | first vector                 |

------------------------------------------------------------------------------

| PT2                    | b                  | second vector                |

------------------------------------------------------------------------------

 

****** Output ******

 

------------------------------------------------------------------------------

| PT2                    | c                  | difference of two vectors    |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is a pointer to the output vector.

 

****** Example ******

 

 

#include <c2vdefs.h>

 

void print_difference ( vec1, vec2 )

PT2 vec1, vec2;

{

      PT2 diff ;

      c2v_sub ( vec1, vec2, diff ) ;

      printf ( "the vector difference is: %lf %lf\n",

            PT2_X(diff), PT2_Y(diff) );

}

This subroutine prints out the difference of two vectors.

 

***>> c2v_vecs_angle  <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL c2v_vecs_angle ( a, b );

 

****** Description ******

 

This function computes the angle between two vectors. The result,  expressed

in radians, is between 0 and two pi.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | first vector                 |

------------------------------------------------------------------------------

| PT2                    | b                  | second vector                |

------------------------------------------------------------------------------

 

****** Return value ******

 

The return value is the angle between the two input vectors.

 

****** Example ******

 

 

#include <c2vdefs.h>

 

void print_angle ( vec1, vec2 )

PT2 vec1, vec2 ;

{

      REAL angle ;

      angle = c2v_vecs_angle ( vec1, vec2 ) ;

      printf ( "The angle between the vectors is %lf.\n",

            angle / PI_OVER_180 ) ;

}

This subroutine prints out the angle between two vectors.

 

***>> c2v_vecs_cos  <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL c2v_vecs_cos ( a, b );

 

****** Description ******

 

This function computes the cosine of the angle between two vectors.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | first vector                 |

------------------------------------------------------------------------------

| PT2                    | a                  | second vector                |

------------------------------------------------------------------------------

 

****** Return value ******

 

The return value is the cosine of the angle between two vectors.

 

****** Example ******

 

 

#include <c2vdefs.h>

 

void print_cosine ( vec1, vec2 )

PT2 vec1, vec2 ;

{

      REAL cosine ;

      cosine = c2v_vecs_cos ( vec1, vec2 ) ;

      printf ( "cosine of angle between vectors is: %lf\n",

            cosine ) ;

}

This subroutine prints out the cosine of the angle between two vectors.

 

***>> c2v_vecs_parallel <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

BOOLEAN c2v_vecs_parallel( a, b );

 

****** Description ******

 

This function determines if two vectors are parallel. Two vectors  are

parallel if the absolute value of the sine of the angle between  them is less

than or equal to the relative tolerance.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | first vector                 |

------------------------------------------------------------------------------

| PT2                    | b                  | second vector                |

------------------------------------------------------------------------------

 

****** Return value ******

 

This function return TRUE if the vectors are parallel, and FALSE if  the

vectors are not parallel.

 

****** Example ******

 

 

#include <c2vdefs.h>

 

void check_parallel ( vec1, vec2 )

PT2 vec1, vec2 ;

{

      if ( c2v_vecs_parallel ( vec1, vec2 ) )

            printf ( "vectors are parallel\n" );

}

This subroutines checks to see if two vectors are parallel.

 

***>> c2v_vecs_sin  <<***

 

****** Summary ******

 

#include <c2vdefs.h>

 

REAL c2v_vecs_sin ( a, b );

 

****** Description ******

 

This function computes the sine of the angle between two vectors.

 

****** Input ******

 

------------------------------------------------------------------------------

| PT2                    | a                  | first vector                 |

------------------------------------------------------------------------------

| PT2                    | b                  | second vector                |

------------------------------------------------------------------------------

 

****** Return value ******

 

The return value is the sine of the angle between the input two vectors.

 

****** Example ******

 

 

#include <c2vdefs.h>

 

void print_sine ( vec1, vec2 )

PT2 vec1, vec2 ;

{

      REAL sine ;

      sine = c2v_vecs_sin ( vec1, vec2 ) ;

      printf ( "sine of angle between vectors is %lf.\n",

            sine ) ;

}

This subroutine prints out the sine of the angle between two vectors.

 

***>> PARM_SET <<***

 

****** Summary ******

 

#include <qgldefs.h>

 

PARM_SET ( t, parm );

 

****** Description ******

 

This macro initializes a parameter record to the parameter value  t.

 

****** Input ******

 

------------------------------------------------------------------------------

| REAL                   | t                  | parameter value              |

------------------------------------------------------------------------------

 

****** Input ******

 

------------------------------------------------------------------------------

| PARM                   | parm               | parameter record to          |

|                        |                    | initialize; target; must be  |

|                        |                    | allocated or  declared as an  |

|                        |                    | automatic variable structure  |

------------------------------------------------------------------------------

 

****** Example ******

 

#include <qgldefs.h>

 

void main()

{

      PARM_S p1, p2;

      PARM_SET ( 0.1, &p1 );

      ald_parm_copy ( &p1, &p2 );

      printf ( "%lf\n", PARM_T(&p2) );

}

This program initializes a parameter record, and then copies it to  another

parameter record.

 

***>> qgl_get_tol  <<***

 

****** Summary ******

 

#include <qgldefs.h>

 

REAL qgl_get_tol();

 

****** Description ******

 

This function returns the current value of the relative tolerance.

 

****** Example ******

 

#include <qgldefs.h>

void main()

{

      REAL world_size = qgl_get_world_size(),

            rel_tol = qgl_get_tol(), tol, x = 1e-9;

      tol = world_size * rel_tol;

      if ( fabs(x) < tol )

            printf ( "x is less than the absolute tolerance\n" );

      if ( IS_SMALL(x) )

            printf ( "x is less than the absolute tolerance\n" );

}

This program compares a real number to the absolute tolerance.

 

***>> qgl_get_world_size  <<***

 

****** Summary ******

 

#include <qgldefs.h>

 

REAL qgl_get_world_size();

 

****** Description ******

 

This function returns the current value of the world size.

 

****** Example ******

 

#include <math.h>

#include <qgldefs.h>

void main()

{

      REAL world_size = qgl_get_world_size(),

            rel_tol = qgl_get_tol(), tol, x;

      printf ( "Enter x:" );

      scanf ( "%lf", &x );

      tol = world_size * rel_tol;

      if ( fabs(x) < tol )

            printf ( "x is less than the absolute tolerance\n" );

      if ( IS_SMALL(x) )

            printf ( "x is less than the absolute tolerance\n" );

}

This program compares a real number to the absolute tolerance.

 

***>> qgl_is_small <<***

 

****** Summary ******

 

#include <qgldefs.h>

 

BOOLEAN qgl_is_small( a );

 

****** Description ******

 

This function determines if the absolute value of a REAL number  is less than

or equal to the absolute tolerance.

 

****** Input ******

 

------------------------------------------------------------------------------

| REAL                   | a                  | a number                     |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is TRUE if the absolute value of input number is  less than

or equal to the absolute tolerance, and FALSE otherwise.

 

****** Example ******

 

#include <qgldefs.h>

 

void main()

{

      REAL a = 0.001;

      if ( qgl_is_small(a) )

            printf ( "a is less than or equal to " );

      else

            printf ( "a is greater than" );

      printf ( "the absolute tolerance\n" );

}

This program determines if 0.001 is less than or greater than the  absolute

tolerance.

 

***>> qgl_is_zero <<***

 

****** Summary ******

 

#include <qgldefs.h>

 

BOOLEAN qgl_is_zero( a );

 

****** Description ******

 

This function determines if the relative value of a REAL number  is less than

or equal to the relative tolerance.

 

****** Input ******

 

------------------------------------------------------------------------------

| REAL                   | a                  | a number                     |

------------------------------------------------------------------------------

 

****** Return Value ******

 

The return value is TRUE if the relative value of input number is  less than

or equal to the relative tolerance, and FALSE otherwise.

 

****** Example ******

 

#include <qgldefs.h>

 

void main()

{

      REAL a = 0.001;

      if ( qgl_is_zero(a) )

            printf ( "a is less than or equal to " );

      else

            printf ( "a is greater than" );

      printf ( "the relative tolerance\n" );

}

This program determines if 0.001 is less than or greater than the  relative

tolerance.

 

***>> qgl_put_tol  <<***

 

****** Summary ******

 

#include <qgldefs.h>

 

void qgl_put_tol ( tol );

 

****** Description ******

 

This function sets the value of the relative tolerance.

 

****** Input ******

 

------------------------------------------------------------------------------

| REAL                   | tol                | relative tolerance value     |

------------------------------------------------------------------------------

 

****** Example ******

 

#include <math.h>

#include <qgldefs.h>

void main()

{

      REAL world_size = qgl_get_world_size(),

            rel_tol, tol = 1e-6, x;

      printf ( "Enter x:" );

      scanf ( "%lf", &x );

      rel_tol = tol / world_size;

      qgl_put_tol ( rel_tol );

}

This programs sets the relative tolerance.

 

***>> qgl_put_world_size  <<***

 

****** Summary ******

 

#include <qgldefs.h>

 

void qgl_put_world_size ( w_size );

 

****** Description ******

 

This function sets the world size to w_size. The product of  the world size

with the relative tolerance yields the absolute tolerance  used in

calculations.

 

****** Input ******

 

------------------------------------------------------------------------------

| REAL                   | w_size             | world size                   |

------------------------------------------------------------------------------

 

****** Example ******

 

#include <qgldefs.h>

void main()

{

      REAL world_size = qgl_get_world_size();

      world_size = world_size * 10;

      qgl_put_world_size ( world_size );

}

This programs increases the world size by a factor of 10. The absolute

tolerance, which is dependent on the world size, is also increased  by a

factor of 10.