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 Kit / 3D (CCDK/3D) provides
functions
that enable your programs to create 3D
curves and points, and to
perform
computations with them. These functions
are collectively called
"3D
GEOMETRY".
The 3D
GEOMETRY collection is an extension of 2D GEOMETRY, the set of CCDK
routines
that perform 2D geometric
operations. CCDK/3D adds "pure
3D"
operations
such as projecting a circle onto a
plane to create an ellipse,
and it enables a 3d mode called "2D-on-a-3D
plane".
Geometry
in the "2D-on-a-3D plane" mode is defined in a 2D "local coordinate
system"
positioned in 3D space, and remains in 2D format. When any
information
on this plane is required in 3D format, such as for display, it
is
converted to 3D using the transformation
associated with the local
coordinate
system. Similarly, information in 3D can be projected into this
2D
coordinate system.
3D
curve parameters are handled identically to those in 2D, so a review of
the
Curve Parameters section of the 2D GEOMETRY
Reference is recommended before
reading
this reference.
Both of
the 3D modes provided by the 3D GEOMETRY functions are useful for
applications
such as:
*
architectural design
* sheet
metal bending
* NC
programming for milling and wire EDM
*
surface design
Fundamental
Concepts
====================
Introduction
------------
This
section describes 3D objects and operations without getting into any
programming
details. The purpose of this section is
to provide a basis for
the
sections of this reference that present
programming information.
3D
Objects
----------
The 3D
object types supported by 3D GEOMETRY are:
*
points and vectors
*
curves
*
bounding boxes
*
transform
A point
is a set of cartesian coordinates. A
vector is a set of cartesian
coordinates
that is the difference between two
points.
A curve
is a general object that can represent
any of these specific types:
* line
* arc
*
ellipse
*
polycurve
*
B-spline
A line
is a linear segment.
An arc
is a part or all of a full circle.
An
ellipse is an elliptical segment.
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.
A
bounding box is a 3D rectangular prism, usually used to record the extents
of a 3D
object. This box is aligned with
the coordinate axes.
Bounding
boxes are useful for determining the approximate locations and
sizes
of 3D objects. This information can be
applied to "cull" objects
from
a set
to increase performance. For example,
drawing performance is increased
for the
"zoom" operation if objects whose
bounding boxes do not appear in
the
view are skipped.
A
transform is a matrix used to transform objects from one coordinate system
into
another.
Curve
Properties
----------------
CCDK/3D
takes advantage of a set of curve properties to enable all curves to
be
treated as one type.
These
curve properties summarized by the following
statements:
* Every
curve has a start point, an end point and an
"orientation"; if it 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 its start point
to its 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, and other
mathematical properties.
*
Curves may be rotated, scaled, translated, mirrored, intersected and
trimmed.
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.
3D
Geometric Operations
-----------------------
This
section presents the 3D operations provided by CCDK/3D functions.
3D
operations consist of four categories:
* point
and vector
* curve
*
bounding box
*
transform
Point
and vector operations are divided into
four groups:
*
construction
*
evaluation
*
addition and multiplication
*
conversion between 2D and 3D
Construction
functions create points and vectors, and set
coordinate values.
They also create copies of points and vectors, and build points and vectors
from
other points and vectors. They also perform transformations such as
rotation,
scaling, mirroring and projection.
Evaluation
functions compute properties of points and
vectors, such as
distances,
lengths, and angles.
Addition
and multiplication functions perform standard
vector operations,
including
weighted sums, dot and cross products.
Conversion
operations transform points and vectors between 3D space and 2D
local
coordinate systems.
Curve
functions are divided into:
*
construction
*
copying
*
modification
*
evaluation
* 2D
<-> 3D conversion
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, optionally with alterations such
as
transformations or trimming.
Modification
operations, which change existing geometry, include:
*
trimming
*
breaking
*
rotation
* scaling
*
mirroring
*
translation
Evaluation
operations compute information about geometry such as: end point
coordinates,
tangent vectors, and lengths.
2D<->3D
conversion operations are the link between 3D space and the 2D local
coordinate
systems positioned in 3D space.
These operations convert 3D
curves
lying on the plane of a local
coordinate system into 2D equivalents
expressed
in coordinates relative to the origin,
x and y axes of the local
coordinate
system. They also bring 2D curves
defined in a local coordinate
system
back into 3D format.
Intersection
of 3D curves is performed by using 2D
intersection routines.
If the
3D curves to be intersected are planar
and are in the same plane,
they
can be converted into 2D in a local
coordinate system on the plane, and
intersected
as 2D curves. The curve parameters of
the intersection points
on the
2D curves also correspond to the
intersection points on the 3D
curves.
If the
3D curves are not planar, or in the same plane, they can be projected
onto a
single plane and intersected as described above. This technique can
be used
to find points where 3D curves appear to
intersect when viewed along
the
normal of the plane onto which they are
projected for intersection.
These
intersection points are called
"apparent" intersections.
Bounding
box operations are divided into:
*
construction
*
evaluation
Construction
operations create and build bounding boxes.
Evaluation
consists of a test that determines if two 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.
Types
=====
Introduction
------------
This
section presents programming information for creating and using the
objects
in defined by CCDK/3D. Use this section
of the manual to locate the
name of
object types and the access macros that access
the attributes of
these
types.
Type
Overview
-------------
The
types provided by CCDK/3D include:
* point
or vector
*
bounding box
* curve
*
transform
A point
or vector represents a position or a direction in 3D space.
A
bounding box is a rectangular prism, used to record the volume spanned by
a 3D
object.
A curve
represents curve geometry, including lines, arcs, circles,
polycurves
and NURB-splines. Some curves, such
as ellipses, parabolas, and
hyperbolas,
can be represented precisely by
NURB-splines. Other curves,
such as
sine and cosine curves can be
approximated to a specified degree of
accuracy.
A
transform is a matrix used to transform objects from one coordinate system
to
another.
The
sections below provide information about the type definitions provided
by
CCDK/3D for representing and using these objects.
Point
------
One
object type represents both points and vectors. Although points and
vectors
are conceptually different, they may be represented by the same type
and
processed by the same routines.
______________________________________________________________________________
|
Type |
Meaning |
|----------------------------------------------------------------------------|
|
PT3 | a
3D point or vector |
|
PT3 | a
pointer to a 3D point or vector |
------------------------------------------------------------------------------
Declaring
a variable of type PT3 allocates uninitialized space for three
coordinate
values. The coordinates values must be
set using access macros,
or with
the function c3v_set.
These
types are defined in the header file c3defs.h.
The
following macros access the coordinates of points and components of
vectors:
______________________________________________________________________________
|
Macro |
Meaning |
|----------------------------------------------------------------------------|
|
PT3_X(P) | a REAL which is the x
coordinate |
| | of 3D
point P |
|
PT3_Y(P) | a
REAL which is the y coordinate |
| | of 3D point P |
|
PT3_Z(P) | a
REAL which is the z coordinate |
| | of 3D
point P |
------------------------------------------------------------------------------
These
macros are defined in the header file c3defs.h.
Bounding
Box
------------
Bounding
boxes are represented by these types:
______________________________________________________________________________
|
Type | Meaning |
|----------------------------------------------------------------------------|
|
C3_BOX_S | a
3D bounding box structure |
|
C3_BOX | a 3D bounding box |
------------------------------------------------------------------------------
These
types are defined in the header file c3defs.h.
The
term "bounding box" means an object of type C3_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:
C3_BOX_S
box_s;
C3_BOX
box = &box_s;
Alternatively,
memory for a bounding box may be allocated with c3a_box:
C3_BOX
box = c3a_box ( NULL, NULL );
When an
allocated bounding box is no longer needed, it must be freed with
c3a_free_box.
The
following macros access bounding box information:
______________________________________________________________________________
|
Macro |
Meaning |
|----------------------------------------------------------------------------|
|
C3_MIN_PT(B) | a
PT3 which specifies the bottom |
| | left
back corner of bounding box |
| | B |
|
C3_MAX_PT(B) | a
PT3 which specifies the top |
| | right
front corner of bounding |
| | box
B |
|
C3_MIN_X(B) | a
REAL which specifies the x |
| | coordinate of the bottom left
|
| | back
corner of bounding box B |
|
C3_MIN_Y(B) | a
REAL which specifies the y |
| | coordinate of the bottom left
|
| | back
corner of bounding box B |
|
C3_MIN_Z(B) | a
REAL which specifies the z |
| | coordinate
of the bottom left |
| | back
corner of bounding box B |
|
C3_MAX_X(B) | a
REAL which specifies the x |
| |
coordinate of the top right front |
| | corner
of bounding box B |
|
C3_MAX_Y(B) | a
REAL which specifies the y |
| |
coordinate of the top right front |
| | corner
of bounding box B |
|
C3_MAX_Z(B) | a
REAL which specifies the z |
| |
coordinate of the top right front |
| | corner of bounding box B |
------------------------------------------------------------------------------
These
macros are defined in the header file c3defs.h.
Curve
-----
The
following object type defines a 3D curve:
______________________________________________________________________________
|
Type |
Meaning |
|----------------------------------------------------------------------------|
| C3_CURVE | a 3D curve |
------------------------------------------------------------------------------
An
object of type C3_CURVE can be used to 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.
C3_CURVE
is defined in the header file c3defs.h.
The
following macros access curve parameters:
______________________________________________________________________________
|
Type |
Meaning |
|----------------------------------------------------------------------------|
|
C3_CURVE_PARM0(C) | a
PARM corresponding to the start |
| | point
of curve C |
|
C3_CURVE_PARM1(C) | a
PARM corresponding to the end |
| | point
of curve C |
| C3_CURVE_T0(C) | a REAL specifying the
curve |
| |
parameter value of the start |
| | point
of curve C |
|
C3_CURVE_T1(C) | a REAL specifying the
curve |
| |
parameter value of the end point |
| | of
curve C |
------------------------------------------------------------------------------
The
following macros access curve bounding boxes:
______________________________________________________________________________
|
Macro |
Meaning |
|----------------------------------------------------------------------------|
|
C3_CURVE_BOX(C) | a
C3_BOX which is the bounding box |
| | of
curve C |
|
C3_CURVE_X_MIN(C) | a
REAL which is the x coordinate |
| | of the
lower left back corner of |
| | the
bounding box of curve C |
|
C3_CURVE_X_MAX(C) | a REAL which is the x
coordinate |
| | of the
upper right front corner |
| | of the
bounding box of curve C |
|
C3_CURVE_Y_MIN(C) | a
REAL which is the y coordinate |
| | of the
lower left back corner of |
| | the
bounding box of curve C |
|
C3_CURVE_Y_MAX(C) | a
REAL which is the y coordinate |
| | of the
lower left back corner of |
| | the
bounding box of curve C |
|
C3_CURVE_Z_MIN(C) | a
REAL which is the z coordinate |
| | of the
lower left back corner of |
| | the
bounding box of curve C |
|
C3_CURVE_Z_MAX(C) | a
REAL which is the z coordinate |
| | of the lower left back corner
of |
| | the
bounding box of curve C |
------------------------------------------------------------------------------
The
following macros report curve type:
______________________________________________________________________________
|
Macro |
Meaning |
|----------------------------------------------------------------------------|
|
C3_CURVE_IS_LINE(C) |
TRUE if curve C is a 3D line; |
| | FALSE
otherwise |
|
C3_CURVE_IS_ARC(C) |
TRUE if curve C is a 3D arc or |
| | circle; FALSE otherwise |
|
C3_CURVE_IS_PCURVE(C) |
TRUE if curve C is a 3D polycurve; |
| | FALSE
otherwise |
------------------------------------------------------------------------------
These
macros are defined in the header file c3defs.h.
Also,
if the symbol SPLINE is defined, the following macros are defined.
______________________________________________________________________________
|
Type |
Meaning |
|----------------------------------------------------------------------------|
|
C3_CURVE_IS_ELLIPSE(C) |
TRUE if curve C is a 3D ellipse; |
| | FALSE otherwise |
------------------------------------------------------------------------------
These
macros are defined in the header file c3defs.h.
Transform
---------
3D
transforms are represented by the type:
______________________________________________________________________________
|
Type |
Meaning |
|----------------------------------------------------------------------------|
|
C3_TRANSFORM | a
3D transform |
------------------------------------------------------------------------------
This
type is defined in the header file c3defs.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 C3_TRANSFORM allocates space for the
transform
matrix.
To
allocate dynamic memory for a transform, use c3t_create:
C3_TRANSFORM
*t = c3t_create();
When an
allocated transform is no longer needed, it must be freed with
c3t_free.
Functions
and Macros By Category
================================
Introduction
------------
This
section presents CCDK/3D functions grouped according to the operations
that
they perform.
Category
Overview
-----------------
The
general categories that all CCDK/3D functions fall into are:
*
point/vector functions
* curve
functions
* bounding
box functions
*
transform functions
Functions
that perform point and vector operations are
divided into the
following
groups:
*
construction
*
evaluation
*
addition and multiplication
*
2D<->3D conversion
Construction
functions create points and vectors.
Evaluation functions
compute
point and vector properties such as
distances and angles. Addition
and
multiplication functions provide
standard point and vector computations.
2D<-> 3D functions provide
transformations between 3D space and 2D
local
coordinate
systems positioned in 3D space.
Functions
that perform curve operations are divided
into the following
groups:
*
construction
*
copying
*
modification
*
evaluation
* 2D
<-> 3D conversion
Construction
functions create 3D curves. Copying
functions create copies of
curves,
with optional alterations. Modification
functions change existing
curves. Evaluation functions compute curve
properties such as coordinates
and
tangent vectors. 2D<->3D functions provide transformations between 3D
space
and 2D local coordinate systems
positioned in 3D space.
Functions
that perform bounding box operations are
divided into the
following
groups:
*
construction
*
evaluation
Construction
functions create and modify bounding boxes.
Evaluation
is testing if bounding boxes overlap or interfere.
Functions
that perform transform operations are
divided into the following
groups:
*
construction
*
evaluation
Construction
functions create and combine transforms. Evaluation apply
transforms
to points and vectors.
Function
Prefixes
-----------------
All
CCDK/3D functions begin with a three character
prefix that indicates the
general
purpose of the function. The table below lists the prefixes used in
CCDK/3D
and their meaning.
______________________________________________________________________________
|
Prefix |
Meaning |
|----------------------------------------------------------------------------|
|
c3v |
point- and vector-related |
|
c3d |
curve creation and copying |
|
c3c |
curve modification and evaluation |
|
c3a |
bounding box |
|
c3t |
transform |
------------------------------------------------------------------------------
Point/Vector
Construction
-------------------------
CCDK/3D
provides a variety of point and vector construction functions.
The
following CCDK/3D functions create new points and vectors:
______________________________________________________________________________
|
Function |
Use |
|----------------------------------------------------------------------------|
|
c3d_point |
to allocate a point |
|
c3v_set |
to set the coordinates of a point |
|
c3v_set_zero |
to set the coordinates of a point |
| | to
(0,0,0) |
|
c3d_free_point |
to free a point |
------------------------------------------------------------------------------
The
following CCDK/3D functions build points and
vectors from other vectors:
______________________________________________________________________________
|
Function |
Use |
|----------------------------------------------------------------------------|
|
c3v_copy | to copy a point or a
vector |
|
c3v_negate |
to construct a vector which has |
| | the
reverse direction of a given |
| | vector |
|
c3v_mid_pt |
to construct the midpoint between |
| | two
vectors |
|
c3v_unit_normal |
to construct a vector of unit |
| | length
perpendicular to two given |
| |
vectors |
|
c3v_project_line |
to project a point onto a line |
| |
segment defined by two points |
|
c3v_basis
| to construct two
perpendicular |
| | unit
vectors which are both |
| | perpendicular to a given
vector; |
| | used
for creating the x and y |
| | axes
of a local coordinate system |
------------------------------------------------------------------------------
The
following functions normalize vectors:
______________________________________________________________________________
|
Function |
Use |
|----------------------------------------------------------------------------|
|
c3v_normalize |
to divide each component of a |
| | vector
by its length to produce a |
| | vector of unit length |
|
c3v_normalize_l1 |
to divide the components of a |
| | vector
by its "Manhattan
length"; |
| | produces a vector whose length
is |
| | close
to one |
------------------------------------------------------------------------------
The
following functions rotate and scale points and vectors:
______________________________________________________________________________
|
Function |
Use |
|----------------------------------------------------------------------------|
|
c3v_rotate_pt |
to rotate a point about an axis |
|
c3v_rotate_pt_cs |
to rotate a point about an axis |
| | given
the cosine and sine of the |
| | rotation angle |
|
c3v_rotate_vec |
to rotate a vector about an axis |
|
c3v_rotate_vec_cs |
to rotate a vector about an axis |
| | given the cosine and
sine of the |
| |
rotation angle |
|
c3v_scale |
to multiply a vector by a scalar |
|
c3v_mirror_pt | to mirror a point about a plane |
| |
defined by a normal vector and a |
| |
distance from the origin |
|
c3v_mirror_vec |
to mirror a vector about a plane |
| |
defined by a normal vector and a |
| |
distance from the origin |
------------------------------------------------------------------------------
The
following functions project points and vectors onto planes:
______________________________________________________________________________
|
Function |
Use |
|----------------------------------------------------------------------------|
|
c3v_project_pt_normal |
to project a point orthogonally |
| | onto a
plane |
|
c3v_project_pt_oblique | to project a point onto a plane |
| | along
a specified direction |
|
c3v_project_vec_normal |
to project a vector orthogonally |
| | onto a
plane |
|
c3v_project_vec_oblique |
to project a vector onto a plane |
| | along
a specified direction |
|
c3v_plane_3pts |
to construct a plane from three |
| |
points |
|
c3v_pt_on_plane |
to determine if a point is on a |
| |
plane |
|
c3v_vec_on_plane |
to determine if a vector is on a |
| |
plane |
------------------------------------------------------------------------------
When
using point/vector construction functions, include the header file
c3ddefs.h
or c3vdefs.h, depending on the prefix.
Point/Vector
Evaluation
-----------------------
Once
points and vectors are constructed, CCDK/3D functions can be used to
compute
their properties.
The
following functions compute distances and lengths:
______________________________________________________________________________
|
Function |
Use |
|----------------------------------------------------------------------------|
|
c3v_dist |
to compute the distance between |
| | two
points |
|
c3v_dist_squared |
to compute the square of the |
| |
distance between two points |
|
c3v_distl1 |
to compute the "Manhattan"
|
| |
distance (the sum of the absolute |
| | values
of the components) between |
| | two
points |
|
c3v_norm |
to compute the length of a vector |
|
c3v_norm_squared |
to compute the square of the |
| | length
of a vector |
|
c3v_norml1 |
to compute the "Manhattan" length
|
| | of a vector |
|
c3v_ident_pts |
to determine if two points |
| |
coincide within the absolute |
| | tolerance |
|
c3v_is_small |
to determine if the absolute |
| | values
of all of the coordinates |
| | are
less that the absolute |
| |
tolerance |
------------------------------------------------------------------------------
The
following functions compute angles related to
points and vectors:
______________________________________________________________________________
|
Function |
Use |
|----------------------------------------------------------------------------|
|
c3v_vecs_angle |
to compute the angle between two |
| |
vectors |
|
c3v_vecs_cos |
to compute the cosine of the angle |
| | between two vectors |
|
c3v_vecs_sin |
to compute the sine of the angle |
| |
between two vectors |
|
c3v_vecs_parallel | to determine if the angle
between |
| | two
vectors is less than the |
| |
relative tolerance |
|
c3v_spherical |
to compute the spherical |
| |
coordinates of a 3D point |
|
c3v_set_spherical |
to set the direction of a 3D |
| | vector
to a direction specified |
| | by
spherical coordinates |
------------------------------------------------------------------------------
When
using point/vector evaluation functions, include the header file
c3vdefs.h.
Point/Vector
Addition and Multiplication
----------------------------------------
CCDK/3D
provides two sets of functions for standard vector computations.
The
following functions perform vector addition and subtraction:
______________________________________________________________________________
|
Function |
Use |
|----------------------------------------------------------------------------|
|
c3v_add | to add to vectors |
|
c3v_addc |
to compute the sum of a vector and |
| | the
weighted sum of two other |
| | vectors |
|
c3v_addt |
to compute the sum of a vector and |
| | a
multiple of another vector |
|
c3v_addu |
to compute the convex combination |
| | of two
vectors |
|
c3v_addw |
to compute the weighted sum of two |
| |
vectors |
|
c3v_sub |
to subtract two vectors |
|
AD |
tion Use |
------------------------------------------------------------------------------
When
using vector computation functions, include the header file c3vdefs.h.
2D<->3D
Point/Vector Conversion
-------------------------------
The
following functions convert points and vectors
between 3D and 2D
formats:
______________________________________________________________________________
|
Function |
Use |
|----------------------------------------------------------------------------|
|
c3v_conv_pt_3d2d |
to convert a 3D point into a 2D |
| | point
in a local coordinate |
| |
system |
|
c3v_conv_pt_2d3d |
to convert a 2D point in a local |
| |
coordinate system into a 3D point |
| | |
|
c3v_conv_vec_3d2d |
to convert a 3D vector into a 2D |
| | vector
in a local coordinate |
| |
system |
|
c3v_conv_vec_2d3d |
to convert a 2D vector in a local |
| | coordinate system into a 3D |
| |
vector |
|
c3v_coord_sys
| to construct a local
coordinate |
| | system on a plane |
------------------------------------------------------------------------------
When
using point/vector conversion functions, include the header file
c3vdefs.h.
Curve
Construction
------------------
CCDK/3D
provides two groups of curve construction functions. One set
creates
single-segment curves, and the other creates polycurves, which are
multi-segment
chains of lines and arcs.
The
following functions create single-segment curves:
______________________________________________________________________________
|
Function |
Use |
|----------------------------------------------------------------------------|
|
c3d_line | to construct a line
defined by two |
| |
points |
|
c3d_line_dir |
to construct a line defined by a |
| | point and a direction vector
|
|
c3d_ray |
to construct a line defined by a |
| | point
and the spherical angles of |
| | its
direction |
|
c3d_arc_3pts |
to create an arc passing through |
| | three
points |
|
c3d_arc_2pts_tan |
to construct an arc starting at |
| | one
point with a specified |
| |
tangent, and ending at another |
| |
point |
| c3d_arc_2pts_ctr | to construct an arc
with a given |
| |
center, starting at one point and |
| | ending
at another |
|
c3d_circle | to construct a circle
defined by a |
| | center
point, normal and a radius |
------------------------------------------------------------------------------
@TABLEHEAD
= The following functions construct splines.
They are available
only
when the symbol SPLINE is defined:
parameterization
The
following functions create polycurves:
______________________________________________________________________________
|
Function | Use |
|----------------------------------------------------------------------------|
|
c3d_pcurve_init |
to start a polycurve |
|
c3d_pcurve_through |
to create a polygonal polycurve |
| |
through a set of points |
|
c3d_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 |
|
c3d_pcurve_add_arc_tan |
to add an arc to the end of a |
| |
polycurve tangent to the endpoint |
| | and
ending at a specified point |
|
c3d_pcurve_add_arc_ctr_pt |
to add an arc to the end of a |
| | polycurve starting at the
end |
| | point,
having a specified center, |
| | and
ending at a specified point |
|
c3d_pcurve_add_line | to add a line segment to the
end |
| | of a
polyline |
|
c3d_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 |
|
c3d_pcurve_remove_last |
to remove the last segment from a |
| |
polycurve |
|
c3d_pcurve_close |
to add a segment to close a |
| |
polycurve |
------------------------------------------------------------------------------
The
function c3d_pcurve_segment creates a C3_CURVE object from a specified
segment
of a 3D polycurve.
The
function c3d_curve_to_spline converts all curve types to splines.
The
function c3d_free_curve frees curves.
When
using curve construction functions, include the header file c3ddefs.h.
Curve
Copying
-------------
CCDK/3D
provides a number of curve copying functions.
Many of these
functions
not only copy a curve, but also apply some other operation such as
transformation
or trimming.
The
function c3d_copy creates an identical copy of a curve.
The
following functions make transformed copies of 3D curves:
______________________________________________________________________________
|
Function |
Use |
|----------------------------------------------------------------------------|
|
c3d_rotate |
to create a curve which is the |
| |
rotation of a curve |
|
c3d_rotate_cs |
to create a curve which is the |
| |
rotation of a curve; the rotation |
| | angle
is specified with its cosine |
| | and
sine; this routine makes |
| |
rotating batches of geometry more |
| |
efficient |
|
c3d_scale |
to create a curve which is the |
| | scale
of a curve |
|
c3d_translate |
to create a curve which is the |
| |
translation of a curve |
|
c3d_mirror |
to create a curve which is the |
| | mirror image of a curve about a
|
| |
plane |
|
c3d_transform |
to create a copy of a curve, and |
| | to
transform the copy |
------------------------------------------------------------------------------
The
following functions make trimmed copies of 3D
curves:
______________________________________________________________________________
|
Function |
Use |
|----------------------------------------------------------------------------|
|
c3d_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 |
|
c3d_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 |
|
c3d_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 |
|
c3d_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 |
|
c3d_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 |
|
c3d_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 |
------------------------------------------------------------------------------
The
following functions create copies of 3D curves
projected on specified
planes:
______________________________________________________________________________
|
Function |
Use |
|----------------------------------------------------------------------------|
|
c3d_project_normal |
to create a curve which is the |
| |
orthogonal projection of a |
| |
specified curve onto a specified |
| |
plane |
|
c3d_project_oblique |
to create a curve which is the |
| | projection of a specified curve
|
| | onto a
specified plane along a |
| |
specified direction |
|
ng |
@SECTION = Curve Modification
|
------------------------------------------------------------------------------
The
following functions modify 3D curves by rotating, scaling, translation
and
mirroring them:
______________________________________________________________________________
|
Function |
Use |
|----------------------------------------------------------------------------|
|
c3c_rotate |
to rotate a curve about an axis |
|
c3c_rotate_cs |
to rotate a curve about an axis |
| | given
the cosine and sine of the |
| |
rotation angle |
|
c3c_scale |
to scale a curve |
|
c3c_translate |
to translate a curve |
|
c3c_mirror |
to mirror a curve about a plane |
|
c3c_transform |
to transform a curve |
------------------------------------------------------------------------------
The
following functions project 3D curves onto planes:
______________________________________________________________________________
|
Function |
Use |
|----------------------------------------------------------------------------|
|
c3c_project_normal |
to project a curve orthogonally |
| | onto a
specified plane |
|
c3c_project_oblique |
to project a curve onto a |
| |
specified plane along a specified |
| |
direction |
------------------------------------------------------------------------------
The
following functions trim 3D curves:
______________________________________________________________________________
|
Function |
Use |
|----------------------------------------------------------------------------|
|
c3c_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 |
|
c3c_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 |
|
c3c_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 |
|
c3c_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 |
|
c3c_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 |
|
c3c_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 c3cdefs.h.
Curve
Evaluation
----------------
The
following functions compute coordinates and
tangent vectors at the start
and end
points of 3D curves:
______________________________________________________________________________
| Function | Use |
|----------------------------------------------------------------------------|
|
c3c_ept0 |
to compute the coordinates of the |
| | start point of a curve |
|
c3c_ept1 |
to compute the coordinates of the |
| | end
point of a curve |
|
c3c_ept_tan0 | to evaluate the coordinates and |
| | the
tangent vector at the start |
| | point
of a curve |
|
c3c_ept_tan1 |
to evaluate the coordinates and |
| | the
tangent vector at the end |
| | point
of a curve |
|
c3c_etan0 |
to evaluate the tangent vector at |
| | the
start point of a curve |
|
c3c_etan1 |
to evaluate the tangent vector at |
| | the
end point of a curve |
| c3c_closed | to determine if a
curve is closed |
------------------------------------------------------------------------------
The
following functions compute coordinates and tangent vectors at any
specified
point on a 3D curve:
______________________________________________________________________________
|
Function |
Use |
|----------------------------------------------------------------------------|
|
c3c_eval_pt |
to compute or to evaluate the |
| |
coordinates of a point on a curve |
| |
specified by a curve parameter |
| | record |
|
c3c_eval_pt_tan |
to evaluate the coordinates and |
| | the
tangent vector of a curve at |
| | a
location specified by a curve |
| |
parameter record |
|
c3c_eval_tan |
to evaluate a tangent vector of a |
| | curve
at a location specified by |
| | a
curve parameter record |
|
c3c_info_curve |
to print information about a curve |
------------------------------------------------------------------------------
The
function c3c_length computes the length of a 3D curve.
The
function c3c_project projects a points onto a 3D curve. A
related
function,
c3c_select, determines if a point is within
a specified distance
from a
3D curve.
The
following functions compute information about curves which are arcs,
circles
and ellipses.
______________________________________________________________________________
|
Function |
Use |
|----------------------------------------------------------------------------|
|
c3c_get_arc_data |
to obtain the center, radius, |
| | normal
and sweep of a 3D arc |
|
c3c_get_arc_radius | to obtain the radius of an
arc |
|
c3c_get_arc_center |
to obtain the center point of an |
| |
arc |
|
c3c_get_arc_normal | to
obtain the start angle of an |
| | arc;
the result is in radians |
|
c3c_get_arc_sweep |
to obtain the sweep of an arc; the |
| | result
is in radians |
|
c3c_arc_angle |
to compute the arc angle |
| |
corresponding to a specified |
| | curve
parameter |
|
c3c_arc_parm |
to compute the arc curve parameter |
| |
corresponding to a specified |
| |
angle |
|
c3c_get_ellipse_data |
to obtain the center, major and |
| | minor
axes of an ellipse; |
| |
available only if SPLINE is |
| | defined |
|
c3c_get_pcurve_data |
to obtain information about a |
| |
specified segment of a polycurve |
------------------------------------------------------------------------------
Include
c3cdefs.h when using arc, ellipse and polycurve information
routines.
The
following functions create linear interpolations, or "polygonal
approximations",
of 3D curves. The precision of approximation is controlled
by a
specified maximum chordal deviation
from the curve being interpolated.
______________________________________________________________________________
|
Function |
Use |
|----------------------------------------------------------------------------|
|
c3c_approx |
to compute a linear approximation |
| | of a
curve |
|
c3c_approx_init |
to initialize a linear |
| |
approximation of a curve |
------------------------------------------------------------------------------
When
using curve evaluation functions, include the header file c3cdefs.h.
2D
<-> 3D Curve Conversion
--------------------------
The
following functions convert curves from 3D format to 2D, and vice versa.
______________________________________________________________________________
|
Function |
Use |
|----------------------------------------------------------------------------|
|
c3c_on_plane |
to determine if a 3D curve is on a |
| |
plane |
|
c3c_plane |
to determine the plane on which a |
| | 3D
curve lies |
|
c3c_curves_plane |
to determine the plane on which a |
| | set of
3D curves lie |
|
c3d_convert_3d2d |
to convert a 3D curve into a 2D |
| | curve in a specified local |
| |
coordinate system |
|
c3d_convert_2d3d |
to convert a 2D curve in a |
| |
specified local coordinate system |
| | into a
3D curve |
------------------------------------------------------------------------------
When
using curve conversion functions, include the header file c3cdefs.h or
c3ddefs.h,
depending on the prefix.
Bounding
Box Construction and Testing
-------------------------------------
The
following functions create and modify bounding
boxes:
______________________________________________________________________________
|
Function |
Use |
|----------------------------------------------------------------------------|
|
c3a_box |
to allocate a bounding box |
|
c3a_box_init_pt |
to initialize both corners of a |
| |
bounding box to a point |
|
c3a_box_append_pt |
to expand a bounding box to |
| | contain a point |
|
c3a_box_append |
to expand a bounding box to |
| |
contain another bounding box |
|
c3a_box_union | to create a bounding box
that |
| |
contains two bounding boxes |
|
c3a_free_box |
to free a bounding box |
|
c3a_box_copy | to
copy a bounding box |
------------------------------------------------------------------------------
The
following function determine if bounding boxes
overlap:
______________________________________________________________________________
|
Function |
Use |
|----------------------------------------------------------------------------|
|
c3a_box_overlap |
to determine if two bounding boxes |
| | overlap |
|
c3a_box_w_overlap |
to determine if two bounding boxes |
| |
overlap, or are within a |
| | specified distance |
------------------------------------------------------------------------------
When
using bounding box functions, include the header file c3adefs.h.
Transform
Construction and Evaluation
-------------------------------------
The
following functions create and modify 3D transforms:
______________________________________________________________________________
|
Function |
Use |
|----------------------------------------------------------------------------|
|
c3t_create |
to create an identity transform |
|
c3t_mirror |
to construct a 3D transform for |
| | mirroring about a plane |
|
c3t_rotate |
to construct a 3D transform for |
| |
rotating about an axis by a given |
| | angle |
|
c3t_rotate_cs |
to construct a 3D transform for |
| |
rotating about an axis, where the |
| | rotation
axis is specified with |
| | its
cosine and sine |
|
c3t_scale |
to construct a 3D transform for |
| |
scaling about a point |
|
c3t_translate |
to construct a 3D transform for |
| |
translating |
|
c3t_inverse |
to compute the inverse of a 3D |
| |
transform |
|
c3t_orthogonal |
to determine if a transform is |
| |
orthogonal |
|
c3t_lcs | to compute a transform for |
| |
transforming objects from the |
| | global
coordinate system to a |
| | local coordinate system |
|
c3t_mult |
to multiply two transforms |
|
c3t_free |
to free a transform |
------------------------------------------------------------------------------
The
following functions transform points and vectors:
______________________________________________________________________________
|
Function |
Use |
|----------------------------------------------------------------------------|
|
c3t_eval_pt |
to transform a point |
|
c3t_eval_vec |
to transform a vector |
------------------------------------------------------------------------------
When
using transform functions, include the header file c3tdefs.h.
Alphabetized
Reference
======================
@NEWPAGE
=
***>>
c3a_box <<***
******
Summary ******
#include
<c3adefs.h>
C3_BOX
c3a_box ( min_pt, max_pt );
******
Description ******
This
function creates a bounding box initialized to the rectangular prism
defined
by two given points.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | min_pt,
max_pt | the lower left back
and |
| | | upper right front
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
<c3vdefs.h>
#include
<c3adefs.h>
void
main()
{
PT3 p0, p1;
C3_BOX box;
c3v_set ( 2.0, 3.0, 1.0, p0 );
c3v_set ( 5.0, 6.0, 4.0, p1 );
box = c3a_box ( p0, p1 );
c3a_free_box ( box );
}
This
program creates a bounding box with corners (2,3,1) and (5,6,4).
***>>
c3a_box_append <<***
******
Summary ******
#include
<c3adefs.h>
void
c3a_box_append ( box, append_box );
******
Description ******
This
routine expands a bounding box to include another bounding box.
******
Input ******
------------------------------------------------------------------------------
|
C3_BOX | box | the box to expand |
------------------------------------------------------------------------------
|
C3_BOX | append_box | the box fitted into the |
| | | expanded box |
------------------------------------------------------------------------------
******
Example ******
#include
<c3vdefs.h>
#include
<c3adefs.h>
void
main()
{
PT3 p0, p1;
C3_BOX box0, box1;
c3v_set ( 2.0, 3.0, 1.0, p0 );
c3v_set ( 5.0, 6.0, 4.0, p1 );
box0 = c3a_box ( p0, p1 );
c3v_set ( 3.0, 4.0, 5.0, p0 );
c3v_set ( 7.0, 8.0, 6.0, p1 );
box1 = c3a_box ( p0, p1 );
c3a_box_append ( box0, box1 );
c3a_free_box ( box0 );
c3a_free_box ( box1 );
}
This
program creates two bounding boxes and then expands the first to
include
the second.
***>>
c3a_box_append_pt <<***
******
Summary ******
#include
<c3adefs.h>
void
c3a_box_append_pt ( box, pt );
******
Description ******
This
routine expands a bounding box to include a point.
******
Input ******
------------------------------------------------------------------------------
|
C3_BOX | box | the box to expand |
------------------------------------------------------------------------------
|
PT3 | pt | a point |
------------------------------------------------------------------------------
******
Example ******
#include
<c3vdefs.h>
#include
<c3adefs.h>
void
main()
{
PT3 p0, p1, p;
C3_BOX box0;
c3v_set ( 2.0, 3.0, 0.0, p0 );
c3v_set ( 5.0, 6.0, 5.0, p1 );
box0 = c3a_box ( p0, p1 );
c3v_set ( 7.0, 8.0, 7.0, p );
c3a_box_append_pt ( box0, p );
c3a_free_box ( box0 );
}
This
program expands a bounding box to include a point.
***>>
c3a_box_copy <<***
******
Summary ******
#include
<c3adefs.h>
void
c3a_box_copy ( box0, box1 );
******
Description ******
This
function copies a bounding box.
******
Input ******
------------------------------------------------------------------------------
|
C3_BOX | box0 | the box to copy |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
C3_BOX | box1
| the copy; this box must be |
| | | created by the
caller |
------------------------------------------------------------------------------
******
Example ******
#include
<c3vdefs.h>
#include
<c3adefs.h>
void
main()
{
PT3 p0, p1, origin;
C3_BOX box0, box1 ;
c3v_set ( 0.0, 0.0, 0.0, origin );
box1 = c3a_box ( origin, origin );
c3v_set ( 2.0, 3.0, 1.0, p0 );
c3v_set ( 5.0, 6.0, 4.0, p1 );
box0 = c3a_box ( p0, p1 );
c3a_box_copy ( box0, box1 );
c3a_free_box ( box0 );
c3a_free_box ( box1 );
}
This
program makes box1 a copy of box0.
***>>
c3a_box_init_pt <<***
******
Summary ******
#include
<c3adefs.h>
void
c3a_box_init_pt ( box, pt );
******
Description ******
This
function initializes the lower left back and upper right front corners
of a
bounding box to the same point. The
result is a rectangular prism with
zero
volume.
******
Input ******
------------------------------------------------------------------------------
|
C3_BOX | box | the box to initialize |
------------------------------------------------------------------------------
|
PT3 | pt | the point to initialize the |
| | | box to |
------------------------------------------------------------------------------
******
Example ******
#include
<c3adefs.h>
#include
<c3vdefs.h>
void
main()
{
PT3 p;
C3_BOX box = c3a_box ( NULL, NULL );
c3v_set ( 2.0, 3.0, 0.0, p );
c3a_box_init_pt ( box, p );
c3a_free_box ( box );
}
This
program creates a bounding box with both corners (2.0,3.0,0.0).
***>>
c3a_box_overlap <<***
******
Summary ******
#include
<c3adefs.h>
BOOLEAN
c3a_box_overlap ( box1, box2 );
******
Description ******
This
routine determines if two bounding boxes overlap.
******
Input ******
------------------------------------------------------------------------------
|
C3_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
<c3vdefs.h>
#include
<c3adefs.h>
void
main()
{
PT3 p0, p1;
C3_BOX box0, box1;
c3v_set ( 2.0, 3.0, 1.0, p0 );
c3v_set ( 5.0, 6.0, 4.0, p1 );
box0 = c3a_box ( p0, p1 );
c3v_set ( 3.0, 4.0, 2.0, p0 );
c3v_set ( 7.0, 8.0, 6.0, p1 );
box1 = c3a_box ( p0, p1 );
if ( c3a_box_overlap ( box0, box1 ) )
printf ( "boxes overlap\n"
);
c3a_free_box ( box0 );
c3a_free_box ( box1 );
}
This
program tests two bounding boxes to determine if they overlap, and
returns
TRUE in this particular example.
***>>
c3a_box_union <<***
******
Summary ******
#include
<c3adefs.h>
void
c3a_box_union ( box1, box2, box );
******
Description ******
This
function computes the bounding box that encloses two bounding boxes.
******
Input ******
------------------------------------------------------------------------------
|
C3_BOX | box1, box2 | the boxes to enclose |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
C3_BOX | box | the box that contains
both |
| | | input boxes |
------------------------------------------------------------------------------
******
Example ******
#include
<c3vdefs.h>
#include
<c3adefs.h>
void
main()
{
PT3 p0, p1;
C3_BOX box0, box1, box;
c3v_set ( 2.0, 3.0, 1.0, p0 );
c3v_set ( 5.0, 6.0, 4.0, p1 );
box0 = c3a_box ( p0, p1 );
c3v_set ( 3.0, 4.0, 2.0, p0 );
c3v_set ( 7.0, 8.0, 6.0, p1 );
box1 = c3a_box ( p0, p1 );
box = c3a_box ( NULL, NULL );
c3a_box_union ( box0, box1, box );
c3a_free_box ( box );
c3a_free_box ( box0 );
c3a_free_box ( box1 );
}
This
program computes the bounding box that encloses two boxes.
***>>
c3a_box_w_overlap <<***
******
Summary ******
#include
<c3adefs.h>
BOOLEAN
c3a_box_w_overlap ( box1, box2, w );
******
Description ******
This
function determines if two boxes are less than a given distance apart.
******
Input ******
------------------------------------------------------------------------------
|
C3_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
<c3vdefs.h>
#include
<c3adefs.h>
void
main()
{
PT3 p0, p1;
C3_BOX box0, box1;
REAL w = 1.0;
c3v_set ( 2.0, 3.0, 1.0, p0 );
c3v_set ( 5.0, 6.0, 4.0, p1 );
box0 = c3a_box ( p0, p1 );
c3v_set ( 5.5, 6.5, 4.5, p0 );
c3v_set ( 7.0, 8.0, 6.0, p1 );
box1 = c3a_box ( p0, p1 );
if ( c3a_box_w_overlap ( box0, box1, w ) )
printf ( "boxes overlap or are
less " );
printf ( "than 1 unit
apart\n" );
c3a_free_box ( box0 );
c3a_free_box ( box1 );
}
This
program determines if two bounding boxes overlap or are less than 1
unit
apart.
***>>
c3a_free_box <<***
******
Summary ******
#include
<c3adefs.h>
void
c3a_free_box ( box );
******
Description ******
This
function frees a bounding box.
******
Input ******
------------------------------------------------------------------------------
|
C3_BOX | box | the box to free |
------------------------------------------------------------------------------
******
Example ******
#include
<c3vdefs.h>
#include
<c3adefs.h>
void
main()
{
PT3 p0, p1;
C3_BOX box0;
c3v_set ( 2.0, 3.0, 1.0, p0 );
c3v_set ( 5.0, 6.0, 4.0, p1 );
box0 = c3a_box ( p0, p1 );
c3a_free_box ( box0 );
}
This
program creates and frees a bounding box.
@NEWPAGE
=
***>>
c3c_approx <<***
******
Summary ******
#include
<c3cdefs.h>
BOOLEAN
c3c_approx ( curve, parm1, current_parm,
max_dist, 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
current_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
current_parm. Thus, if a polygon cannot be generated
with one call, it can
be
generated with successive calls.
Prior
to generating a polygon with this function, the argument current_parm
should
be initialized with the c3c_approx_init
function.
This
function optionally computes the curve parameters that correspond to
the
vertices of the polygon.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a 3D curve from which the |
| | | polygon is to be |
| |
| constructed |
------------------------------------------------------------------------------
|
PARM | parm1 | ending parameter value;
the |
| | | polygon will end at the
|
| | | point corresponding to
this |
| | | parameter value; if
this |
| | | argument is NULL, the
|
| | | polygon ends at the
end |
| | | point of the curve |
------------------------------------------------------------------------------
|
PARM |
current_parm | on input, this
argument |
| | | marks the location of
the |
| | | first point to be
computed; |
| | | on output, this
argument |
| | | marks the location of
the |
| | | last point computed;
this |
| |
| parameter must be |
| | | initialized with |
| | | c3c_approx_init
before |
| | | starting the approximation |
------------------------------------------------------------------------------
|
REAL | max_dist | the maximum allowed chordal |
| | | deviation of the polygon
|
| | | from the curve |
------------------------------------------------------------------------------
|
BOOLEAN | dir | the direction to follow;
if |
| | | TRUE, the polygon
follows |
| | | the "natural" direction of |
| | | the curve; if FALSE,
the |
| | | polygon runs
against this |
| | | direction |
------------------------------------------------------------------------------
| PT3
* | pt_buffer
| an array of buf_size points; |
| | | if this argument is NULL, |
| | | the points are not
computed |
------------------------------------------------------------------------------
| PARM
* | parm_buffer | an array of buf_size |
| | | parameter records; if
this |
| | | argument is NULL, the |
| | | parameters are not
computed |
------------------------------------------------------------------------------
|
INT | buf_size | the number of points and/or |
| | | parameters that can be held
|
| | | by the provided
arrays |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
| INT
* | index | the number of points
and/or |
| | | parameters that
were |
| | | computed; this number is |
| | | buf_size if the arrays
are |
| | | completely filled; it is
|
| | | less than buf_size if
the |
| | | number of points
required to |
| | | approximate the curve is |
| |
| less than buf_size; this |
| | | argument is passed by |
| | | reference |
------------------------------------------------------------------------------
******
Return Value ******
This
function returns TRUE if the polygon has reached the point on the curve
where
the polygon should end; otherwise it returns FALSE.
******
Example ******
#include
<c3cdefs.h>
#include
<dmldefs.h>
#define
BUF_SIZE 50
DML_LIST
polygonize_curve ( curve, max_dist )
C3_CURVE
curve ;
REAL
max_dist ;
{
PT3 pt_buffer[BUF_SIZE] ;
DML_LIST pt_list = dml_create_list();
PARM_S curve_parm ;
BOOLEAN end_bit, dir = FALSE;
INT index, i ;
c3c_approx_init ( curve, NULL,
&curve_parm, dir ) ;
do {
end_bit = c3c_approx ( curve, NULL,
&curve_parm, max_dist,
dir, pt_buffer, NULL,
BUF_SIZE, &index ) ;
for ( i=0 ; i < index ; i++ )
dml_append_data ( pt_list,
pt_buffer[i] ) ;
} while ( !end_bit ) ;
return ( pt_list ) ;
}
@NEWPAGE
=
***>>
c3c_approx_init <<***
******
Summary ******
#include
<c3cdefs.h>
void
c3c_approx_init ( curve, parm0, start_parm,
dir );
******
Description ******
This
function initializes the parameter record used in calls to c3c_approx
to mark
the "current" point of a polygon.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | the curve that will be |
| | | approximated |
------------------------------------------------------------------------------
|
PARM | parm0 | the parameter value of the |
| | | point where the
polygon |
| | | should begin; if this |
| | | parameter is NULL,
the |
| | | polygon begins at the
start |
| | | or end point of the curve, |
| | | depending on the value
of |
| | | dir |
------------------------------------------------------------------------------
|
BOOLEAN | dir | the direction that the |
| | | polygon will follow
along |
| | | the curve; if TRUE, the |
| | | polygon will follow
the |
| |
| "natural" direction of the
|
| | | curve; if FALSE, it
will |
| | | follow the opposite |
| | | direction |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PARM | start_parm | the parameter record |
| | | initialized to the
parameter |
| | | value of the start point of |
| | | the polygon. |
------------------------------------------------------------------------------
******
Example ******
See
example for the routine c3c_approx.
***>>
c3c_arc_angle <<***
******
Summary ******
#include
<c3cdefs.h>
BOOLEAN
c3c_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 ******
------------------------------------------------------------------------------
|
C3_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
<c3cdefs.h>
void pr_arc_angle
( arc, parm )
C3_CURVE
arc ;
PARM
parm ;
{
REAL angle;
if ( c3c_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.
***>>
c3c_arc_parm <<***
******
Summary ******
#include
<c3cdefs.h>
BOOLEAN
c3c_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 ******
------------------------------------------------------------------------------
|
C3_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
<c3cdefs.h>
void
pr_arc_parm ( arc, angle )
C3_CURVE
arc ;
REAL
angle ;
{
PARM_S parm_s;
PARM parm = &parm_s;
if ( c3c_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.
@NEWPAGE
=
***>>
c3c_closed <<***
******
Summary ******
#include
<c3cdefs.h>
BOOLEAN
c3c_closed ( curve );
******
Description ******
This
function determines if a curve forms a closed loop, i.e. its start and
end
points are coincident.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a 3D curve |
------------------------------------------------------------------------------
******
Return Value ******
This
function returns TRUE if the curve is closed.
Otherwise it returns
FALSE.
******
Example ******
#include
<c3cdefs.h>
void
check_closed ( curve )
C3_CURVE
curve ;
{
if ( c3c_closed ( curve ) )
printf ( "The curve is
closed.\n" ) ;
else
printf ( "The curve is not
closed.\n" ) ;
}
This
routine checks if a given curve is closed, and prints out an
appropriate
message.
@NEWPAGE
=
***>>
c3c_curves_plane <<***
******
Summary ******
#include
<c3cdefs.h>
BOOLEAN
c3c_curves_plane ( curvelist, normal,
dist_ptr, status_ptr );
******
Description ******
This
function computes the normal vector and distance from the origin of the
plane
in which a set of curves lie. If the
curves are not on a plane, FALSE
is
returned.
******
Input ******
------------------------------------------------------------------------------
|
DML_LIST | curvelist | a list of curves |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | normal | the normal vector of the |
| | | plane that the curves
lie on |
------------------------------------------------------------------------------
| REAL
* | dist_ptr | the distance from the origin |
| | | to the plane along
the |
| | | normal direction |
------------------------------------------------------------------------------
|
C3_PLANE_STATUS * | status_ptr | status of plane computation; |
| | | may be NULL |
------------------------------------------------------------------------------
The
argument status will be set to one of the
following values when this
routine
returns:
______________________________________________________________________________
| Value | Meaning |
|----------------------------------------------------------------------------|
|
C3_PLANE_DET |
the curves determine a plane |
|
C3_PLANE_OVER_DET |
the curves are not planar |
|
C3_PLANE_UNDER_DET |
the curves do not determine a |
| | unique
plane |
------------------------------------------------------------------------------
******
Return Value ******
This
function returns TRUE if the computation was successful. Otherwise it
returns
FALSE.
******
Example ******
#include
<c3cdefs.h>
void
print_plane ( curves )
DML_LIST
curves ;
{
PT3 n;
REAL d;
C3_PLANE_STATUS status;
if ( !c3c_curves_plane ( curves, n,
&d, &status ) )
printf ( "Curves are not in one
plane.\n" ) ;
else
printf ( "normal dist: %lf %lf
%lf %lf\n",
PT3_X(n), PT3_Y(n), PT3_Z(n),
d );
}
This
routine prints out the normal vector and distance from the origin of
the
plane in which a set of curves lie.
@NEWPAGE
=
***>>
c3c_ept0 <<***
******
Summary ******
#include
<c3cdefs.h>
BOOLEAN
c3c_ept0 ( curve, pt );
******
Description ******
This
function evaluates the start point of a curve.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a curve |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | pt | the start point of the
input |
| | | curve |
------------------------------------------------------------------------------
******
Return Value ******
This
function returns TRUE if the computation was
successful. Otherwise it
returns
FALSE.
******
Example ******
#define
SPLINE
#include
<c3ddefs.h>
#include
<c3cdefs.h>
void
spline4_ept0 ( a, ept0 )
PT3 *a
; /* four point array */
PT3
ept0 ;
{
C3_CURVE curve ;
curve = c3d_spline ( a, 4 );
if ( !c3c_ept0 ( curve, ept0 ) )
printf ( "Evaluation
failed.\n" ) ;
c3d_free_curve ( curve ) ;
}
This
routine creates a spline passing through four given points, and then
computes
the start point of this curve.
@NEWPAGE
=
***>>
c3c_ept1 <<***
******
Summary ******
#include
<c3cdefs.h>
BOOLEAN
c3c_ept1 ( curve, pt );
******
Description ******
This
function evaluates the end point of a curve.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a 3D curve |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | pt | the end point of the
curve |
------------------------------------------------------------------------------
******
Return Value ******
This
function returns TRUE if the computation was
successful. Otherwise it
returns
FALSE.
******
Example ******
#define
SPLINE
#include
<c3ddefs.h>
#include
<c3cdefs.h>
void
spline4_ept1 ( a, ept1 )
PT3 *a
; /* four point array */
PT3
ept1 ;
{
C3_CURVE curve ;
curve = c3d_spline ( a, 4 ) ;
if ( !c3c_ept1 ( curve, ept1 ) )
printf ( "Evaluation
failed.\n" ) ;
c3d_free_curve ( curve ) ;
}
This
routine creates a spline with four through points, and then computes
the end
point of this curve.
@NEWPAGE
=
***>>
c3c_ept_tan0 <<***
******
Summary ******
#include
<c3cdefs.h>
BOOLEAN
c3c_ept_tan0 ( curve, pt, tan_vec );
******
Description ******
This
function evaluates the coordinate and the tangent vector at the start
point
of a curve.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a 3D curve |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | pt | the start point of the |
| | | curve; if this argument
is |
| | | NULL, the start point is |
| | | not computed |
------------------------------------------------------------------------------
|
PT3 | tan_vec | the start tangent of the |
| | | curve; if this argument
is |
| | | NULL, the start tangent is |
| |
| not computed |
------------------------------------------------------------------------------
******
Return Value ******
This
function returns TRUE if the computation was
successful. Otherwise it
returns
FALSE.
******
Example ******
#define
SPLINE
#include
<c3cdefs.h>
void
spline4_ept_tan0 ( a, pt0, tan0 )
PT3 *a
; /* four point array */
PT3
pt0, tan0 ;
{
C3_CURVE curve ;
curve = c3d_spline ( a, 4 ) ;
if ( !c3c_ept_tan0 ( curve, pt0, tan0 ) )
printf ( "Evaluation
failed.\n" ) ;
c3d_free_curve ( curve ) ;
}
This
routine creates a spline passing through four given points, and then
computes
its start point and the tangent vector at this point.
@NEWPAGE
=
***>>
c3c_ept_tan1 <<***
******
Summary ******
#include
<c3cdefs.h>
BOOLEAN
c3c_ept_tan1 ( curve, pt, tan_vec );
******
Description ******
This
function evaluates the coordinates and the tangent vector at the end
point
of a curve.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a 3D curve |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | pt | the end point of the
curve; |
| | | if this argument is
NULL, |
| | | the end point is not |
| | | computed |
------------------------------------------------------------------------------
|
PT3 | tan_vec
| the end tangent of the |
| | | curve; if this argument
is |
| | | NULL, the end tangent is |
| | | not computed |
------------------------------------------------------------------------------
******
Return Value ******
This
function returns TRUE if the computation was
successful. Otherwise it
returns
FALSE.
******
Example ******
#define
SPLINE
#include
<c3ddefs.h>
#include
<c3cdefs.h>
void
spline4_ept_tan1 ( a, pt1, tan1 )
PT3 *a;
PT3
pt1, tan1 ;
{
C3_CURVE curve ;
curve = c3d_spline ( a, 4 );
if ( !c3c_ept_tan1 ( curve, pt1, tan1 ) )
printf ( "Evaluation
failed.\n" ) ;
c3d_free_curve ( curve ) ;
}
This
routine creates a spline with four through points, and then computes
its end
point and the tangent vector at this point.
@NEWPAGE
=
***>>
c3c_etan0 <<***
******
Summary ******
#include
<c3cdefs.h>
BOOLEAN
c3c_etan0 ( curve, tan_vec );
******
Description ******
This
function evaluates the start tangent vector of a curve. This vector is
not
necessarily a unit vector.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a 3D curve |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | tan_vec | the start tangent of the |
| | | curve |
------------------------------------------------------------------------------
******
Return Value ******
This
function returns TRUE if the computation was
successful. Otherwise it
returns
FALSE.
******
Example ******
#define
SPLINE
#include
<c3ddefs.h>
#include
<c3cdefs.h>
void
spline4_tan0 ( a, tan0 )
PT3 *a
; /* four point array */
PT3
tan0 ;
{
C3_CURVE curve ;
curve = c3d_spline ( a, 4 ) ;
if ( !c3c_etan0 ( curve, tan0 ) )
printf ( "Evaluation
failed.\n" ) ;
c3d_free_curve ( curve ) ;
}
This routine
creates a spline with four through points, and
then computes
tangent
vector at the start point of this curve.
@NEWPAGE
=
***>>
c3c_etan1 <<***
******
Summary ******
#include
<c3cdefs.h>
BOOLEAN
c3c_etan1 ( curve, tan_vec );
******
Description ******
This
function evaluates the end tangent vector of a
curve. This vector is
not
necessarily a unit vector.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve
| a 3D curve |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
| PT3 | tan_vec | the end tangent of the
curve |
------------------------------------------------------------------------------
******
Return Value ******
This
function returns TRUE if the computation was
successful. Otherwise it
returns
FALSE.
******
Example ******
#define
SPLINE
#include
<c3ddefs.h>
#include
<c3cdefs.h>
void
spline4_tan1 ( a, tan1 )
PT3 *a
; /* four point array */
PT3
tan1 ;
{
C3_CURVE curve ;
curve = c3d_spline ( a, 4 ) ;
if ( !c3c_etan1 ( curve, tan1 ) )
printf ( "Evaluation
failed.\n" ) ;
c3d_free_curve ( curve ) ;
}
This
routine creates a spline with four through points, and then computes
tangent
vector at the end point of this curve.
@NEWPAGE
=
***>>
c3c_eval <<***
******
Summary ******
#include
<c3cdefs.h>
BOOLEAN
c3c_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 the
Newton-Raphson
method.
******
Input ******
------------------------------------------------------------------------------
| C3_CURVE | curve | a 3D curve |
------------------------------------------------------------------------------
|
PARM | parm | the parameter specifying
the |
| | |
location on the curve where |
| | | the evaluation should
be |
| | | performed |
------------------------------------------------------------------------------
|
INT | p | the maximun
derivative |
| | | order; 0 means compute
the |
| | | coordinates of the
point |
| | | only; 1 means compute
the |
| | | coordinates and the first
|
| | | derivative |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | x[0] | the point on the curve |
------------------------------------------------------------------------------
|
PT3 |
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
<c3ddefs.h>
#include
<c3cdefs.h>
void
spline4_mid_pt ( a, mid_pt )
PT3 *a
; /* four point array */
PT3
mid_pt[3] ;
{
PARM_S parm ;
C3_CURVE curve ;
curve = c3d_spline ( a, 4 ) ;
PARM_SET ( 0.5 * C3_CURVE_T1(curve),
&parm ) ;
if ( !c3c_eval ( curve, &parm, 2,
mid_pt ) )
printf ( "Evaluation
failed.\n" ) ;
c3d_free_curve ( curve ) ;
}
This
routine creates a spline that passes through four points. Then
it
computes
the midpoint of the spline, as well as the first and second
derivatives
at that point.
@NEWPAGE
=
***>>
c3c_eval_pt <<***
******
Summary ******
#include
<c3cdefs.h>
BOOLEAN
c3c_eval_pt ( curve, parm, pt );
******
Description ******
This
routine evaluates the point on a curve corresponding to a curve
parameter
record.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a 3D curve |
------------------------------------------------------------------------------
|
PARM | parm | the curve parameter |
| | | specifying the location
of |
| | | the point on the
curve |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | pt | the point on the curve
|
| | | corresponding to the
curve |
| | | parameter |
------------------------------------------------------------------------------
******
Return Value ******
This
function returns TRUE if the computation was
successful. Otherwise it
returns
FALSE.
******
Example ******
#define
SPLINE
#include
<c3ddefs.h>
#include
<c3cdefs.h>
void
spline4_mid_pt ( a, mid_pt )
PT3 *a
; /* four point array */
PT3
mid_pt ;
{
PARM_S parm ;
C3_CURVE curve ;
curve = c3d_spline ( a, 4 ) ;
PARM_SET ( 0.5 * C3_CURVE_T1(curve),
&parm ) ;
if ( !c3c_eval_pt ( curve, &parm,
mid_pt ) )
printf ( "Evaluation failed.\n"
) ;
c3d_free_curve ( curve ) ;
}
This
routine creates a spline passing through four points, and then computes
midpoint
of this curve.
@NEWPAGE
=
***>>
c3c_eval_pt_tan <<***
******
Summary ******
#include
<c3cdefs.h>
BOOLEAN
c3c_eval_pt_tan ( curve, parm, pt,
tan_vec );
******
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 ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a 3D curve |
------------------------------------------------------------------------------
|
PARM | parm | a curve parameter record |
| | | specifying the
location on |
| | | the curve where the |
| | | evaluation should
be |
| | | performed |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | pt | the point on the curve |
| | | corresponding to the
curve |
| | | parameter record; if this |
| | | argument is NULL, the
point |
| | | is not computed |
------------------------------------------------------------------------------
|
PT3 | tan_vec | 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 ******
#define
SPLINE
#include
<c3ddefs.h>
#include
<c3cdefs.h>
void
spline4_mid_pt_tan ( a, mid_pt, mid_tan )
PT3 *a ;
/* four point array */
PT3
mid_pt, mid_tan ;
{
PARM_S parm ;
C3_CURVE curve ;
curve = c3d_spline ( a, 4 ) ;
PARM_SET ( 0.5 * C3_CURVE_T1(curve),
&parm ) ;
if ( !c3c_eval_pt_tan ( curve, &parm,
mid_pt, mid_tan ) )
printf ( "Evaluation failed.\n"
) ;
c3d_free_curve ( curve ) ;
}
This
routine creates a spline passing through four points, and then computes
the
coordinates of, and tangent vector at, its midpoint.
@NEWPAGE
=
***>>
c3c_eval_tan <<***
******
Summary ******
#include
<c3cdefs.h>
BOOLEAN
c3c_eval_tan ( curve, parm, tan_vec );
******
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 ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a 3D curve |
------------------------------------------------------------------------------
|
PARM | parm | a curve parameter record |
| | | specifying the
location on |
| | | the curve at which
to |
| | | evaluate the tangent
vector |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | tan_vec | 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 ******
#define
SPLINE
#include
<c3ddefs.h>
#include
<c3cdefs.h>
void
spline4_mid_tan ( a, mid_tan )
PT3 *a
; /* four point array */
PT3
mid_tan ;
{
PARM_S parm ;
C3_CURVE curve ;
curve = c3d_spline ( a, 4 ) ;
PARM_SET ( 0.5 * C3_CURVE_T1(curve),
&parm ) ;
if ( !c3c_eval_tan ( curve, &parm,
mid_tan ) )
printf ( "Evaluation
failed.\n" ) ;
c3d_free_curve ( curve ) ;
}
This
routine creates a spline with four through points, and then computes
the
tangent vector at the midpoint of this curve.
***>>
c3c_get_arc_center <<***
******
Summary ******
#include
<c3cdefs.h>
BOOLEAN
c3c_get_arc_center ( curve, ctr ) ;
******
Description ******
This
function evaluates the center point of an arc. The input curve must be
an arc.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | an arc |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | 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
<c3cdefs.h>
void
pr_arc_ctr ( arc )
C3_CURVE
arc ;
{
PT3 c ;
if ( c3c_get_arc_center ( arc, c ) )
printf ( "Center at %lf, %lf,
%lf\n",
PT3_X(c), PT3_Y(c), PT3_Z(c) )
;
else printf ( "Curve is not an
arc\n" ) ;
}
This
subroutine prints the coordinates of the center of an arc.
***>>
c3c_get_arc_data <<***
******
Summary ******
#include
<c3cdefs.h>
BOOLEAN
c3c_get_arc_data ( curve, ctr, rad_ptr,
normal, sweep_ptr ) ;
******
Description ******
This
routine evaluates the center, radius, normal vector and sweep. The
input
curve must be an arc.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | an arc |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | ctr | the center of the arc;
not |
| | | computed if NULL |
------------------------------------------------------------------------------
|
REAL* | rad_ptr | the radius of the arc; not |
| | | computed if NULL |
------------------------------------------------------------------------------
|
PT3 | normal | the normal vector of the |
| | | plane of the arc; not |
| | | computed if NULL |
------------------------------------------------------------------------------
| REAL
* | sweep_ptr | the sweep of the arc; not |
| | | computed if NULL |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is TRUE if the input curve is an arc; it is FALSE
otherwise.
******
Example ******
#include
<c3cdefs.h>
void
print_arc_data ( arc )
C3_CURVE
arc ;
{
PT3 c, n ;
REAL radius, sweep ;
if ( c3c_get_arc_data ( arc, c,
&radius,
n, &sweep ) ) {
printf ( "center: %lf, %lf,
%lf\n",
PT3_X(c), PT3_Y(c), PT3_Z(c) )
;
printf ( "radius %lf\n",
radius ) ;
printf ( "normal: %lf, %lf,
%lf\n",
PT3_X(n), PT3_Y(n), PT3_Z(n) )
;
printf ( "sweep %lf\n",
sweep ) ;
}
else printf ( "Curve is not an arc\n"
) ;
}
***>>
c3c_get_arc_radius <<***
******
Summary ******
#include
<c3cdefs.h>
BOOLEAN
c3c_get_arc_radius ( curve, rad_ptr ) ;
******
Description ******
This
function evaluates the radius of an arc.
******
Input ******
------------------------------------------------------------------------------
|
C3_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
<c3cdefs.h>
void
pr_arc_radius ( arc )
C3_CURVE
arc ;
{
REAL radius ;
if ( c3c_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.
***>>
c3c_get_arc_sweep <<***
******
Summary ******
#include
<c3cdefs.h>
BOOLEAN
c3c_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 ******
------------------------------------------------------------------------------
|
C3_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.
@HEADIOG
= Example
#include
<c3cdefs.h>
void
pr_arc_sweep ( arc )
C3_CURVE
arc ;
{
REAL sweep ;
if ( c3c_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).
***>>
c3c_get_ellipse_data <<***
******
Summary ******
#include
<c3cdefs.h>
BOOLEAN
c3c_get_ellipse_data ( curve, ctr,
major_axis, minor_axis );
******
Description ******
This
function computes the center, the major and minor axis vectors.
All
source code of programs that call this function must be compiled with
the
symbol SPLINE defined.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | an ellipse |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | ctr | the center of the
ellipse |
------------------------------------------------------------------------------
|
PT3 | major_axis, | the major and minor axes |
| | minor_axis | vectors |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is TRUE if the input curve is an ellipse; it is FALSE
otherwise.
******
Example ******
#define
SPLINE
#include
<c3cdefs.h>
void
print_ellipse ( ellipse )
C3_CURVE
ellipse ;
{
PT3 c, u, v ;
if ( c3c_get_ellipse_data ( ellipse, c, u,
v ) ) {
printf ( "center %lf %lf
%lf\n",
PT3_X(c), PT3_Y(c), PT3_Z(c) )
;
printf ( "major axis: %lf %lf
%lf\n",
PT3_X(u), PT3_Y(u), PT3_Z(u) )
;
printf ( "minor axis: %lf %lf
%lf\n",
PT3_X(v), PT3_Y(v), PT3_Z(v) )
;
}
else
printf ( "the curve is not an
ellipse\n" ) ;
}
This
function prints information about an ellipse.
***>>
c3c_get_pcurve_data <<***
******
Summary ******
#include
<c3cdefs.h>
BOOLEAN
c3c_get_pcurve_data ( curve, i, is_arc, ctr,
ept1, rad_ptr, normal,
sweep_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 normal vector, and the sweep are computed in
addition
to the end point. The sweep angle is expressed
in radians.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a polycurve |
------------------------------------------------------------------------------
|
INT | i | the index of the segment
to |
| | | query; the index i |
| | | corresponds to the first |
| | | segment |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | ctr | the center point of the
ith |
| | | segment, if it is an arc; |
| | | may be NULL |
------------------------------------------------------------------------------
|
PT3 | 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 |
------------------------------------------------------------------------------
|
PT3 | normal | the normal vector of the |
| | | plane of the 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 |
------------------------------------------------------------------------------
******
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
<c3cdefs.h>
void
print_pcurve ( pcurve )
C3_CURVE
pcurve ;
{
INT i,
dir ;
BOOLEAN
is_arc ;
PT3
ctr, ept1, n ;
REAL
rad, sweep ;
BOOLEAN
more;
c3c_ept0 ( pcurve, ept1 );
printf ( "x: %lf y: %lf
z: %lf\n", PT3_X(ept1),
PT3_Y(ept1), PT3_Z(ept1) );
i = 0;
do
{
more = c3c_get_pcurve_data ( pcurve,
i, &is_arc, ctr,
ept1, &rad, n, &sweep
);
if ( is_arc == TRUE )
printf ( "arc
segment\n" );
printf ( "x: %lf y: %lf
z: %lf\n", PT3_X(ept1),
PT3_Y(ept1), PT3_Z(ept1) );
i++;
}
while ( more == TRUE );
}
This
program computes information about a polycurve.
@NEWPAGE
=
***>>
c3c_info_curve <<***
******
Summary ******
#include
<c3cdefs.h>
void
c3c_info_curve ( curve, outfile );
******
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 ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a 3D curve |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
| FILE
* | outfile | output file |
------------------------------------------------------------------------------
******
Example ******
#include
<c3cdefs.h>
void
curves_list_info ( curves_list )
DML_LIST
curves_list ;
{
DML_ITEM item ;
C3_CURVE curve ;
DML_WALK_LIST ( curves_list, item ) {
curve = ( C3_CURVE ) DML_RECORD (
item ) ;
c3c_info_curve ( curve, NULL ) ;
}
}
This
routine prints out information about the curves on the list onto the
screen.
@NEWPAGE
=
***>>
c3c_length <<***
******
Summary ******
#include
<c3cdefs.h>
REAL
c3c_length ( curve );
******
Description ******
This
function computes the length of a curve.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a 3D curve |
------------------------------------------------------------------------------
******
Return Value ******
The
return value of this function is the length of the input curve.
******
Example ******
#include
<c3cdefs.h>
REAL
curves_length ( curves_list )
DML_LIST
curves_list ;
{
REAL length ;
DML_ITEM item ;
C3_CURVE curve ;
length = 0.0 ;
DML_WALK_LIST ( curves_list, item ) {
curve = (C3_CURVE) DML_RECORD(item)
;
length += c3c_length ( curve ) ;
}
RETURN ( length ) ;
}
Given a
list of curves, this routine computes the total length of all the
curves
on this list.
@NEWPAGE
=
***>>
c3c_mirror <<***
******
Summary ******
#include
<c3cdefs.h>
void
c3c_mirror ( curve, n, d );
******
Description ******
This
function mirrors a 3D curve about a plane. The plane is defined by a
normal
vector and a distance from the origin.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a 3D curve |
------------------------------------------------------------------------------
|
PT3 | n | the normal vector of
the |
| | | mirroring plane |
------------------------------------------------------------------------------
|
REAL | d | the normal distance
between |
| | | the plane and the origin
|
------------------------------------------------------------------------------
******
Example ******
#include
<c3cdefs.h>
void
mirror_curve ( curve )
C3_CURVE
curve ;
{
REAL dist ;
PT3 normal ;
printf ( "Enter normal vector and
" );
printf ( "distance of the mirror plane\n"
) ;
scanf ( "%lf%lf%lf%lf", normal,
normal+1,
normal+2, &dist ) ;
c3c_mirror ( curve, normal, dist ) ;
}
This
subroutine constructs a curve which is a mirror image of the input curve
with
respect to the given plane.
@NEWPAGE
=
***>>
c3c_on_plane <<***
******
Summary ******
#include
<c3cdefs.h>
BOOLEAN
c3c_on_plane ( curve, normal, dist );
******
Description ******
This
function determines if a 3D curve is on a plane.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a curve |
------------------------------------------------------------------------------
|
PT3 | normal | the normal vector of the |
| | | plane |
------------------------------------------------------------------------------
|
REAL | dist | the distance from the
origin |
| | | to the plane along
the |
| | | normal direction |
------------------------------------------------------------------------------
******
Return Value ******
This
function returns TRUE if the curve lies on the plane. Otherwise it
returns
FALSE.
******
Example ******
#include
<dmldefs.h>
#include
<c3cdefs.h>
void
print_on_plane ( curves, n, d )
DML_LIST
curves ;
PT3 n;
REAL d;
{
C3_CURVE curve;
DML_ITEM item;
DML_WALK_LIST ( curves, item ) {
curve = dml_record ( item );
if ( !c3c_on_plane ( curve, n, d ) )
printf ( "Curve is not on
plane.\n" ) ;
else
printf ( "Curve is on
plane\n" );
}
}
***>>
c3c_plane <<***
******
Summary ******
#include
<c3cdefs.h>
BOOLEAN
c3c_plane ( curve, normal, dist_ptr,
status );
******
Description ******
This
function computes the normal vector and distance from the origin of the
plane
in which a curve lies. If the curve is
not planar, or it is a line,
FALSE
is returned.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a curve |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | normal | the normal vector of the |
| | | plane that the curve
lies in |
| | | |
------------------------------------------------------------------------------
| REAL
* | dist_ptr | the distance from the origin |
| | | to the plane along
the |
| | | normal direction
|
------------------------------------------------------------------------------
|
C3_PLANE_STATUS * | status | status of plane
computation; |
| | | may be NULL |
------------------------------------------------------------------------------
If the
argument status is not NULL, it will be
set to one of the following
values
when this routine returns:
______________________________________________________________________________
|
Value |
Meaning |
|----------------------------------------------------------------------------|
|
C3_PLANE_DET |
the curve determines a plane |
|
C3_PLANE_OVER_DET |
the curve is not planar |
|
C3_PLANE_UNDER_DET |
the curve does not determine a |
| | unique
plane |
------------------------------------------------------------------------------
******
Return Value ******
This
function returns TRUE if the curve lies in a plane. Otherwise it
returns
FALSE.
******
Example ******
#include
<c3cdefs.h>
void
print_plane ( curve )
C3_CURVE
curve;
{
PT3 n;
REAL d;
C3_PLANE_STATUS status;
if ( !c3c_plane ( curve, n, &d,
&status ) )
printf ( "Curve is not
planar.\n" ) ;
else
printf ( "normal dist: %lf %lf
%lf %lf\n",
PT3_X(n), PT3_Y(n), PT3_Z(n),
d );
}
This
routine prints out the normal vector and distance from the origin of
the
plane in which a curve lies.
@NEWPAGE
=
***>>
c3c_project <<***
******
Summary ******
#include
<c3cdefs.h>
BOOLEAN
c3c_project ( curve, pt, parm, pt_on_curve );
******
Description ******
This
function computes the orthogonal projection of a 3D point onto a 3D
curve.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a 3D curve |
------------------------------------------------------------------------------
|
PT3 | pt | the point to be
projected |
| | | onto the curve |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PARM | parm | the address of the curve |
| | | parameter record |
| | | corresponding to
the |
| | | orthogonal projection of pt
|
| | | on the curve |
------------------------------------------------------------------------------
|
PT3 |
pt_on_curve | the coordinates of
the |
| | | projection of point pt
on |
| | | the curve; may be
NULL |
------------------------------------------------------------------------------
******
Return Value ******
This
function returns TRUE if the computation was
successful. Otherwise it
returns
FALSE.
******
Example ******
#include
<c3cdefs.h>
#include
<c3vdefs.h>
void
projection_point ( curve, pt )
C3_CURVE
curve ;
PT3 pt
;
{
PARM_S parm ;
PT3 prj_pt ;
if ( c3c_project ( curve, pt, &parm,
prj_pt ) ) {
printf ( "Projection point is
%lf %lf %lf .\n",
PT3_X(prj_pt), PT3_Y(prj_pt),
PT3_Z(prj_pt) ) ;
if ( c3v_ident_pts ( pt, prj_pt ) )
printf ( "The point lies
on the curve.\n" ) ;
}
else
printf ( "Projection
failed.\n" ) ;
}
This
routine projects a point onto a curve.
It also determines if the point
was
orginally on the curve.
@NEWPAGE
=
***>>
c3c_project_normal <<***
******
Summary ******
#include
<c3cdefs.h>
C3_CURVE
c3c_project_normal ( curve, normal, dist );
******
Description ******
This
function projects a curve onto a plane defined by a normal and distance
from
the origin. The direction of projection
is along the normal of the
plane.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | the curve to project;
this |
| | | curve is modified by this |
| | | function; it is planar
on |
| | | output |
------------------------------------------------------------------------------
|
PT3 | normal | the normal vector of the |
| | | plane onto which the
curve |
| | | is projected |
------------------------------------------------------------------------------
|
REAL | dist | the perpendicular
distance |
| | | between the plane and
the |
| | | origin |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the input curve.
******
Example ******
#include
<dmldefs.h>
#include
<c3cdefs.h>
void
project_curves ( list, n, d )
DML_LIST
list;
PT3 n;
REAL d;
{
DML_ITEM item;
C3_CURVE c;
DML_WALK_LIST ( list, item )
{
c = dml_record ( item );
c3c_project_normal ( c, n, d );
}
}
This
function projects a list of curves orthogonally onto a plane.
@NEWPAGE
=
***>>
c3c_project_oblique <<***
******
Summary ******
#include
<c3cdefs.h>
C3_CURVE
c3c_project_oblique ( curve, normal, dist,
direction );
******
Description ******
This
function projects a curve onto a plane defined by a normal and distance
from
the origin. The direction of projection
is along a specified direction.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | the curve to project;
this |
| | | curve is modified by
this |
| | | function; it is planar
on |
| | | output |
------------------------------------------------------------------------------
|
PT3 | normal | the normal vector of the |
| |
| plane onto which the curve |
| | | is projected |
------------------------------------------------------------------------------
|
REAL | dist | the perpendicular distance |
| | | between the plane and
the |
| | | origin |
------------------------------------------------------------------------------
|
PT3 | direction | projection direction |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the input curve if the projection was successful. It is
NULL
otherwise. Two situations where
the projection fails are: (1) when the
normal
of the plane is perpendicular to the
projection direction, and (2)
when an
arc or polycurve with circular segments
are projected to produce
elliptical curves, and the symbol SPLINE has not been
defined to enable
ellipses
and splines.
******
Example ******
#include
<dmldefs.h>
#include
<c3cdefs.h>
void
project_curves ( list, n, d, dir )
DML_LIST
list;
PT3 n;
REAL d;
PT3
dir;
{
DML_ITEM item;
C3_CURVE c;
DML_WALK_LIST ( list, item )
{
c = dml_record ( item );
c3c_project_oblique ( c, n, d, dir
);
}
}
This
function projects a list of curves obliquely onto a plane.
@NEWPAGE
=
***>>
c3c_rotate <<***
******
Summary ******
#include
<c3cdefs.h>
C3_CURVE
c3c_rotate ( curve, origin, axis, angle );
******
Description ******
This
function rotates a curve about an axis.
The axis is defined by an
origin
and an axis vector. The rotation angle
must be specified in radians.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | the curve to rotate; it
is |
| | |
modified by this function |
------------------------------------------------------------------------------
|
PT3 | origin,
axis | the origin and axis
vector |
| | | of the rotation axis |
------------------------------------------------------------------------------
|
REAL | angle | the angle to rotate the |
| | | curve; must be specified
in |
| | | radians |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the input curve.
******
Example ******
#include
<dmldefs.h>
#include
<c3cdefs.h>
void
rotate_curves ( curvelist )
DML_LIST
curvelist;
{
DML_ITEM item;
PT3 o, v;
REAL angle;
C3_CURVE curve;
printf ( "enter axis origin" );
scanf ( "%lf%lf%lf", o, o+1, o+2
);
printf ( "enter axis direction"
);
scanf ( "%lf%lf%lf", v, v+1, v+2
);
printf ( "enter rotation angle"
);
scanf ( "%lf", &angle );
angle *= PI_OVER_180;
DML_WALK_LIST ( curvelist, item )
{
curve = dml_record ( item );
c3c_rotate ( curve, o, v, angle );
}
}
This
function rotates a set of curves on a list.
@NEWPAGE
=
***>>
c3c_rotate_cs <<***
******
Summary ******
#include
<c3cdefs.h>
C3_CURVE
c3c_rotate_cs ( curve, origin, axis, c, s );
******
Description ******
This
function rotates a curve about an axis.
The axis is defined by an
origin
and an axis vector. The rotation angle
is specified with its cosine
and
sine.
By
reusing the sine and cosine values of the rotation angle, this function
rotates
groups of geometry more quickly than
c3c_rotate.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | the curve to rotate; it
is |
| | |
modified by this function |
------------------------------------------------------------------------------
|
PT3 | origin,
axis | the origin and axis
vector |
| | | of the rotation axis |
------------------------------------------------------------------------------
|
REAL | c, s | the cosine and sine of
the |
| | | rotation angle |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the input curve.
******
Example ******
#include
<dmldefs.h>
#include
<c3cdefs.h>
void
rotate_curves ( curvelist )
DML_LIST
curvelist;
{
DML_ITEM item;
PT3 o, v;
REAL angle, s, c;
C3_CURVE curve;
printf ( "enter axis origin" );
scanf ( "%lf%lf%lf", o, o+1, o+2
);
printf ( "enter axis direction"
);
scanf ( "%lf%lf%lf", v, v+1, v+2
);
printf ( "enter rotation angle"
);
scanf ( "%lf", &angle );
angle *= PI_OVER_180;
c = cos ( angle );
s = sin ( angle );
DML_WALK_LIST ( curvelist, item )
{
curve = dml_record ( item );
c3c_rotate_cs ( curve, o, v, c, s );
}
}
This
function rotates a set of curves on a list.
It is more efficient than
the
example for c3c_rotate because the angle is
specified with the sine and
cosine
of the rotation angle.
@NEWPAGE
=
***>>
c3c_scale <<***
******
Summary ******
#include
<c3cdefs.h>
C3_CURVE
c3c_scale ( curve, origin, factor );
******
Description ******
This
function scales a curve by a scale factor. The
center of scaling is the
point
origin.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a 3D curve |
------------------------------------------------------------------------------
|
REAL | factor | the scale factor
|
------------------------------------------------------------------------------
|
PT3 | origin | the center of scaling |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the input curve.
******
Example ******
#include
<c3cdefs.h>
void
scale_curve ( curve )
C3_CURVE
curve ;
{
REAL scale_factor ;
PT3 origin ;
printf ( "Enter scale origin\n"
) ;
scanf ( "%lf%lf%lf", origin,
origin+1, origin+2 ) ;
printf ( "Enter scale factor\n"
) ;
scanf ( "%lf", &scale_factor
) ;
c3c_scale ( curve, origin, scale_factor )
;
}
This
subroutine scales the input curve by a given factor about a given scaling
origin.
@NEWPAGE
=
***>>
c3c_select <<***
******
Summary ******
#include
<c3cdefs.h>
BOOLEAN
c3c_select ( curve, pt, ray_vec, tol,
sel_parm, dist_ptr );
******
Description ******
This
function determines if a ray passes within a specified distance of a
curve. The ray is defined by a point and a vector.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a curve |
------------------------------------------------------------------------------
|
PT3 | pt,
ray_vec | the base point and
the |
| | | vector that define the
ray |
------------------------------------------------------------------------------
|
REAL | tol | the select distance;
this |
| | | function determines if
the |
| |
| ray passes within this |
| | | distance of curve |
------------------------------------------------------------------------------
|
PARM | sel_parm | the curve parameter |
| | | indicating the point on
the |
| | | curve nearest the ray; if |
| | | this argument is NULL, the
|
| | | select parameter is not
|
| | | computed |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PARM | sel_parm | the curve parameter |
| | | indicating the point on
the |
| | | curve nearest the ray |
------------------------------------------------------------------------------
| REAL
* | dist_ptr | the distance between the ray |
| | | and the point on the
curve |
| | | nearest the ray |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is TRUE if the ray passes by the curve within the select
distance. It is FALSE otherwise.
******
Example ******
#include
<dmldefs.h>
#include
<c3cdefs.h>
C3_CURVE
select_curve ( curvelist, dist, p, vec )
DML_LIST
curvelist;
REAL
*dist;
PT3 p,
vec;
{
PARM_S parm;
DML_ITEM item;
C3_CURVE curve;
REAL d;
DML_WALK_LIST ( curvelist, item )
{
curve = dml_record ( item );
if ( c3c_select ( curve, p, vec,
*dist, &parm, &d ) )
break;
}
if ( item != NULL ) {
*dist = d;
return ( curve );
}
else
return ( NULL );
}
This
function returns the first curve on a list which passes within a
specified
distance of a ray.
@NEWPAGE
=
***>>
c3c_transform <<***
******
Summary ******
#include
<c3cdefs.h>
C3_CURVE
c3c_transform ( curve0, t );
******
Description ******
This
function transforms a specified curve by a specified 3D transform.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve0 | a 3D curve |
------------------------------------------------------------------------------
|
C3_TRANSFORM | t | a 3D transform |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the specified curve. If
the curve could not be
transformed,
NULL is returned.
******
Example ******
#include
<c3tdefs.h>
#include
<c3cdefs.h>
void
transform_curve ( curve, c, x, y )
C3_CURVE
curve ;
PT3 c,
x, y;
{
C3_TRANSFORM t;
c3t_lcs ( c, x, y, t );
c3c_transform ( curve, t ) ;
}
This
subroutine transforms a curve into a given local coordinate system.
@NEWPAGE
=
***>>
c3c_translate <<***
******
Summary ******
#include
<c3cdefs.h>
C3_CURVE
c3c_translate ( curve, shift );
******
Description ******
This
function translates a curve by a vector.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a 3D curve |
------------------------------------------------------------------------------
| PT3 | shift | the translation vector |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the input curve.
******
Example ******
#include
<c3vdefs.h>
#include
<c3cdefs.h>
void
move_curve ( curve )
C3_CURVE
curve ;
{
REAL x, y, z ;
PT3 shift ;
printf ( "Enter translation
vector\n" ) ;
scanf ( "%lf%lf%lf", &x,
&y, &z ) ;
c3v_set ( x, y, z, shift ) ;
c3c_translate ( curve, shift ) ;
}
This
subroutine translates a curve by a given translation vector.
@NEWPAGE
=
***>>
c3c_trim <<***
******
Summary ******
#include
<c3cdefs.h>
C3_CURVE
c3c_trim ( curve, parm0, parm1 );
******
Description ******
This
function trims off the portions of a curve outside the interval defined
by two
specified curve parameters.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a 3D curve |
------------------------------------------------------------------------------
|
PARM | parm0,
parm1 | curve parameter
records |
| | | specifying the interval
on |
| | | the curve to keep; if parm0 |
| | | is NULL, the interval
begins |
| | | at the start point of the |
| | | curve; if parm1 is NULL,
the |
| | | interval ends at the end
|
| | | point of the curve |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the input curve.
******
Example ******
#include
<c3cdefs.h>
void
trim_at_points ( pt0, pt1, curve )
PT3
pt0, pt1 ;
C3_CURVE
curve ;
{
PARM_S parm0, parm1 ;
c3c_project ( curve, pt0, &parm0, NULL
) ;
c3c_project ( curve, pt1, &parm1, NULL
) ;
c3c_trim ( curve, &parm0, &parm1 )
;
}
This
program trims off the portion of the input curve outside the interval
between
the projections of two specified points.
@NEWPAGE
=
***>>
c3c_trim0 <<***
******
Summary ******
#include
<c3cdefs.h>
C3_CURVE
c3c_trim0 ( curve, parm );
******
Description ******
This
function trims off the portion of the input curve between the start
point
and the position specified by a curve
parameter record.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a 3D curve |
------------------------------------------------------------------------------
|
PARM | parm | a curve parameter record |
| | | specifying the new position
|
| | | of the start point |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the input curve.
******
Example ******
#include
<c3cdefs.h>
void
trim0_at_point ( pt, curve )
PT3 pt
;
C3_CURVE
curve ;
{
PARM_S parm ;
c3c_project ( curve, pt, &parm, NULL )
;
c3c_trim0 ( curve, &parm ) ;
}
This
program trims off the portion of the input curve between the start
point
and the projection of the given point
onto the curve.
@NEWPAGE
=
***>>
c3c_trim1 <<***
******
Summary ******
#include
<c3cdefs.h>
C3_CURVE
c3c_trim1 ( curve, parm );
******
Description ******
This
function trims off the portion of the input curve between the endpoint
and the
position specified by a curve parameter
record.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a 3D curve
|
------------------------------------------------------------------------------
|
PARM | parm | a curve parameter record |
| | | specifying the new position
|
| | | of the end point |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the input curve.
******
Example ******
#include
<c3cdefs.h>
void
trim1_at_point ( pt, curve )
PT3 pt
;
C3_CURVE
curve ;
{
PARM_S parm ;
c3c_project ( curve, pt, &parm, NULL )
;
c3c_trim1 ( curve, &parm ) ;
}
This
program trims off the portion of the input curve between the end point
and the
projection of the given point onto the
curve.
***>>
c3c_trim_t <<***
******
Summary ******
#include
<c3cdefs.h>
C3_CURVE
c3c_trim_t ( curve, t0, t1 );
******
Description ******
This
function trims off the portions of a curve outside the interval defined
by two
specified curve parameter values.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a 3D curve |
------------------------------------------------------------------------------
|
REAL | t0, t1 | curve parameter values |
| | | specifying the interval on |
| | | the curve to keep |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the input curve.
******
Example ******
#include
<c3cdefs.h>
void
trim_off_ends ( curve )
C3_CURVE
curve ;
{
c3c_trim_t ( curve, 0.3, 0.8 ) ;
}
This
program trims off the portion of the input curve outside the interval
between
the parameter values 0.3 and 0.8.
***>>
c3c_trim_t0 <<***
******
Summary ******
#include
<c3cdefs.h>
C3_CURVE
c3c_trim_t0 ( curve, t );
******
Description ******
This
function trims off the portion of the input curve between the start
point
and the position specified by a curve
parameter values.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | C3_CURVE | curve |
------------------------------------------------------------------------------
@T3C3 =
a 3D curve
------------------------------------------------------------------------------
|
REAL | t | a curve parameter
value |
| | | specifying the new position
|
| | | of the start point |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the input curve.
******
Example ******
#include
<c3cdefs.h>
void
trim_off_start ( curve )
C3_CURVE
curve ;
{
c3c_trim_t0 ( curve, 0.3 ) ;
}
This
program trims off the portion of the input curve between the start
point
and the parameter value 0.3.
@NEWPAGE
=
***>>
c3c_trim_t1 <<***
******
Summary ******
#include
<c3cdefs.h>
C3_CURVE
c3c_trim_t1 ( curve, t );
******
Description ******
This
function trims off the portion of the input curve between the endpoint
and the
position specified by a curve parameter
value.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a 3D curve |
------------------------------------------------------------------------------
|
REAL | t | a curve parameter
value |
| | | specifying the new position
|
| | | of the end point |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the input curve.
******
Example ******
#include
<c3cdefs.h>
void
trim1_off_end ( curve )
C3_CURVE
curve ;
{
c3c_trim_t1 ( curve, 0.8 ) ;
}
This
program trims off the portion of the input curve between the parameter
value
0.8 and the end point of the curve.
***>>
c3d_arc_2pts_ctr <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_arc_2pts_ctr ( pt0, pt1, ctr );
******
Description ******
This
function constructs a 3D arc starting at a specified point, ending at
another
specified point, and having a specified center.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | pt0, pt1,
ctr | the start, end and
center |
| | | points of the arc |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the constructed curve.
If the curve could not be
constructed,
NULL is returned.
******
Example ******
#include
<c3ddefs.h>
C3_CURVE
build_arc()
{
PT3 ctr, p1, p2;
printf ( "enter center:" );
scanf ( "%lf%lf%lf", ctr, ctr+1,
ctr+2 );
printf ( "enter start point:" );
scanf ( "%lf%lf%lf", p1, p1+1,
p1+2 );
printf ( "enter end point:" );
scanf ( "%lf%lf%lf", p2, p2+1,
p2+2 );
return ( c3d_arc_2pts_ctr ( p1, p2, ctr )
);
}
This
function constructs an arc from a center point, start point and end
point.
***>>
c3d_arc_2pts_tan <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_arc_2pts_tan ( pt0, tan0, pt1 );
******
Description ******
This
function constructs a 3D arc which starts at a specified point, ends at
another
specified point, and has a specified start tangent.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | pt0, tan0,
pt1 | the start point, the
start |
| | | tangent, and end
point |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the constructed curve.
If the curve could not be
constructed,
NULL is returned.
******
Example ******
#include
<c3ddefs.h>
C3_CURVE
build_arc()
{
PT3 tan, p1, p2;
printf ( "enter start tangent:"
);
scanf ( "%lf%lf%lf", tan, tan+1,
tan+2 );
printf ( "enter start point:" );
scanf ( "%lf%lf%lf", p1, p1+1,
p1+2 );
printf ( "enter end point:" );
scanf ( "%lf%lf%lf", p2, p2+1,
p2+2 );
return ( c3d_arc_2pts_tan ( p1, tan, p2 )
);
}
This
function constructs an arc from a start tangent, start point and end
point.
***>>
c3d_arc_3pts <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_arc_3pts ( pt1, pt2, pt3 );
******
Description ******
This function
constructs a 3D arc passing through three points.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | pt1, pt2,
pt3 | three points |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the constructed curve.
If the curve could not be
constructed,
NULL is returned.
******
Example ******
#include
<c3ddefs.h>
C3_CURVE
build_arc()
{
PT3 p1, p2, p3;
printf ( "enter first point:" );
scanf ( "%lf%lf%lf", p1, p1+1,
p1+2 );
printf ( "enter second point:"
);
scanf ( "%lf%lf%lf", p2, p2+1,
p2+2 );
printf ( "enter third point:" );
scanf ( "%lf%lf%lf", p3, p3+1,
p3+2 );
return ( c3d_arc_3pts ( p1, p2, p3 ) );
}
This
function constructs an arc from three points.
***>>
c3d_circle <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_circle ( ctr, rad, normal );
******
Description ******
This
function constructs a 3D circle with a specified center and radius.
The
plane of the circle is specified with a normal vector.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | ctr,
normal | the center point and
the |
| | | plane normal |
------------------------------------------------------------------------------
|
REAL | rad | the radius |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the constructed curve.
If the curve could not be
constructed,
NULL is returned.
******
Example ******
#include
<c3ddefs.h>
C3_CURVE
build_circle()
{
PT3 ctr, n;
REAL r;
printf ( "enter center: ");
scanf ( "%lf%lf%lf", ctr, ctr+1,
ctr+2 );
printf ( "enter radius" );
scanf ( "%lf", &r );
printf ( "enter plane normal: "
);
scanf ( "%lf%lf%lf", n, n+1, n+2
);
return ( c3d_circle ( ctr, r, n ) );
}
This
function constructs a circle from a center point, radius and plane
normal.
***>>
c3d_convert_2d3d <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_convert_2d3d ( curve_2d, c, u, v );
******
Description ******
This
function creates a 3D curve by placing a 2D curve on the x-y plane of a
local
coordinate system in 3D space. The
local coordinate system is defined
by an
origin, an x-axis, and a y-axis, all defined
in the 3D space.
******
Input ******
------------------------------------------------------------------------------
|
C2_CURVE | curve_2d | a 2D curve |
------------------------------------------------------------------------------
|
PT3 | c, u, v | the origin, x-axis and |
| | | y-axis of the local |
| | | coordinate system |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is a 3D curve. If the
curve could not be created, NULL is
returned.
******
Example ******
#include
<dmldefs.h>
#include
<c3ddefs.h>
void
convert_curves ( in, out, o, x, y )
DML_LIST
in, out;
PT3 o,
x, y;
{
DML_ITEM item;
C2_CURVE c2;
C3_CURVE c3;
DML_WALK_LIST ( in, item ) {
c2 = dml_record ( item );
c3 = c3d_convert_2d3d ( c2, o, x, y
);
dml_append_data ( out, c3 );
}
}
This
function converts a set of 2D curves into 3D curves.
***>>
c3d_convert_3d2d <<***
******
Summary ******
#include
<c3ddefs.h>
C2_CURVE
c3d_convert_3d2d ( curve_3d, c, u, v );
******
Description ******
This
function creates a 2D curve by projecting a 3D curve onto the x-y plane
of a
local coordinate system in 3D space. The local coordinate system is
defined
by an origin, an x-axis, and a y-axis, all defined in the 3D space.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve_3d | a 3D curve |
------------------------------------------------------------------------------
|
PT3 | c, u, v | the origin, x-axis, and |
| | | y-axis of the local |
| | | coordinate system
|
------------------------------------------------------------------------------
******
Return Value ******
The
return value is a 2D curve. If the
curve could not be created, NULL is
returned.
******
Example ******
#include
<dmldefs.h>
#include
<c3ddefs.h>
void
convert_curves ( in, out, o, x, y )
DML_LIST
in, out;
PT3 o,
x, y;
{
DML_ITEM item;
C3_CURVE c3;
C2_CURVE c2;
DML_WALK_LIST ( in, item ) {
c3 = dml_record ( item );
c2 = c3d_convert_3d2d ( c3, o, x, y
);
dml_append_data ( out, c2 );
}
}
This
function converts a set of 3D curves into 2D curves.
***>>
c3d_copy <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_copy ( curve0 );
******
Description ******
This
function creates a copy of a curve.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve0 | a 3D curve |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the copy. If memory could not be allocated to create the
copy,
NULL is returned.
******
Example ******
#include
<c3ddefs.h>
C3_CURVE
create_copy ( curve )
C3_CURVE
curve ;
{
C3_CURVE copy ;
copy = c3d_copy ( curve ) ;
return ( copy ) ;
}
This
routine creates a copy of a given curve.
***>>
c3d_curve_to_spline <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_curve_to_spline ( curve );
******
Description ******
This
function converts curves into geometrically-identical splines.
All
source code for programs that call this function must be compiled with
the
symbol SPLINE defined.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a curve |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is a curve which is the spline representation of the input
curve. If memory for the spline could not be
allocated, NULL is returned.
******
Example ******
#define
SPLINE
#include
<dmldefs.h>
#include
<c3ddefs.h>
void
convert_curves ( inlist, outlist )
DML_LIST
inlist, outlist;
{
DML_ITEM item;
C3_CURVE curve, spline;
DML_WALK_LIST ( inlist, item )
{
curve = dml_record ( item );
spline = c3d_curve_to_spline ( curve
);
dml_append_data ( outlist, spline );
}
}
This
function creates a set of splines from a set of curves.
***>>
c3d_ellipse <<***
******
Summary ******
#include
<c3ddefs.h>
C2_CURVE
c3d_ellipse ( ctr, major_axis, minor_axis );
******
Description ******
This
function creates an ellipse defined by its center and its major axis
and
minor axis vectors. The major and minor
axes must be orthogonal.
All
source code of programs that call this function must be compiled with
the
symbol SPLINE defined.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | ctr | the center of the
ellipse |
------------------------------------------------------------------------------
|
PT3 | major_axis | the major axis vector; the |
| | | length of this
vector |
| | | specifies the major radius |
| | | of the ellipse |
------------------------------------------------------------------------------
|
PT3 | minor_axis | the minor axis vector; the |
| | | length of this vector |
| | | specifies the minor radius |
| | | of the ellipse |
------------------------------------------------------------------------------
******
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 ()
{
PT3 c, maj_axis, min_axis;
C3_CURVE ellipse ;
c3v_set ( 1.0, 1.0, 2.0, c ) ;
c3v_set ( 5.0, 0.0, 0.0, maj_axis ) ;
c3v_set ( 0.0, 3.0, 0.0, min_axis ) ;
ellipse = c2d_ellipse ( c, maj_axis,
min_axis );
if ( ellipse == NULL ) printf (
"Error creating curve.\n" );
}
This
program creates an ellipse with center (1,1,2), major axis with length
5.0
aligned with the x-axis, and minor axis with length 3.0 aligned with the
y-axis.
***>>
c3d_free_curve <<***
******
Summary ******
#include
<c3ddefs.h>
void
c3d_free_curve ( curve );
******
Description ******
This
function frees a curve.
******
Input ******
------------------------------------------------------------------------------
| C3_CURVE | curve | a 3D curve |
------------------------------------------------------------------------------
******
Example ******
#include
<c3ddefs.h>
#include
<c3cdefs.h>
void
main()
{
C3_CURVE curve ;
PT3 pt0, pt1 ;
curve = c3d_line ( pt0, pt1 ) ;
if ( curve == NULL )
printf ( "Cannot create a
curve.\n" ) ;
else {
c3c_info_curve ( curve, NULL ) ;
c3d_free_curve ( curve ) ;
}
}
This
program creates a line, prints information about this line onto the
screen,
and then frees the memory used by it.
***>>
c3d_free_point <<***
******
Summary ******
#include
<c3ddefs.h>
void
c3d_free_point ( pt );
******
Description ******
This
function frees a point created with c3d_point.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | *pt | a 3D point |
------------------------------------------------------------------------------
******
Example ******
#include
<c3ddefs.h>
void
main()
{
PT3 *p ;
p = c3d_point ( 1.0, 2.0, 3.0 ) ;
c3d_free_point ( p ) ;
}
This
program creates a point, and then frees the memory used by it.
***>>
c3d_line <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_line ( ept0, ept1 );
******
Description ******
This
function creates a line between two points.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | ept0 | the start point of the
line |
------------------------------------------------------------------------------
|
PT3 | 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 copy, NULL is returned.
******
Example ******
#include
<c3vdefs.h>
#include
<c3ddefs.h>
C3_CURVE
create_line ()
{
C3_CURVE line ;
PT3 pt0, pt1 ;
REAL x, y, z ;
printf ( "Enter coordinates of the
first point.\n" ) ;
scanf ( "%lf%lf%lf", &x,
&y, &z ) ;
c3v_set ( x, y, z, pt0 ) ;
printf ( "Enter coordinates of the
second point.\n" );
scanf ( "%lf%lf%lf", &x,
&y, &z ) ;
c3v_set ( x, y, z, pt1 ) ;
line = c3d_line ( pt0, pt1 ) ;
if ( line == NULL )
printf ( "Error creating
line.\n" ) ;
return ( line ) ;
}
This
program creates a line passing through two given points.
***>>
c3d_line_dir <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_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 ******
------------------------------------------------------------------------------
|
PT3 | ept0 | the start point of the
line |
------------------------------------------------------------------------------
|
PT3 | 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
<c3vdefs.h>
#include
<c3ddefs.h>
C3_CURVE
create_line_dir ()
{
C3_CURVE line ;
PT3 pt, dir_vec ;
REAL x, y, z ;
printf ( "Enter start point.\n"
) ;
scanf ( "%lf%lf%lf", &x,
&y, &z ) ;
c3v_set ( x, y, z, pt ) ;
printf ( "Enter direction
vector.\n" ) ;
scanf ( "%lf%lf%lf", &x,
&y, &z ) ;
c3v_set ( x, y, z, dir_vec ) ;
line = c3d_line_dir ( pt, dir_vec ) ;
if ( line == NULL )
printf ( "Error creating
line.\n" ) ;
return ( line ) ;
}
This
program creates a line starting at a given point and having a given
direction.
***>>
c3d_mirror <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_mirror ( curve0, n, d );
******
Description ******
This
function creates a curve which is the mirror image of the input curve
about a
plane. The plane is defined by a normal vector and the distance of
the
plane to the origin.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve0 | a 3D curve
|
------------------------------------------------------------------------------
|
PT3 | n | the normal vector of
the |
| | | plane |
------------------------------------------------------------------------------
|
REAL | d | the normal distance
between |
| | | the plane and the
origin |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is a curve which is the mirror image of the input curve.
If
memory could not be allocated to create the curve, NULL is returned.
******
Example ******
#include
<c3ddefs.h>
C3_CURVE
mirror_curve ( curve )
C3_CURVE
curve ;
{
REAL dist ;
PT3 n ;
C3_CURVE mirrored_curve ;
printf (
"Enter mirror plane normal and
distance\n" );
scanf ( "%lf%lf%lf%lf", n, n+1,
n+2, &dist ) ;
mirrored_curve = c3d_mirror ( curve, n,
dist ) ;
return ( mirrored_curve ) ;
}
This
subroutine creates a curve which is a mirror image of the input curve
with
respect to the user-defined plane.
***>>
c3d_pcurve_add_arc_2pts <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_pcurve_add_arc_2pts ( curve, a0, a1 );
******
Description ******
This
function adds an arc segment to a 3D polycurve. The arc segment is
defined
by three points: the end point of the polycurve, and two additional
points.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a 3D polycurve |
------------------------------------------------------------------------------
|
PT3 | 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
c3d_pcurve_init.
***>>
c3d_pcurve_add_arc_tan <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_pcurve_add_arc_tan ( curve, a );
******
Description ******
This
function adds an arc segment to the end of a 3D polycurve. The
arc is
tangent
to the end of the polycurve, and ends at a specified point.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a 3D polycurve |
------------------------------------------------------------------------------
|
PT3 | 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
c3d_pcurve_init.
***>>
c3d_pcurve_add_line <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_pcurve_add_line ( curve, a );
******
Description ******
This
function adds a line segment to a 3D polycurve. The line segment ends
at a
specified point.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a 3D polycurve |
------------------------------------------------------------------------------
|
PT3 | 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
c3d_pcurve_init.
***>>
c3d_pcurve_add_line_tan <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_pcurve_add_line_tan ( curve, a );
******
Description ******
This
function adds a line segment to the end of a 3D polycurve. The
line
segment
is tangent to the end of the polycurve, and ends at the projection
of a
specified point onto the ray tangent to the end of the polycurve.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a polycurve |
------------------------------------------------------------------------------
|
PT3 | 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
c3d_pcurve_init.
***>>
c3d_pcurve_close <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_pcurve_close ( curve );
******
Description ******
This
function adds a line segment to close a polycurve.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a polycurve |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the polycurve. If the
line could not be constructed,
NULL is
returned.
******
Example ******
See
c3d_pcurve_init.
***>>
c3d_pcurve_init <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_pcurve_init ( a );
******
Description ******
This
function begins a 3D polycurve at a specified point.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | 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
<c3ddefs.h>
C3_CURVE
build_pcurve ( p1, p2, p31, p32, p4,
p5, p6 )
PT3 p1,
p2, p31, p32, p4, p5, p6;
{
C3_CURVE pc;
pc = c3d_pcurve_init ( p1 );
c3d_pcurve_add_line ( pc, p2 );
c3d_pcurve_add_arc_2pts ( pc, p31, p32 );
c3d_pcurve_add_arc_tan ( pc, p4 );
c3d_pcurve_add_line_tan ( pc, p5 );
c3d_pcurve_add_line ( pc, p6 );
c3d_pcurve_remove_last ( pc );
c3d_pcurve_close ( pc );
return ( pc );
}
This
function creates a polycurve that contains both lines and arcs.
***>>
c3d_pcurve_remove_last <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_pcurve_remove_last ( curve );
******
Description ******
This
function removes the last segment from a 3D polycurve.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve | a 3D polycurve |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the input polycurve if the segment was successfully
removed,
and NULL if the segment could not be removed.
******
Example ******
See
c3d_pcurve_init.
***>>
c3d_pcurve_segment <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_pcurve_segment ( curve, i );
******
Description ******
This
function creates a C3_CURVE from the ith segment of a polycurve.
******
Input ******
------------------------------------------------------------------------------
|
C3_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
<c3ddefs.h>
#include
<dmldefs.h>
DML_LIST
pcurve_segments ( pcurve )
C3_CURVE
pcurve;
{
DML_LIST list = dml_create_list();
INT i = 0;
C3_CURVE curve;
for ( curve = c3d_pcurve_segment ( pcurve,
i++ );
curve != NULL;
curve = c3d_pcurve_segment ( pcurve,
i++ ) )
dml_append_data ( list, curve );
return ( list );
}
This
function creates a curve for each of the segments of a polycurve.
***>>
c3d_pcurve_through <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_pcurve_through ( a, n );
******
Description ******
This
function creates a 3D polycurve through a set of points. All
segments
of the
polycurve are linear.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | 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
<c3ddefs.h>
#include
<c3vdefs.h>
C3_CURVE
build_pcurve ( a, n )
PT3
a[];
INT n;
{
C3_CURVE pc = c3d_pcurve_through ( a, n );
if ( !c3v_ident_pts ( a[0], a[n-1] ) )
c3d_pcurve_close ( pc );
return ( pc );
}
This
function creates a closed polycurve through a set of points.
***>>
c3d_point <<***
******
Summary ******
#include
<c3ddefs.h>
PT3
*c3d_point ( x, y, z );
******
Description ******
This
function creates a point with coordinates x, y
and z.
******
Input ******
------------------------------------------------------------------------------
|
REAL | x, y, z | the x, y and z coordinates |
| | | of the created
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
<c3ddefs.h>
PT3
*create_point ()
{
PT3 *point ;
REAL x, y, z ;
printf ( "Enter coordinates of the
point.\n" ) ;
scanf ( "%lf%lf%lf", &x,
&y, &z ) ;
point = c3d_point ( x, y, z ) ;
return ( point ) ;
}
This
routine creates a point with given coordinates.
***>>
c3d_project_normal <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_project_normal ( curve0, normal, dist
);
******
Description ******
This
function creates a 3D curve which is the projection of a specified 3D
curve
onto a specified plane.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve0 | a 3D curve |
------------------------------------------------------------------------------
|
PT3 | normal | the normal vector of the |
| | | plane |
------------------------------------------------------------------------------
|
REAL | dist | the distance between the |
| |
| origin and the plane along |
| | | the normal direction |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is a curve which is the projection of the input curve on
the
specified plane. NULL is returned if
(1) memory could not be allocated
to
create the curve, or (2) an arc or a polyline
with arcs is projected to
create
elliptical segments, and SPLINE was not
defined to enable ellipses
and
splines.
@NEWPAGE
=
******
Example ******
#include
<dmldefs.h>
#include
<c3ddefs.h>
void
project_curves ( inlist, outlist, n, d )
DML_LIST
inlist, outlist;
PT3 n;
REAL d;
{
DML_ITEM item;
C3_CURVE c, c1;
DML_WALK_LIST ( inlist, item )
{
c = dml_record ( item );
c1 = c3d_project_normal ( c, n, d );
dml_append_data ( outlist, c1 );
}
}
This
function creates curves which are orthogonal projections of curves on a
list. The created curves are appended to a
list. The plane onto which the
curves
are projected is defined with its normal
vector and its distance from
the
origin along the normal direction.
***>>
c3d_project_oblique <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_project_oblique ( curve0, normal, dist,
direction );
******
Description ******
This
function creates a 3D curve which is the oblique projection of a
specified
curve onto a specified plane.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | C3_CURVE | curve0 |
------------------------------------------------------------------------------
@T3C3 =
a 3D curve
------------------------------------------------------------------------------
|
PT3 | normal | the normal vector of the |
| | | plane |
------------------------------------------------------------------------------
|
REAL | dist | the distance between the |
| | | origin and the plane
along |
| |
| the normal direction |
------------------------------------------------------------------------------
|
PT3 | direction | the projection direction |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is a curve which is the projection of the input curve on
the
specified plane. NULL is returned if
(1) memory could not be allocated
to
create the curve, or (2) an arc or a polyline with arcs is projected to
create
elliptical segments, and SPLINE was not
defined to enable ellipses
and
splines, or (3) the projection
direction is perpendicular to the plane
normal,
******
Example ******
#include
<dmldefs.h>
#include
<c3ddefs.h>
void
project_curves ( inlist, outlist, n, d, dir )
DML_LIST
inlist, outlist;
PT3 n;
REAL d;
PT3
dir;
{
DML_ITEM item;
C3_CURVE c, c1;
DML_WALK_LIST ( inlist, item ) {
c = dml_record ( item );
c1 = c3d_project_oblique ( c, n, d,
dir );
dml_append_data ( outlist, c1 );
}
}
This
function creates curves which are oblique projections of curves on a
list.
***>>
c3d_ray <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_ray ( point, theta, phi );
******
Description ******
This
function creates a line starting a specified point and following a
direction
vector specified by spherical angles.
Theta is the angle between
the
x-axis and the projection on the x-y
plane of the direction vector. Phi
is the
angle between the z-axis and the
direction vector. Both angles must
be expressed in radians. The length of the line is the world size.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | point | the start point of the
line |
------------------------------------------------------------------------------
|
REAL | theta | the angle about the z-axis, |
| | | as measured from the
x-axis |
------------------------------------------------------------------------------
|
REAL | phi | the angle from the
z-axis |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is a line starting at the specified point, and following
the
specified direction. If memory could not be allocated to create the
curve,
NULL is returned.
******
Example ******
#include
<c3vdefs.h>
#include
<c3ddefs.h>
C3_CURVE
create_ray ()
{
PT3 p;
REAL theta, phi;
printf ( "Enter coordinates of the
base point.\n" ) ;
scanf ( "%lf%lf%lf", p, p+1, p+2
) ;
printf ( "Enter theta and phi: "
);
scanf ( "%lf%lf", &theta,
&phi ) ;
return ( c3d_ray ( p, theta, phi ) ) ;
}
This
program creates a ray starting a specified point and following a
specified
angle.
***>>
c3d_rotate <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_rotate ( curve0, origin, axis, angle );
******
Description ******
This
function creates a 3D curve which is the rotation of a specified 3D
curve
about a specified axis. The rotation
follows the counter-clockwise
direction
about the axis.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve0 | a curve |
------------------------------------------------------------------------------
|
PT3 | origin,
axis | the base point and the |
| | | direction vector that
define |
| | | the rotation axis |
------------------------------------------------------------------------------
|
REAL | angle | the rotation angle; must
be |
| | | specified in
radians |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is a curve which is the rotation of the input curve about
the
specified axis. If memory could not be allocated to create the curve,
NULL is
returned.
******
Example ******
#include
<dmldefs.h>
#include
<c3ddefs.h>
void
rotate_curves ( inlist, outlist )
DML_LIST
inlist, outlist;
{
DML_ITEM item;
PT3 o, v;
REAL angle;
C3_CURVE curve, curve1;
printf ( "enter axis origin" );
scanf ( "%lf%lf%lf", o, o+1, o+2
);
printf ( "enter axis direction"
);
scanf ( "%lf%lf%lf", v, v+1, v+2
);
printf ( "enter rotation angle"
);
scanf ( "%lf", &angle );
angle *= PI_OVER_180;
DML_WALK_LIST ( inlist, item )
{
curve = dml_record ( item );
curve1 = c3d_rotate ( curve, o, v,
angle );
dml_append_data ( outlist, curve1 );
}
}
This
function creates a set of curves which are rotations of the input set
of
curves.
***>>
c3d_rotate_cs <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_rotate_cs ( curve0, origin, axis, c, s
);
******
Description ******
This
function creates a curve which is the rotation about an axis of a
specified
curve. The rotation axis is defined by a point and a vector. The
rotation
angle is specified with its sine and cosine.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve0 | a 3D curve |
------------------------------------------------------------------------------
|
PT3 | origin,
axis | the origin and the
direction |
| | | that define the
rotation |
| | | axis |
------------------------------------------------------------------------------
|
REAL | c, | s ; |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the created curve. It
is NULL if the curve could not be
created.
******
Example ******
#include
<dmldefs.h>
#include
<c3ddefs.h>
void
rotate_curves ( inlist, outlist )
DML_LIST
inlist, outlist;
{
DML_ITEM item;
PT3 o, v;
REAL angle, s, c;
C3_CURVE curve, curve1;
printf ( "enter axis origin" );
scanf ( "%lf%lf%lf", o, o+1, o+2
);
printf ( "enter axis direction"
);
scanf ( "%lf%lf%lf", v, v+1, v+2
);
printf ( "enter rotation angle"
);
scanf ( "%lf", &angle );
angle *= PI_OVER_180;
c = cos ( angle );
s = sin ( angle );
DML_WALK_LIST ( inlist, item )
{
curve = dml_record ( item );
curve1 = c3d_rotate_cs ( curve, o,
v, c, s );
dml_append_data ( outlist, curve1 );
}
}
This
function creates a set of curves which are rotations of the input set
of
curves. It is more efficient that
example for c3d_rotate because the
sine
and cosine of the rotation angle do not
have to be computed with each
call to
c3d_rotate_cs.
***>>
c3d_scale <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_scale ( curve0, origin, factor );
******
Description ******
This
function creates a curve by scaling the input curve by a scale factor
about a
given origin.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve0 | a 3D curve |
------------------------------------------------------------------------------
|
REAL | factor | the scale factor |
------------------------------------------------------------------------------
| PT3 | origin | the scaling origin |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is a curve that is the scale of the input curve. If memory
could
not be allocated to create the scaled curve, NULL is returned.
******
Example ******
#include
<c3ddefs.h>
C3_CURVE
scale_curve ( curve )
C3_CURVE
curve ;
{
REAL f ;
PT3 origin ;
C3_CURVE scaled_curve ;
printf ( "Enter scale origin\n"
) ;
scanf ( "%lf%lf%lf", origin,
origin+1, origin+2 ) ;
printf ( "Enter scale factor\n"
) ;
scanf ( "%lf", &f ) ;
scaled_curve = c3d_scale ( curve, origin,
f ) ;
return ( scaled_curve ) ;
}
This
subroutine scales the input curve by a given factor about a given
scaling
origin. The scaled curve is returned.
@NEWPAGE
=
***>>
c3d_spline <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_spline ( a, n );
******
Description ******
This
function creates a spline that passes through a set of points.
All
source code of programs that call this function must be compiled with
the
symbol SPLINE defined.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | 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
<c3ddefs.h>
C3_CURVE
list_to_spline (ptlist)
DML_LIST
ptlist ;
{
C3_CURVE spline ;
PT3 *points ;
INT size ;
size = dml_length ( ptlist ) ;
points = ( PT3* ) dml_create_list_to_array
( ptlist,
sizeof(PT3) ) ;
spline = c3d_spline ( points, size ) ;
if ( spline == NULL )
printf ( "Error creating
spline.\n" ) ;
free ( points ) ;
return ( spline ) ;
}
This
program obtains points from a list and creates a spline passing through
them.
This spline has default knots.
@NEWPAGE
=
***>>
c3d_spline_clsd <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_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.
All
source code of programs that call this function must be compiled with
the
symbol SPLINE defined.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a[] | an array of n 3D points |
------------------------------------------------------------------------------
|
INT | n | the number of points in
the |
| | | array |
------------------------------------------------------------------------------
|
C3_KNOT_OPTIONS |
knot_options | the
parametrization |
| | | convention;
generally |
| | | C3_DEFAULT should be used
|
------------------------------------------------------------------------------
Valid
parameterization options are:
______________________________________________________________________________
|
Option |
Meaning |
|----------------------------------------------------------------------------|
|
C3_DEFAULT |
non-uniform parameterization based |
| | on the
square root of the |
| |
distance between through points |
|
C3_UNIFORM |
uniform parameterization |
|
C3_CLSC_UNI |
uniform parameterization with |
| | coalesced start and end knots |
|
C3_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
<c3ddefs.h>
C3_CURVE
list_to_closed_spline (ptlist)
DML_LIST
ptlist ;
{
C3_CURVE spline ;
PT3 *points ;
INT size ;
size = dml_length ( ptlist ) ;
points = ( PT3* ) dml_create_list_to_array
( ptlist, sizeof(PT3) ) ;
if ( points == NULL )
printf ( "Error creating array
of points.\n" ) ;
spline = c3d_spline_clsd ( points, size,
C3_DEFAULT ) ;
if ( spline == NULL )
printf ( "Error creating
spline.\n" ) ;
free ( points ) ;
return ( spline ) ;
}
This
program obtains points from a list and creates a closed spline passing
through
them. This spline has default knots.
@NEWPAGE
=
***>>
c3d_spline_knots <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_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.
All
source code of programs that call this function must be compiled with
the
symbol SPLINE defined.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a[n] | the array of n through |
| | | points |
------------------------------------------------------------------------------
|
INT | n | the number of through
points |
------------------------------------------------------------------------------
|
C3_KNOT_OPTIONS |
knot_options | the
parametrization |
| | | convention;
generally |
| | | C3_DEFAULT should be used
|
------------------------------------------------------------------------------
Valid
parameterization options are:
______________________________________________________________________________
|
Option |
Meaning |
|----------------------------------------------------------------------------|
|
C3_DEFAULT |
non-uniform parameterization based |
| | on the
square root of the |
| | distance between through
points |
|
C3_UNIFORM |
uniform parameterization |
|
C3_CLSC_UNI |
uniform parameterization with |
| |
coalesced start and end knots |
|
C3_NONUNI |
non-uniform parameterization based |
| | on the
distance between through |
| |
points; corresponds approximately |
| | to the
parameterization based on |
| | the
spline arc length |
------------------------------------------------------------------------------
******
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
<c3ddefs.h>
C3_CURVE
list_to_spline ( ptlist )
DML_LIST
ptlist ;
{
C3_CURVE spline ;
PT3 *points ;
INT size ;
size = dml_length ( ptlist ) ;
points = ( PT3* ) dml_create_list_to_array
( ptlist, sizeof(PT3) ) ;
if ( points == NULL )
printf ( "Error creating array
of points.\n" ) ;
spline = c3d_spline_knots ( points, size,
C3_DEFAULT ) ;
if ( spline == NULL )
printf ( "Error creating
spline.\n" ) ;
free ( points ) ;
return ( spline ) ;
}
This
program obtains points from a list and creates a spline passing through
them.
This spline has uniform knots ( i.e., consecutive integers ).
@NEWPAGE
=
***>>
c3d_spline_tan <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_spline_tan ( a, n, knot_options, tan0,
tan0_options, tan1,
tan1_options);
******
Description ******
This
function creates a spline that passes through a given set of points and
has
given start and end tangents.
All
source code of programs that call this function must be compiled with
the
symbol SPLINE defined.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a[n] | array of n through
points |
------------------------------------------------------------------------------
|
INT | n | the number of through
points |
------------------------------------------------------------------------------
|
C3_KNOT_OPTIONS |
knot_options | the
parametrization |
| | | convention |
------------------------------------------------------------------------------
|
PT3 | tan0 | the start tangent vector |
------------------------------------------------------------------------------
|
C3_TAN_OPTIONS |
tan0_options | the start tangent
convention |
------------------------------------------------------------------------------
|
PT3 | tan1 | the end tangent vector |
------------------------------------------------------------------------------
|
C3_TAN_OPTIONS |
tan1_options | the end tangent
convention |
------------------------------------------------------------------------------
Valid
parameterization options are:
______________________________________________________________________________
|
Option |
Meaning |
|----------------------------------------------------------------------------|
|
C3_DEFAULT |
non-uniform parameterization based |
| | on the
square root of the |
| | distance between through
points |
|
C3_UNIFORM |
uniform parameterization |
|
C3_CLSC_UNI |
uniform parameterization with |
| | coalesced
start and end knots |
|
C3_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 could not be allocated to
create
the curve, NULL is returned.
******
Example ******
#define
SPLINE
#include
<dmldefs.h>
#include
<c3ddefs.h>
C3_CURVE
list_to_spline ( ptlist, tan0, tan1 )
DML_LIST
ptlist ;
PT3
tan0, tan1 ;
{
C3_CURVE spline ;
PT3 *points ;
INT size ;
size = dml_length ( ptlist ) ;
points = ( PT3* ) dml_create_list_to_array
( ptlist, sizeof(PT3) ) ;
if ( points == NULL )
printf ( "Error creating array
of points.\n" ) ;
spline = c3d_spline_tan ( points, size,
C3_DEFAULT,
tan0, C3_DEF_TAN, tan1,
C3_DEF_TAN ) ;
if ( spline == NULL )
printf ( "Error creating
spline.\n" ) ;
free ( points ) ;
return ( spline ) ;
}
This
program obtains points from a list and creates a spline passing through
them
having given start and end tangent directions.
@NEWPAGE
=
***>>
c3d_translate <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_translate ( curve0, shift );
******
Description ******
This
function creates a new curve which is a copy of the input curve
translated
by a given vector.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve0 | a 3D curve |
------------------------------------------------------------------------------
|
PT3 | shift | the translation vector |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the translated curve.
If memory could not be allocated
to
create the curve, NULL is returned.
******
Example ******
#include
<c3vdefs.h>
#include
<c3ddefs.h>
C3_CURVE
move_curve ( curve )
C3_CURVE
curve ;
{
REAL x, y, z ;
PT3 shift ;
C3_CURVE moved_curve ;
printf ( "Enter translation
vector\n" ) ;
scanf ( "%lf%lf%lf", &x,
&y, &z ) ;
c3v_set ( x, y, z, shift ) ;
moved_curve = c3d_translate ( curve, shift
) ;
return ( moved_curve ) ;
}
This
subroutine creates a curve which is a a copy of the given curve
translated
by a given vector. It returns the
created curve.
@NEWPAGE
=
***>>
c3d_transform <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_transform ( curve0, t );
******
Description ******
This
function creates a transformed copy of a specified curve.
******
Input ******
------------------------------------------------------------------------------
|
C3_CURVE | curve0 | a 3D curve |
------------------------------------------------------------------------------
|
C3_TRANSFORM | t | a 3D transform |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the transformed copy of the specified curve. It
is NULL
if (1)
memory could not be allocated to create the copy, or (2) if the
transform
is not orthogonal (i.e. will convert arcs into
ellipses), the
curve
is an arc or a polyline that contains arcs, and the symbol SPLINE is
not
defined to enable ellipses and splines.
******
Example ******
#include
<c3tdefs.h>
#include
<c3ddefs.h>
C3_CURVE
transform_curve ( curve, c, x, y )
C3_CURVE
curve ;
PT3 c,
x, y;
{
C3_TRANSFORM t;
C3_CURVE transformed_curve ;
c3t_lcs ( c, x, y, t );
transformed_curve = c3d_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.
***>>
c3d_trim <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_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 ******
------------------------------------------------------------------------------
|
C3_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 |
| | | unchanged; if parm1 is |
| | | NULL, the the end point
is |
| | | unchanged |
------------------------------------------------------------------------------
******
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
<c3cdefs.h>
#include
<c3ddefs.h>
C3_CURVE
trim_at_points ( curve, p0, p1 )
C3_CURVE
curve;
PT3 p0,
p1;
{
PARM_S parm0, parm1;
c3c_project ( curve, p0, &parm0, NULL
) ;
c3c_project ( curve, p1, &parm1, NULL
) ;
return ( c3d_trim ( curve, &parm0,
&parm1 ) );
}
This
program creates a copy of a curve that is trimmed to the projections of
two
given points.
***>>
c3d_trim0 <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_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 ******
------------------------------------------------------------------------------
|
C3_CURVE | a 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
<c3vdefs.h>
#include
<c3cdefs.h>
#include
<c3ddefs.h>
C3_CURVE
trim_at_point ( curve )
C3_CURVE
curve;
{
PT3 p ;
PARM_S parm;
c3v_set ( 3.0, 1.0, 2.0, p ) ;
c3c_project ( curve, p, &parm, NULL )
;
return ( c3d_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.
***>>
c3d_trim1 <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_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 ******
------------------------------------------------------------------------------
|
C3_CURVE | a curve | curve to be trimmed |
------------------------------------------------------------------------------
|
PARM | parm | curve parameter record
|
| | | specifying the new
position |
| | | of the end point |
------------------------------------------------------------------------------
#include
<qgldefs.h>
#include
<c3ddefs.h>
C3_CURVE
trim_at_point ( curve )
{
PT3 p ;
PARM_S parm;
c3v_set ( 3.0, 1.0, 2.0, p ) ;
c3c_project ( curve, p, &parm, NULL )
;
return ( c3d_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.
***>>
c3d_trim_t <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_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 ******
------------------------------------------------------------------------------
|
C3_CURVE | a 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
<c3cdefs.h>
#include
<c3ddefs.h>
C3_CURVE
trim_off_ends ( curve )
C3_CURVE
curve;
{
return ( c3d_trim_t ( curve, 0.3, 0.8 );
}
This
program trims off the portions of a curve that lies outside the the
interval
defined by the parameter values 0.3 and 0.8.
***>>
c3d_trim_t0 <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_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 ******
------------------------------------------------------------------------------
|
C3_CURVE | a 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
<c3vdefs.h>
#include
<c3cdefs.h>
#include
<c3ddefs.h>
C3_CURVE
trim_off_start ( curve )
C3_CURVE
curve;
{
return ( c3d_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.
***>>
c3d_trim_t1 <<***
******
Summary ******
#include
<c3ddefs.h>
C3_CURVE
c3d_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 ******
------------------------------------------------------------------------------
|
C3_CURVE | a curve | curve to be trimmed |
------------------------------------------------------------------------------
|
REAL | t | curve parameter record |
| | | specifying the new
position |
| | | of the end 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
<c3vdefs.h>
#include
<c3cdefs.h>
#include
<c3ddefs.h>
C3_CURVE
trim_off_ends ( curve )
C3_CURVE
curve;
{
return ( c3d_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.
***>>
c3t_create <<***
******
Summary ******
#include
<c3tdefs.h>
C3_TRANSFORM
*c3t_create ( );
******
Description ******
This
function creates a 3D identity transform.
******
Return Value ******
The
return value is a pointer to a 3D identity transform. If the transform
could
not be created, NULL is returned.
******
Example ******
#include
<c3tdefs.h>
#include
<c3vdefs.h>
void
main (void)
{
PT3 n, c, x, y, a, b;
C3_TRANSFORM t1, t2, *t = c3t_create();
c3v_set ( 1., 1., 1., c );
c3v_set ( 3./5., 4./5., 0., n );
c3v_basis ( n, x, y );
c3t_lcs ( c, x, y, t1 );
c3v_set ( 5., 6., 7., a );
c3t_eval_pt ( a, t1, b );
c3v_set ( 1., 1., 1., c );
c3v_set ( 0., 4./5., 3./5., x );
c3v_basis ( n, x, y );
c3t_lcs ( c, x, y, t2 );
if ( !c3t_orthogonal ( t2 ) )
printf ( "t2 is not
orthogonal\n" );
c3t_mult ( t1, t2, *t );
c3t_eval_vec ( a, *t, b );
c3t_inverse ( t1, *t );
c3t_eval_pt ( a, *t, b );
c3t_free ( *t );
}
This
program creates transforms for 3D coordinate systems, and converts
points
and vectors between coordinate systems using the transforms.
***>>
c3t_eval_pt <<***
******
Summary ******
#include
<c3tdefs.h>
REAL
*c3t_eval_pt ( a, t, b );
******
Description ******
This
function transforms a 3D point by a 3D transform.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a | a 3D point |
------------------------------------------------------------------------------
|
C3_TRANSFORM | t | a 3D transform |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | b | the transformed 3D
point |
------------------------------------------------------------------------------
******
Return Value ******
The return
value is the output point.
******
Example ******
See
c3t_create.
***>>
c3t_eval_vec <<***
******
Summary ******
#include
<c3tdefs.h>
REAL
*c3t_eval_vec ( a, t, b );
******
Description ******
This
function transforms a 3D vector by a 3D transform.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a | a 3D vector |
------------------------------------------------------------------------------
|
C3_TRANSFORM | t | a 3D transform |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | b | the transformed
vector |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the output point.
******
Example ******
See
c3t_create.
***>>
c3t_free <<***
******
Summary ******
#include
<c3tdefs.h>
void
c3t_free ( t );
******
Description ******
This
function frees a 3D transform.
******
Input ******
------------------------------------------------------------------------------
|
C3_TRANSFORM | t | a 3D transform |
------------------------------------------------------------------------------
******
Example ******
See
c3t_create.
***>>
c3t_inverse <<***
******
Summary ******
#include
<c3tdefs.h>
REAL *
c3t_inverse ( t0, t1 );
******
Description ******
This
function computes the inverse of a 3D transform.
******
Input ******
------------------------------------------------------------------------------
|
C3_TRANSFORM | t0 | a 3D transform |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
C3_TRANSFORM | t1 | the inverse of the 3D |
| | | transform |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is TRUE if the transform was computed successfully.
Otherwise
it is FALSE.
******
Example ******
See
c3t_create.
***>>
c3t_lcs <<***
******
Summary ******
#include
<c3tdefs.h>
C3_TRANSFORM
*c3t_lcs ( c, x, y, t );
******
Description ******
This
function computes the 3D 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 ******
------------------------------------------------------------------------------
|
PT3 | c, x, y | the origin, x-axis and |
| | | y-axis of the local |
| | | coordinate system |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
C3_TRANSFORM | t | the computed
transform |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is a pointer to the output transform if it was successfully
computed. It is NULL otherwise.
******
Example ******
See
c3t_create.
***>>
c3t_mirror <<***
******
Summary ******
#include
<c3tdefs.h>
REAL
*c3t_mirror ( normal, dist, t );
******
Description ******
This
function constructs a 3D transform that mirrors 3D objects about a
plane.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | normal | the normal vector of the |
| | | plane |
------------------------------------------------------------------------------
|
REAL | dist | the distance between the |
| | | origin and the plane
along |
| | | the normal direction |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
C3_TRANSFORM | t | the constructed
transform |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the output transform.
******
Example ******
#include
<c3tdefs.h>
void
main()
{
PT3 n;
REAL dist;
C3_TRANSFORM *t = c3t_create();
printf ( "Enter plane normal and
dist:" );
scanf ( "%lf%lf%lf%lf", n, n+1,
n+2, &dist );
c3t_mirror ( n, dist, *t );
c3t_free ( *t );
}
This
program creates a transform for mirroring 3D objects.
***>>
c3t_mult <<***
******
Summary ******
#include
<c3tdefs.h>
REAL
*c3t_mult ( t1, t2, t );
******
Description ******
This
function multiplies two transform to make a third transform.
******
Input ******
------------------------------------------------------------------------------
|
C3_TRANSFORM | t1, t2 | two 3D transforms |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
C3_TRANSFORM | t | the product of the
two |
| | | transforms |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the output transform.
******
Example ******
See
c3t_create.
***>>
c3t_orthogonal <<***
******
Summary ******
#include
<c3tdefs.h>
BOOLEAN
c3t_orthogonal ( t );
******
Description ******
This
function determines if a transform is orthogonal. Non- orthogonal
transforms
distort angles, and cause circles to become
ellipses.
******
Input ******
------------------------------------------------------------------------------
|
C3_TRANSFORM | t | a 3D transform |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is TRUE if the transform is orthogonal, and FALSE if it is
not
orthogonal.
******
Example ******
See
c3t_create.
***>>
c3t_rotate <<***
******
Summary ******
#include
<c3tdefs.h>
REAL
*c3t_rotate ( origin, axis, angle, t );
******
Description ******
This
function constructs a 3D transform that rotates 3D objects about an
axis. The rotation occurs in the
counter-clockwise direction about the
axis.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | origin, axis
| the origin and axis vector |
| | | of the rotation
axis |
------------------------------------------------------------------------------
|
REAL | angle | the rotation angle; must
be |
| | | specified in
radians |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
C3_TRANSFORM | t | the constructed
transform |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the output transform.
******
Example ******
#include
<c3tdefs.h>
void
main()
{
PT3 o, v;
REAL angle;
C3_TRANSFORM *t = c3t_create();
printf ( "Enter rotation origin, axis
and angle" );
scanf ( "%lf%lf%lf%lf%lf%lf%lf",
o, o+1, o+2,
v, v+1, v+2, &angle );
c3t_rotate ( o, v, angle, *t );
c3t_free ( *t );
}
This
program constructs a transform for rotating 3D objects.
***>>
c3t_rotate_cs <<***
******
Summary ******
#include
<c3tdefs.h>
REAL
*c3t_rotate_cs ( origin, axis, c, s, t );
******
Description ******
This
function constructs a 3D transform that rotates 3D objects about an
axis. The rotation angle is specified with its
cosine and sine. The
rotation
occurs in the counter-clockwise direction about the axis.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | origin,
axis | the origin and axis
vector |
| | | of the rotation
axis |
------------------------------------------------------------------------------
|
REAL | c, s | the cosine and sine of
the |
| | | rotation angle |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
C3_TRANSFORM | t | the constructed
transform |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the output transform.
******
Example ******
#include
<c3tdefs.h>
void
main()
{
PT3 o, v;
REAL angle, c, s;
C3_TRANSFORM *t = c3t_create();
printf ( "Enter rotation origin, axis
and angle" );
scanf ( "%lf%lf%lf%lf%lf%lf%lf",
o, o+1, o+2,
v, v+1, v+2, &angle );
c = cos ( angle );
s = sin ( angle );
c3t_rotate_cs ( o, v, c, s, *t );
c3t_free ( *t );
}
***>>
c3t_scale <<***
******
Summary ******
#include
<c3tdefs.h>
REAL
*c3t_scale ( origin, f0, f1, f2, t );
******
Description ******
This
function constructs a 3D transform for scaling 3D objects about a
point. The x, y and z directions may have different scale factors.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | origin | the center of scaling |
------------------------------------------------------------------------------
|
REAL | f0, f1, f2 | the x, y and z scale factors |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
C3_TRANSFORM | t | the constructed
transform |
------------------------------------------------------------------------------
****** Return
Value ******
The
return value is the output transform.
******
Example ******
#include
<c3tdefs.h>
void
main()
{
PT3 o;
REAL f0, f1, f2;
C3_TRANSFORM *t = c3t_create();
printf ( "Enter scaling origin and
factors" );
scanf ( "%lf%lf%lf%lf%lf%lf", o,
o+1, o+2, &f0, &f1, &f2 );
c3t_scale ( o, f0, f1, f2, *t );
c3t_free ( *t );
}
This
program constructs a transform for scaling 3D objects.
***>>
c3t_translate <<***
******
Summary ******
#include
<c3tdefs.h>
REAL
*c3t_translate ( shift, t );
******
Description ******
This
function constructs a 3D transform for translating 3D objects.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | shift | the translation vector |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
C3_TRANSFORM | t | the constructed
transform |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the output transform.
******
Example ******
#include
<c3tdefs.h>
void
main()
{
PT3 shift;
C3_TRANSFORM *t = c3t_create();
printf ( "Enter translation
vector" );
scanf ( "%lf%lf%lf", shift,
shift+1, shift+2 );
c3t_translate ( shift, *t );
c3t_free ( *t );
}
This
program constructs a transform for translating 3D objects.
@NEWPAGE
=
***>>
c3v_add <<***
******
Summary ******
#include
<c3vdefs.h>
REAL *
c3v_add ( a, b, c );
******
Description ******
This
function adds two vectors. This operation is defined by the following
expression:
c = a + b.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a, b | the vectors to add |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | c | the sum of a and b |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the output vector.
******
Example ******
#include
<c3vdefs.h>
void
main()
{
PT3 pt1, pt2, pt3 ;
c3v_set ( 1., 2., 3., pt1 ) ;
c3v_set ( 4., 5., 6., pt2 ) ;
c3v_add ( pt1, pt2, pt3 ) ;
}
This
program adds two vectors. The result is (5., 7., 9. ).
@NEWPAGE
=
***>>
c3v_addc <<***
******
Summary ******
#include
<c3vdefs.h>
REAL*
c3v_addc ( c, a, p, b, q, x );
******
Description ******
This
function adds the weighted sum of two vectors a and b to a third vector
c.
This
sum is expressed by:
x = c + p * a + q * b ;
******
Input ******
------------------------------------------------------------------------------
|
PT3 | c | a vector |
------------------------------------------------------------------------------
|
PT3 | a, b | the two vectors combined |
| |
| with a weighted sum |
------------------------------------------------------------------------------
|
REAL | p, q | weights applied to a and
b, |
| | | respectively |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | x | the result of this sum |
------------------------------------------------------------------------------
******
Return Value ******
If the
computation was successful, the return value is a pointer to the
result
vector x. Otherwise it is NULL.
******
Example ******
#include
<c3vdefs.h>
void
combine_pts ( a, b, c, x )
PT3 a,
b, c, x;
{
REAL p, q;
printf ( "enter 2 weights" );
scanf ( "%lf%lf", &p, &q
);
c3v_addc ( c, a, p, b, q, x );
}
This
function combines three points using specified weights.
@NEWPAGE
=
***>>
c3v_addt <<***
******
Summary ******
#include
<c3vdefs.h>
REAL *
c3v_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 ******
------------------------------------------------------------------------------
|
PT3 | a, b | the vectors to add |
------------------------------------------------------------------------------
|
REAL | t | the weighting factor |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | c | the sum of the first
vector |
| | | and the multiple of the
|
| | | second vector |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the output vector.
******
Example ******
#include
<c3vdefs.h>
void
main()
{
PT3 v1, v2, v3 ;
REAL t = 0.25 ;
c3v_set ( 3., 2., 1., v1 ) ;
c3v_set ( 8., 4., -4., v2 ) ;
c3v_addt ( v1, v2, t, v3 ) ;
}
This
program computes the sum of the vector v0 and a quarter of the vector v1.
The
result vector v2 will have the coordinates ( 5., 3.0, 0. ).
@NEWPAGE
=
***>>
c3v_addu <<***
******
Summary ******
#include
<c3vdefs.h>
REAL *
c3v_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 ******
------------------------------------------------------------------------------
|
PT3 | a, b
| the vectors to add |
------------------------------------------------------------------------------
|
REAL | u | weighting fraction |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | c | the convex combination of
a |
| | |
and b |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the output vector.
******
Example ******
#include
<c3vdefs.h>
void
main()
{
PT3 p1, p2, p3 ;
REAL u = 1.0/3.0 ;
c3v_set ( 1.0, 2.0, 3.0, p1 ) ;
c3v_set ( 4.0, 5.0, 6.0, p2 ) ;
c3v_addu ( p1, p2, u, p3 ) ;
}
This
program computes coordinates of a vector which is a sum of 2/3 of the
first
vector and 1/3 of the second vector. Therefore, p3=(2.0,3.0,4.0).
@NEWPAGE
=
***>>
c3v_addw <<***
******
Summary ******
#include
<c3vdefs.h>
REAL *
c3v_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 ******
------------------------------------------------------------------------------
|
PT3 | a, b | the vectors to add |
------------------------------------------------------------------------------
|
REAL | p, q | weighting factors |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | c | the weighted sum of a and
b |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the output vector.
******
Example ******
#include
<c3vdefs.h>
void
compute_new_position ( old_pos, wind_dir, our_dir,
del_time, wind_vel, our_vel, new_pos )
PT3
old_pos, wind_dir, our_dir, new_pos ;
REAL
wind_vel, our_vel, del_time ;
{
PT3 offset ;
REAL wind_dist, our_dist ;
wind_dist = del_time * wind_vel ;
our_dist = del_time * our_vel ;
c3v_addw ( wind_dir, wind_dist, our_dir,
our_dist, offset ) ;
c3v_add ( old_pos, offset, new_pos ) ;
}
This
subroutine computes the position of an airplane flying in a crosswind.
@NEWPAGE
=
***>>
c3v_basis <<***
******
Summary ******
#include
<c3vdefs.h>
BOOLEAN
c3v_basis ( n, u, v );
******
Description ******
This
function constructs two orthogonal unit vectors that are both
orthogonal
to a given vector. This function is
useful for creating x and y
axes of
a local coordinate system located on a plane.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | n | a 3D vector |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | u, v | two unit vectors which
are |
| | | both orthogonal to n;
if v
|
| | | is NULL, it is not
computed |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is TRUE if the vectors were successfully constructed.
Otherwise
it is NULL.
******
Example ******
#include
<c3vdefs.h>
void
combine_pts ( u, v )
PT3 u,
v;
{
PT3 n;
printf ( "enter normal vector"
);
scanf ( "%lf%lf%lf", n, n+1, n+2
);
c3v_basis ( n, u, v );
}
This
function constructs two orthogonal vectors that are both orthogonal to
a
specified vector.
@NEWPAGE
=
***>>
c3v_conv_pt_2d3d <<***
******
Summary ******
#include
<c3vdefs.h>
REAL
*c3v_conv_pt_2d3d ( b, c, u, v, a);
******
Description ******
This
function computes the 3D coordinates of a 2D point on the x-y plane of
a local
coordinate system in 3D space. The
local coordinate system is
defined
by an origin, an x-axis vector and a y- axis vector.
******
Input ******
------------------------------------------------------------------------------
|
PT2 | b | a 2D point |
------------------------------------------------------------------------------
|
PT3 | c, u, v | the origin, x-axis vector |
| | | and y-axis vector |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | a | the output 3D point |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the output vector.
******
Example ******
#include
<c3vdefs.h>
void
transform_point ( o, x, y, p )
PT3 o,
x, y, p;
{
PT2 p2d;
printf ( "enter a 2D point" );
scanf ( "%lf%lf", p2d, p2d+1 );
c3v_conv_pt_2d3d ( p2d, o, x, y, p );
}
This
function transforms a specified 2D point in a local coordinate system
into
its corresponding point in 3D space.
@NEWPAGE
=
***>>
c3v_conv_pt_3d2d <<***
******
Summary ******
#include
<c3vdefs.h>
REAL*
c3v_conv_pt_3d2d ( b, c, u, v, a );
******
Description ******
This
function computes the x and y coordinates of the projection of a 3D
point
onto the x-y plane of a local coordinate system in 3D space. The
local
coordinate system is defined by an origin, an x- axis vector and a
y-axis
vector.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | b | a 3D point |
------------------------------------------------------------------------------
|
PT3 | c, u, v | the origin, x-axis vector |
| | | and y-axis vector |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT2 | a | the output 2D point |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the output vector.
******
Example ******
#include
<c3vdefs.h>
void
transform_point ( o, x, y, p )
PT3 o,
x, y;
PT2 p;
{
PT3 p3d;
printf ( "enter a 3D point" );
scanf ( "%lf%lf%lf", p3d, p3d+1,
p3d+2);
c3v_conv_pt_3d2d ( p3d, o, x, y, p );
}
This
function transforms a 3D point into its corresponding 2D point in a
local
coordinate system.
@NEWPAGE
=
***>>
c3v_conv_vec_2d3d <<***
******
Summary ******
#include
<c3vdefs.h>
REAL*
c3v_conv_vec_2d3d ( b, u, v, a );
******
Description ******
This
function computes the 3D coordinates of a 2D vector on the x-y plane
of a
local coordinate system in 3D space.
The local coordinate system is
defined
by an origin, an x-axis vector and a y- axis vector.
******
Input ******
------------------------------------------------------------------------------
|
PT2 | b | a 2D vector |
------------------------------------------------------------------------------
|
PT3 | u, v | x-axis and y-axis
vectors |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | a | the output 3D vector |
------------------------------------------------------------------------------
******
Return Value ******
The return
value is a pointer to the output vector.
******
Example ******
#include
<c3vdefs.h>
void
transform_vector ( x, y, vec )
PT3 x,
y, vec;
{
PT2 vec2d;
printf ( "enter a 2D vector" );
scanf ( "%lf%lf", vec2d, vec2d+1
);
c3v_conv_vec_2d3d ( vec2d, x, y, vec );
}
This
function converts a 2D vector in a local coordinate system to its
corresponding
vector in 3D space.
@NEWPAGE
=
***>>
c3v_conv_vec_3d2d <<***
******
Summary ******
#include
<c3vdefs.h>
REAL*
c3v_conv_vec_3d2d ( b, u, v, a );
******
Description ******
This
function computes the x and y coordinates of the projection of a 3D
vector
onto the x-y plane of a local coordinate system in 3D space. The
local
coordinate system is defined by an origin, an x-axis vector and a
y-axis
vector.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | b | a 3D point |
------------------------------------------------------------------------------
|
PT3 | u, v | x-axis and y-axis
vectors |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT2 | a | the output 2D vector |
------------------------------------------------------------------------------
******
Return Value ******
The return
value is a pointer to the output vector.
******
Example ******
#include
<c3vdefs.h>
void
transform_vector ( x, y, vec )
PT3 x,
y;
PT2
vec;
{
PT3 vec3d;
printf ( "enter a 3D vector" );
scanf ( "%lf%lf%lf", vec3d,
vec3d+1, vec3d+2);
c3v_conv_vec_3d2d ( vec3d, x, y,
vec );
}
This
function transforms a 3D vector into its corresponding 2D vector in a
local
coordinate system.
@NEWPAGE
=
***>>
c3v_coord_sys <<***
******
Summary ******
#include
<c3vdefs.h>
void
c3v_coord_sys ( normal, dist, origin, x_axis,
y_axis );
******
Description ******
Given a
plane specified by a normal vector and distance, this function
constructs
a local coordinate system on the plane.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | normal | the normal vector of the |
| | | plane |
------------------------------------------------------------------------------
|
REAL | dist | the distance from the
origin |
| | | to the plane along
the |
| | | normal direction |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | origin | origin |
------------------------------------------------------------------------------
|
PT3 | x_axis | x axis |
------------------------------------------------------------------------------
|
PT3 | y_axis | y axis |
------------------------------------------------------------------------------
******
Example ******
#include
<c3vdefs.h>
void
main()
{
PT3 n, o, x, y ;
REAL dist = 5.0;
c3v_set ( 3.0, 2.0, 1.0, n ) ;
c3v_coord_sys ( n, dist, o, x, y ) ;
}
This
program constructs a coordinate system on a plane specified with a
normal
and a distance from the origin.
@NEWPAGE
=
***>>
c3v_copy <<***
******
Summary ******
#include
<c3vdefs.h>
REAL *
c3v_copy(a,b);
******
Description ******
This
function copies one point to another.
******
Input ******
------------------------------------------------------------------------------
| PT3 | a | the point to copy |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | b | the copy |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the output vector.
******
Example ******
#include
<c3vdefs.h>
void
main()
{
PT3 p0, p1 ;
c3v_set ( 3.0, 2.0, 1.0, p0 ) ;
c3v_copy ( p0, p1 ) ;
}
This
program copies one point to another.
@NEWPAGE
=
***>>
c3v_cross <<***
******
Summary ******
#include
<c3vdefs.h>
REAL *
c3v_cross ( a, b, c );
******
Description ******
This
function computes the cross product of two vectors. The result is a
vector
whose components are defined by the
following expressions:
c[0] = a[1] * b[2] - a[2] * b[1]
c[1] = a[2] * b[0] - a[0] * b[2]
c[2] = a[0] * b[1] - a[1] * b[0].
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a, b | the vectors to cross |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | c | the cross product of a
with |
| | | b |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the output vector.
******
Example ******
#include
<c3vdefs.h>
void
print_cross_product
( vec1, vec2 )
PT3
vec1, vec2 ;
{
PT3 cross_prod ;
c3v_cross ( vec1, vec2, cross_prod ) ;
printf ( "The cross product of vec1
and vec2 is " ) ;
printf ( "%lf %lf %lf.\n",
cross_prod[0], cross_prod[1], cross_prod[2] ) ;
}
This
subroutine prints out the coordinates of the cross product of the input
vectors.
@NEWPAGE
=
***>>
c3v_dist <<***
******
Summary ******
#include
<c3vdefs.h>
REAL
c3v_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] ) ) +
( a[2]-b[2] )*( a[2]-b[2] ) ).
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a, b | two points |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the distance between the two points.
******
Example ******
#include
<c3vdefs.h>
void
print_distance
( pt1, pt2 )
PT3
pt1, pt2 ;
{
REAL dist ;
dist = c3v_dist ( pt1, pt2 ) ;
printf ( "The distance between two
points is %lf.\n", dist ) ;
}
This
subroutine prints the distance between two points.
@NEWPAGE
=
***>>
c3v_dist_squared <<***
******
Summary ******
#include
<c3vdefs.h>
REAL
c3v_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] ) +
( a[2]-b[2] )*( a[2]-b[2] ).
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a, b | two points |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the square of the distance between the two points.
******
Example ******
#include
<c3vdefs.h>
void
print_distance_squared
( pt1, pt2 )
PT3
pt1, pt2 ;
{
REAL dist ;
dist = c3v_dist ( pt1, pt2 ) ;
printf ( "The distance squared
between two points is %lf.\n", dist ) ;
}
This
subroutine prints out the square of the distance between two points.
@NEWPAGE
=
***>>
c3v_distl1 <<***
******
Summary ******
#include
<c3vdefs.h>
REAL
c3v_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] )
+ fabs ( a[2]-b[2] ).
This
value is a rough estimate of the distance between two points, and is
computed
much more quickly than the exact Euclidean
distance.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a, b | two points |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the "L1" distance between two points.
******
Example ******
#include
<c3vdefs.h>
void
print_distance_l1
( pt1, pt2 )
PT3
pt1, pt2 ;
{
REAL dist ;
dist = c3v_distl1 ( pt1, pt2 ) ;
printf ( "The L1 distance between two
points is %lf.\n",
dist ) ;
}
This
subroutine prints the L1 distance between two points.
@NEWPAGE
=
***>>
c3v_dot <<***
******
Summary ******
#include
<c3vdefs.h>
REAL
c3v_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] + a[2] *
b[2].
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a, b | two vectors |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the dot product of the two vectors.
******
Example ******
#include
<c3vdefs.h>
void
print_dot_product ( vec1, vec2 )
PT3
vec1, vec2 ;
{
REAL dot_prod ;
dot_prod = c3v_dot ( vec1, vec2 ) ;
printf ( "The dot product of vec1 and
vec2 is %lf.\n", dot_prod ) ;
}
This
subroutine prints out the dot product of two vectors.
@NEWPAGE
=
***>>
c3v_ident_pts <<***
******
Summary ******
#include
<c3vdefs.h>
BOOLEAN
c3v_ident_pts(a,b);
******
Description ******
This
function determines if two points coincide within a tolerance. The
tolerance
used is the absolute tolerance, which
can be changed by resetting
either the world size or the relative tolerance.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a, b | two points |
------------------------------------------------------------------------------
******
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
<c3vdefs.h>
void
coincidence_check
( pt0, pt1 )
PT3
pt0, pt1 ;
{
if ( !c3v_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.
@NEWPAGE
=
***>>
c3v_is_small <<***
******
Summary ******
#include
<c3vdefs.h>
BOOLEAN
c3v_is_small ( a );
@HEADIOG
= Description
This
function determines if absolute values of all of the 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 ******
------------------------------------------------------------------------------
|
PT3 | a | a vector |
------------------------------------------------------------------------------
******
Return Value ******
This
function returns TRUE if absolute values of all three 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
<c3vdefs.h>
void
check_zerolength
( v )
PT3 v ;
{
if ( c3v_is_small ( v ) )
printf ( "vector has zero
length\n" ) ;
else
printf ( "vector has non-zero
length\n" ) ;
}
This
subroutine checks if a vector has nearly zero length and prints out the
appropriate
message.
@NEWPAGE
=
***>>
c3v_mid_pt <<***
******
Summary ******
#include
<c3vdefs.h>
REAL *
c3v_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 ******
------------------------------------------------------------------------------
|
PT3 | a, b | two points |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | c | midpoint between the
two |
| | | points |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the output vector.
******
Example ******
#include
<c3vdefs.h>
void
main()
{
PT3 pt1, pt2, mid_pt ;
c3v_set ( 1.0, 2.0, 3.0, pt1 ) ;
c3v_set ( 4.0, 5.0, 6.0, pt2 ) ;
c3v_mid_pt ( pt1, pt2, mid_pt ) ;
}
This
program computes a midpoint between pt1 and pt2. Therefore, mid_pt = (
2.5,
3.5, 4.5 ) .
@NEWPAGE
=
***>>
c3v_mirror_pt <<***
******
Summary ******
#include
<c3vdefs.h>
REAL *
c3v_mirror_pt ( a, n, d, b );
******
Description ******
This
function mirrors a point across a plane. The plane is defined by a
normal
vector and a distance from the origin.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a | a 3D point |
------------------------------------------------------------------------------
|
PT3 | n | the normal vector of the |
| | | plane |
------------------------------------------------------------------------------
|
REAL | d | the distance of the plane
to |
| | | the origin |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | b | the mirror image of a
across |
| | | the plane |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the output vector.
******
Example ******
#include
<c3vdefs.h>
void
main()
{
PT3 a, n, b ;
REAL d ;
c3v_set ( 0.0, 0.0, 1.0, n ) ;
d = 1.0 ; /* plane z = 1 */
c3v_set ( 2.0, 3.0, 4.0, a ) ;
c3v_mirror_pt ( a, n, d, b ) ;
}
This
routine computes a mirror image of the point ( 2.0, 3.0, 4.0 ) with
respect
to the plane z = 1. The result of this operation is b=(2.0, 3.0,
-2.0).
@NEWPAGE
=
***>>
c3v_mirror_vec <<***
******
Summary ******
#include
<c3vdefs.h>
REAL *
c3v_mirror_vec ( a, n, b );
******
Description ******
This
function mirrors a vector across a plane perpendicular to a specified
vector.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a | a 3D vector |
------------------------------------------------------------------------------
|
PT3 | n | the normal vector of the |
| | | plane |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | b | the mirror image of a
across |
| | | the plane |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the output vector.
******
Example ******
#include
<c3vdefs.h>
void
main()
{
PT3 a, n, b ;
c3v_set ( 0.0, 0.0, 1.0, n ) ;
c3v_set ( 2.0, 3.0, 4.0, a ) ;
c3v_mirror_vec ( a, n, b ) ;
}
This
routine computes a mirror image of the vector ( 2.0, 3.0, 4.0 ) with
respect
to the plane z = 1. The result of this operation is b=(2.0, 3.0,
-4.0).
@NEWPAGE
=
***>>
c3v_negate <<***
******
Summary ******
#include
<c3vdefs.h>
REAL *
c3v_negate ( a, b );
******
Description ******
This
function negates or reverses a vector. This
operation is defined by the
expression:
b = -a.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a | a vector |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | b | vector with direction |
| | | reversed |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the output vector.
******
Example ******
#include
<c3vdefs.h>
void
main()
{
PT3 vec, vec1 ;
REAL x = 2.0, y = 5.0, z = -3.0 ;
c3v_set ( x, y, z, vec ) ;
c3v_negate ( vec, vec1 ) ;
}
This
program negates a vector. As a result, vec1 = (-2.0, -5.0, 3.0 ) .
***>>
c3v_norm <<***
******
Summary ******
#include
<c3vdefs.h>
REAL
c3v_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] +
a[2]*a[2] ).
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a | a vector |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the length or "norm" of the vector.
******
Example ******
#include
<c3vdefs.h>
void
main()
{
PT3 vec ;
REAL length ;
c3v_set ( 1.0, 2.0, 3.0, vec ) ;
length = c3v_norm ( vec ) ;
printf ( "vector length is
%lf.\n", length ) ;
}
This
program computes the length of the vector, and prints it out.
***>>
c3v_norm_squared <<***
******
Summary ******
#include
<c3vdefs.h>
REAL
c3v_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] +
a[2]*a[2].
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a | a vector |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the length or norm of the vector squared.
******
Example ******
#include
<c3vdefs.h>
void
main()
{
PT3 vec ;
REAL l_sqr ;
c3v_set ( 1.0, 2.0, 3.0, vec ) ;
l_sqr = c3v_norm_squared ( vec ) ;
printf ( "vector length squared is
%lf.\n", l_sqr ) ;
}
This
program computes the square of the length of the vector, and prints it
out.
***>>
c3v_normalize <<***
******
Summary ******
#include
<c3vdefs.h>
BOOLEAN
c3v_normalize ( a, b );
******
Description ******
This
function normalizes a vector to produce a unit vector. This operation
is
defined by the following expression:
b = a / c3v_norm(a).
The
vector must have non-zero length to be normalized.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a | a vector |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | 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,
and the coordinates of the output vector are
(0,0,0).
******
Example ******
#include
<c3vdefs.h>
void
main()
{
PT3 vec, vec1 ;
c3v_set ( 1.0, 2.0, 3.0, vec ) ;
if ( !c3v_normalize ( vec, vec1 ) )
printf ( "Cannot normalize zero
length vector\n" ) ;
}
This
routine normalizes the vector ( 1.0, 2.0, 3.0 ).
***>>
c3v_normalize_l1 <<***
******
Summary ******
#include
<c3vdefs.h>
BOOLEAN
c3v_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
c3v_norml1).
This
operation is defined by the following expression:
b = a / c3v_norml1(a).
If the
"L1" length of the vector is zero, this function returns FALSE, and
the
output vector b is (0,0,0).
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 ******
------------------------------------------------------------------------------
|
PT3 | a | a vector |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | 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 (0,0,0).
******
Example ******
#include
<c3vdefs.h>
void
main()
{
PT3 vec, vec1 ;
c3v_set ( 1.0, 2.0, 3.0, vec ) ;
if ( !c3v_normalize_l1 ( vec, vec1 ) )
printf ( "Cannot normalize zero
length vector\n" ) ;
}
This
routine normalizes the vector ( 1.0, 2.0, 3.0 ) by the "L1" norm.
***>>
c3v_norml1 <<***
******
Summary ******
#include
<c3vdefs.h>
REAL
c3v_norml1 ( a );
******
Description ******
This
function computes the "L1" length of a vector. This quantity is defined
by the
following expression:
norm_l1 = fabs ( a[0] ) + fabs ( a[1] ) +
fabs ( a[2] ).
This
length is computed much more quickly than the true length, and
consequently
should be used when an approximate length will suffice.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a | a vector |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the "L1" norm of the vector.
******
Example ******
#include
<c3vdefs.h>
void
main()
{
PT3 vec ;
REAL length ;
c3v_set ( 1.0, 2.0, 3.0, vec ) ;
length = c3v_norml1 ( vec ) ;
printf ( "L1 length is %lf.\n",
length ) ;
}
This
routine prints out the "L1" length of the vector ( 1.0, 2.0, 3.0 ),
which
is 6.0.
***>>
c3v_plane_3pts <<***
******
Summary ******
#include
<c3vdefs.h>
BOOLEAN
c3v_plane_3pts ( p0, p1, p2, normal, dist_ptr );
******
Description ******
This
function computes the normal vector and distance from the origin of a
plane
defined by three points.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | p0, p1, p2 | three points |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | normal | the normal of the plane |
------------------------------------------------------------------------------
| REAL
* | dist_ptr | the distance between the |
| | | origin and the plane
along |
| | | the normal direction |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is TRUE if the plane could be constructed. It is
FALSE if
the
points do not define a unique plane; this condition arises if the three
points
are not distinct or if they are
collinear.
******
Example ******
#include
<c3vdefs.h>
void
main ()
{
PT3 p0, p1, p2, n;
REAL dist ;
c3v_set ( 1.0, 0.0, 0.0, p0 ) ;
c3v_set ( 1.0, 1.0, 1.0, p1 ) ;
c3v_set ( -1.0, 1.0, -1.0, p2 ) ;
if ( c3v_plane_3pts ( p0, p1, p2, n,
&dist ) )
printf ( "Plane normal and
dist: %lf %lf %lf %lf\n",
n[0], n[1], n[2], dist );
}
This
program constructs a plane through three points.
***>>
c3v_project_line <<***
******
Summary ******
#include
<c3vdefs.h>
REAL
c3v_project_line ( a, b, c, p );
******
Description ******
This
function projects a point onto a line defined by two points.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a, b | two points that define a |
| | | line |
------------------------------------------------------------------------------
|
PT3 | c | the point to project |
------------------------------------------------------------------------------
****** Output
******
@T3C2 =
p
@T3C3 =
a point which is the projection of c onto the line defined by a and
b; if
this argument is NULL, this point is
not computed
******
Return Value ******
The
return value is the parameter value on the line that corresponds to the
point
of projection.
******
Example ******
#include
<c3vdefs.h>
void
main ()
{
PT3 pt0, pt1, pt ;
REAL t ;
c3v_set ( 0.0, 0.0, 0.0, pt0 ) ;
c3v_set ( 1.0, 1.0, 1.0, pt1 ) ;
c3v_set ( 1.0, 1.0, 0.0, pt ) ;
t = c3v_project_line ( pt0, pt1, pt, NULL
) ;
printf ( "Projection parameter is
%lf\n", t ) ;
}
This
routine prints out the parameter of the projection of point pt onto
line
(pt0,pt1). The computed value of t is 2/3.
***>>
c3v_project_pt_normal <<***
******
Summary ******
#include
<c3vdefs.h>
REAL *
c3v_project_pt_normal ( a, n, d, b );
******
Description ******
This
function projects a point onto a plane along the normal vector of the
plane.
The plane is defined with a normal vector and a distance from the
origin.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a | the point to project |
------------------------------------------------------------------------------
|
PT3 | n | the normal vector of
the |
| | | plane |
------------------------------------------------------------------------------
|
REAL | d | the distance of the
plane |
| | | from the origin |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | b | the point of projection
on |
| | | the plane |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the output point.
******
Example ******
#include
<c3vdefs.h>
void
main()
{
PT3 a, n, b ;
REAL d ;
c3v_set ( 0.0, 0.0, 1.0, n ) ;
d = 0.0 ; /* plane z = 0 */
c3v_set ( 2.0, 3.0, 4.0, a ) ;
c3v_project_pt_normal ( a, n, d, b ) ;
}
This
routine computes projection of the point ( 2.0, 3.0, 4.0 ) onto the x-y
plane (
plane z=0 ). The result of this operation is b=(2.0, 3.0, 0.0).
***>>
c3v_project_pt_oblique <<***
******
Summary ******
#include
<c3vdefs.h>
BOOLEAN
c3v_project_pt_oblique ( a, normal, dist, direction, b );
******
Description ******
This
function projects a point onto a plane along a specified direction. The
plane
is defined with a normal vector and a distance from the origin.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a
| the point to project |
------------------------------------------------------------------------------
|
PT3 | n | the normal vector of
the |
| | | plane |
------------------------------------------------------------------------------
|
REAL | d | the distance of the
plane |
| | | from the origin |
------------------------------------------------------------------------------
|
PT3 | direction | the projection direction |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | b | the point of projection
on |
| | | the plane |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the output point. It is
NULL if the normal and
direction
vectors are perpendicular to each other.
******
Example ******
#include
<c3vdefs.h>
void
main()
{
PT3 a, n, dir, b ;
REAL d ;
c3v_set ( 0.0, 0.0, 1.0, n ) ;
c3v_set ( 1.0, 1.0, 1.0, dir ) ;
d = 0.0 ; /* plane z = 0 */
c3v_set ( 2.0, 3.0, 4.0, a ) ;
c3v_project_pt_oblique ( a, n, d, dir, b
);
}
This
routine computes oblique projection of the point ( 2.0, 3.0, 4.0 ) onto
the x-y
plane ( plane z=0 ).
***>>
c3v_project_vec_normal <<***
******
Summary ******
#include
<c3vdefs.h>
REAL *
c3v_project_vec_normal ( a, n, b );
******
Description ******
This
function projects a vector onto a plane along the normal vector of the
plane.
The plane is defined with a normal vector and a distance from the
origin.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a | the vector to project |
------------------------------------------------------------------------------
|
PT3 | n | the normal vector of the |
| | | plane |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | b | the projection of the
vector |
| | | on the plane |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the output vector.
******
Example ******
#include
<c3vdefs.h>
void
main()
{
PT3 a, n, b ;
c3v_set ( 0.0, 0.0, 1.0, n ) ;
c3v_set ( 2.0, 3.0, 4.0, a ) ;
c3v_project_vec_normal ( a, n, b ) ;
}
This
routine computes projection of the vector ( 2.0, 3.0, 4.0 ) onto the
x-y
plane ( plane z=0 ). The result of this operation is b=(2.0, 3.0, 0.0).
***>>
c3v_project_vec_oblique <<***
******
Summary ******
#include
<c3vdefs.h>
BOOLEAN
c3v_project_vec_oblique ( a, normal, direction, b );
******
Description ******
This
function projects a vector onto a plane along a specified direction.
The
plane is defined with a normal vector and a distance from the origin.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a | the vector to project |
------------------------------------------------------------------------------
|
PT3 | n | the normal vector of
the |
| | | plane |
------------------------------------------------------------------------------
|
PT3 | direction | the projection direction |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | b | the projection of the
vector |
| | | on the plane |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the output vector. It
is NULL if the normal and
direction
vectors are perpendicular to each other.
******
Example ******
#include
<c3vdefs.h>
void
main()
{
PT3 a, n, dir, b ;
c3v_set ( 0.0, 0.0, 1.0, n ) ;
c3v_set ( 1.0, 1.0, 1.0, dir ) ;
c3v_set ( 2.0, 3.0, 4.0, a ) ;
c3v_project_vec_oblique ( a, n, dir, b ) ;
}
This
routine computes oblique projection of the vector ( 2.0, 3.0, 4.0 )
onto
the x-y plane ( plane z=0 ).
***>>
c3v_pt_on_plane <<***
******
Summary ******
#include
<c3vdefs.h>
BOOLEAN
c3v_pt_on_plane ( p, normal, dist );
******
Description ******
This
function determines if a point is on a plane.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | p | a 3D point |
------------------------------------------------------------------------------
|
PT3 | normal | the normal of the plane |
------------------------------------------------------------------------------
|
REAL | dist | the distance between the |
| | | origin and the plane along |
| | | the normal direction |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is TRUE if the point is within the plane by a distance less
than
the absolute tolerance. It is
FALSE otherwise.
******
Example ******
#include
<c3vdefs.h>
void
main ()
{
PT3 p0, p1, p2, p, n;
REAL dist ;
c3v_set ( 1.0, 0.0, 0.0, p0 ) ;
c3v_set ( 1.0, 1.0, 1.0, p1 ) ;
c3v_set ( -1.0, 1.0, -1.0, p2 ) ;
c3v_plane_3pts ( p0, p1, p2, n, &dist
);
printf ( "enter point
coordinates" );
scanf ( "%lf%lf%lf", p, p+1, p+2
);
if ( c3v_pt_on_plane ( p, n, dist ) )
printf ( "point is on plane\n"
);
}
This
program determines if a point is on a plane.
***>>
c3v_rotate_pt <<***
******
Summary ******
#include
<c3vdefs.h>
REAL*
c3v_rotate_pt ( a, origin, axis_vector, angle, b );
******
Description ******
This
function rotates a 3D point about an axis.
The axis is defined by a
point
and a direction. The angle must
specified in radians.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a | the point to rotate; it is |
| | | not affected by
this |
| | | operation |
------------------------------------------------------------------------------
|
PT3 | origin,
axis_vector | the point and the direction
|
| | | that define the
rotation |
| | | axis |
------------------------------------------------------------------------------
|
REAL | angle | the rotation angle; if it
is |
| | | positive, the rotation
is |
| | | counter-clockwise;
otherwise |
| | | it is clockwise; it must
be |
| | | specified in radians |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | b | the rotated point |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the output point.
******
Example ******
#include
<c3vdefs.h>
void
rotate_point ( p, p1 )
PT3 p,
p1;
{
PT3 o, v;
REAL angle;
printf ( "enter axis origin" );
scanf ( "%lf%lf%lf", o, o+1, o+2
);
printf ( "enter axis direction"
);
scanf ( "%lf%lf%lf", v, v+1, v+2
);
printf ( "enter rotation angle"
);
scanf ( "%lf", &angle );
angle *= PI_OVER_180;
c3v_rotate_pt ( p, o, v, angle, p1 );
}
This
function rotates a point about a specified axis.
***>>
c3v_rotate_pt_cs <<***
******
Summary ******
#include
<c3vdefs.h>
REAL*
c3v_rotate_pt_cs ( a, origin, axis_vector, c, s, b );
******
Description ******
This
function rotates a 3D point about an axis.
The axis is defined by an
origin
and an axis vector. The rotation angle
is specified with its cosine
and
sine.
By
reusing the sine and cosine values of the rotation angle, this function
rotates
groups of geometry more quickly than
c3v_rotate_pt.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a | the point to rotate; it
is |
| |
| not modified by this |
| | | function |
------------------------------------------------------------------------------
|
PT3 | origin,
axis_vector | the origin and axis vector
|
| | | of the rotation
axis |
------------------------------------------------------------------------------
|
REAL | c, s | the cosine and sine of the
|
| | | rotation angle |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | b | the rotated point |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the output point.
******
Example ******
#include
<c3vdefs.h>
void
rotate_point ( p, p1, p2, p3, p4 )
PT3 p,
p1, p2, p3, p4;
{
PT3 o, v;
REAL angle, s, c;
printf ( "enter axis origin" );
scanf ( "%lf%lf%lf", o, o+1, o+2
);
printf ( "enter axis direction"
);
scanf ( "%lf%lf%lf", v, v+1, v+2
);
printf ( "enter rotation angle"
);
scanf ( "%lf", &angle );
angle *= PI_OVER_180;
c = cos ( angle );
s = sin ( angle );
c3v_rotate_pt_cs ( p, o, v, c, s, p1 );
c3v_rotate_pt_cs ( p1, o, v, c, s, p2 );
c3v_rotate_pt_cs ( p2, o, v, c, s, p3 );
c3v_rotate_pt_cs ( p3, o, v, c, s, p4 );
}
This
function rotates a point about an axis.
The rotation computations are
more
efficient when c3v_rotate_pt_cs is used
instead of c3v_rotate_pt
because
the latter function must recompute the
sine and cosine of the
rotation
angle for each rotation.
***>>
c3v_rotate_vec <<***
******
Summary ******
#include
<c3vdefs.h>
REAL*
c3v_rotate_vec ( a, axis_vector, angle, b );
******
Description ******
This
function rotates a 3D vector about an axis.
The axis is defined by a
direction. The angle must specified in radians.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a | the vector to rotate; it
is |
| | | not affected by
this |
| | | operation |
------------------------------------------------------------------------------
|
PT3 |
axis_vector | the direction that
defines |
| | | the rotation axis |
------------------------------------------------------------------------------
|
REAL | angle | the rotation angle; if it
is |
| | | positive, the rotation
is |
| | | counter-clockwise; otherwise |
| | | it is clockwise; it must
be |
| | | specified in radians |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | b | the rotated vector |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the output vector.
******
Example ******
#include
<c3vdefs.h>
void
rotate_vector ( p, p1 )
PT3 p,
p1;
{
PT3 v;
REAL angle;
printf ( "enter axis direction"
);
scanf ( "%lf%lf%lf", v, v+1, v+2
);
printf ( "enter rotation angle"
);
scanf ( "%lf", &angle );
angle *= PI_OVER_180;
c3v_rotate_vec ( p, v, angle, p1 );
}
This
function rotates a vector about a specified axis.
***>>
c3v_rotate_vec_cs <<***
******
Summary ******
#include
<c3vdefs.h>
REAL*
c3v_rotate_vec_cs ( a, axis_vector, c, s, b );
******
Description ******
This
function rotates a 3D vector about an axis.
The axis is defined by an
axis
vector. The rotation angle is specified
with its cosine and sine.
By
reusing the sine and cosine values of the rotation angle, this function
rotates
groups of geometry more quickly than
c3v_rotate_vec.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a | the vector to rotate; it
is |
| | | not modified by
this |
| | | function |
------------------------------------------------------------------------------
|
PT3 |
axis_vector | the axis vector of
the |
| | | rotation axis |
------------------------------------------------------------------------------
|
REAL | c, s | the cosine and sine of
the |
| | | rotation angle |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | b | the rotated vector |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the output vector.
******
Example ******
#include
<c3vdefs.h>
void
rotate_vector ( p, p1, p2, p3, p4 )
PT3 p,
p1, p2, p3, p4;
{
PT3 v;
REAL angle, s, c;
printf ( "enter axis direction"
);
scanf ( "%lf%lf%lf", v, v+1, v+2
);
printf ( "enter rotation angle"
);
scanf ( "%lf", &angle );
angle *= PI_OVER_180;
c = cos ( angle );
s = sin ( angle );
c3v_rotate_vec_cs ( p, v, c, s, p1 );
c3v_rotate_vec_cs ( p1, v, c, s, p2 );
c3v_rotate_vec_cs ( p2, v, c, s, p3 );
c3v_rotate_vec_cs ( p3, v, c, s, p4 );
}
This
function rotates a vector about an axis.
The rotation computations are
more
efficient when c3v_rotate_vec_cs is used
instead of c3v_rotate_vec
because
the latter function must recompute the
sine and cosine of the
rotation
angle for each rotation.
***>>
c3v_scale <<***
******
Summary ******
#include
<c3vdefs.h>
REAL *
c3v_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 ******
------------------------------------------------------------------------------
|
PT3 | a | a vector |
------------------------------------------------------------------------------
|
REAL | t | a scale factor |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | b | the scaled vector |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the output vector.
******
Example ******
#include
<c3vdefs.h>
void
main()
{
PT3 vec ;
REAL scale = 2.0, x=1.0, y=2.0, z=3.0 ;
c3v_set ( x, y, z, vec ) ;
c3v_scale ( vec, scale, vec ) ;
}
This
program multiplies a vector by a scale factor. As a result of this
operation,
vec = ( 2.0, 4.0, 6.0 ) .
***>>
c3v_set <<***
******
Summary ******
#include
<c3vdefs.h>
REAL *
c3v_set(x,y,z,a);
******
Description ******
This
function sets the coordinate values of a vector.
******
Input ******
------------------------------------------------------------------------------
|
REAL | x, y, z
| coordinate values |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | a | vector initialized
with |
| | | coordinate values x,
y, and
|
| | | z. |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the output vector.
******
Example ******
#include
<c3vdefs.h>
void
main()
{
PT3 v ;
c3v_set ( 1., 2., 3., v ) ;
}
This
routine sets the vector v to ( 1.0,2.0,3.0)
***>>
c3v_set_spherical <<***
******
Summary ******
#include
<c3vdefs.h>
REAL *
c3v_set_spherical ( r, theta, phi, a );
******
Description ******
This
function sets the direction of a vector to the direction specified by a
set of
spherical coordinates.
******
Input ******
------------------------------------------------------------------------------
|
REAL | r, theta,
phi | the radius, the angle
about |
| |
| the z-axis from the x-z |
| | | plane, and the angle from |
| | | the z-axis of the
specified |
| | | direction |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | a | a vector with the specified |
| | | direction |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the output vector.
******
Example ******
#include
<c3vdefs.h>
void
main()
{
PT3 v ;
c3v_set_spherical ( 5.0, PI / 4.0, PI/
4.0, v ) ;
}
This
routine creates a vector with length 5.0, rotated about the z- axis by
45
degrees from the x-z plane, and rotated down from the z- axis by 45
degrees.
***>>
c3v_set_zero <<***
******
Summary ******
#include
<c3vdefs.h>
REAL *
c3v_set_zero(a);
******
Description ******
This
function sets all coordinates of a vector to zero.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a | a vector |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the input vector.
******
Example ******
#include
<c3vdefs.h>
void
main()
{
PT3 v ;
c3v_set_zero ( v ) ;
}
This
routine sets the vector v to ( 0.0, 0.0, 0.0 ).
***>>
c3v_spherical <<***
******
Summary ******
#include
<c3vdefs.h>
void
c3v_spherical ( a, r, theta, phi );
******
Description ******
This
function computes the spherical coordinates of a point.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a | a 3D point |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
| REAL
* | r | spherical radius; not |
| | | computed if NULL |
------------------------------------------------------------------------------
| REAL
* | theta | the angle between the
x-axis |
| | | and vector from the
origin |
| | | to the projection of the |
| | | point onto the x-y
plane; |
| | | not computed if
NULL |
------------------------------------------------------------------------------
| REAL
* | phi | the angle between the
z-axis |
| | | and the vector from
the |
| | | origin to the point; not |
| | | computed if NULL |
------------------------------------------------------------------------------
******
Example ******
#include
<c3vdefs.h>
void
print_spherical ( p )
PT3 p ;
{
REAL r, theta, phi ;
c3v_spherical ( p, &r, &theta,
&phi ) ;
printf ( "r theta phi: %lf %lf
%lf\n",
r, theta, phi );
}
This
routine prints out the spherical coordinates of a point.
***>>
c3v_sub <<***
******
Summary ******
#include
<c3vdefs.h>
REAL *
c3v_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 ******
------------------------------------------------------------------------------
|
PT3 | a, b | vectors to subtract |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | c | difference of a and b |
------------------------------------------------------------------------------
******
Return Value ******
The return
value is the output vector.
******
Example ******
#include
<c3vdefs.h>
void
print_difference ( vec1, vec2 )
PT3
vec1, vec2 ;
{
PT3 diff ;
c3v_sub ( vec1, vec2, diff ) ;
printf ( "the difference vector is:
%lf %lf %lf\n",
diff[0], diff[1], diff[2] ) ;
}
This
routine prints out the difference of two vectors.
***>>
c3v_triple_prod <<***
******
Summary ******
#include
<c3vdefs.h>
REAL
c3v_triple_prod ( a, b, c );
******
Description ******
This
function computes the triple product of three vectors. This
quantity
is
defined by the following expression:
triple_product
= a[0] * ( b[1] * c[2] - b[2] * c[1] ) +
a[1] * ( b[2] * c[0] - b[0] * c[2] ) +
a[2] * ( b[0] * c[1] - b[1] * c[0] );
It is
also equivalent to the dot product of a with the cross product of b
and c,
or the dot product of the cross product
of a and b with c.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a, b, c | three vectors |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the triple product of the three input vectors.
******
Example ******
#include
<c3vdefs.h>
void
print_triple_product
( vec1, vec2, vec3 )
PT3
vec1, vec2, vec3 ;
{
REAL triple_prod ;
triple_prod = c3v_triple_prod ( vec1,
vec2, vec3 ) ;
printf ( "Triple product of vec1,
vec2 and vec3 is " ) ;
printf ( "%lf.\n", triple_prod )
;
}
This
routine prints out the coordinates of the triple product of three
vectors.
@NEWPAGE
=
***>>
c3v_unit_normal <<***
******
Summary ******
#include
<c3vdefs.h>
BOOLEAN
c3v_unit_normal ( a, b, c );
******
Description ******
This
function computes a unit vector which is perpendicular to two given
vectors. The resulting vector is obtained by
normalizing the cross product
of the
first vector with the second.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a, b | two vectors |
------------------------------------------------------------------------------
******
Output ******
------------------------------------------------------------------------------
|
PT3 | c | a unit vector which
is |
| | | perpendicular to the
two |
| | | input vectors |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is TRUE if the unit vector could be constructed. Otherwise
it
returns FALSE.
******
Example ******
#include
<c3vdefs.h>
void
compute_normal ( c )
PT3 c;
{
PT3 a, b;
printf ( "enter a: " );
scanf ( "%lf%lf%lf", a, a+1, a+2
);
printf ( "enter b: " );
scanf ( "%lf%lf%lf", b, b+1, b+2
);
c3v_unit_normal ( a, b, c );
}
This
function constructs the vector orthogonal to two specified vectors.
***>>
c3v_vec_on_plane <<***
******
Summary ******
#include
<c3vdefs.h>
REAL
c3v_vec_on_plane ( vec, normal );
******
Description ******
This
function determines if a vector is parallel to a plane.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | vec | a 3D vector |
------------------------------------------------------------------------------
|
PT3 | normal | the normal of the plane |
------------------------------------------------------------------------------
******
Return Value ******
The return
value is TRUE if the vector lies parallel to the set of planes
with
the specified normal. It is FALSE otherwise.
******
Example ******
#include
<c3vdefs.h>
void
main ()
{
REAL dist ;
PT3 p0, p1, p2, v, n;
c3v_set ( 1.0, 0.0, 0.0, p0 ) ;
c3v_set ( 1.0, 1.0, 1.0, p1 ) ;
c3v_set ( -1.0, 1.0, -1.0, p2 ) ;
c3v_plane_3pts ( p0, p1, p2, n, &dist
);
printf ( "enter vector
coordinates" );
scanf ( "%lf%lf%lf", v, v+1, v+2
);
if ( c3v_vec_on_plane ( v, n ) )
printf ( "vector is parallel to
plane\n" );
}
This
program determines if a vector is parallel to a plane.
***>>
c3v_vecs_angle <<***
******
Summary ******
#include
<c3vdefs.h>
REAL
c3v_vecs_angle ( a, b );
******
Description ******
This
function computes the angle between two vectors. The result is
expressed
in radians, and falls between 0 and two pi.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a, b | two vectors |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the angle between the two input vectors.
******
Example ******
#include
<c3vdefs.h>
void
print_angle ( vec1, vec2 )
PT3
vec1, vec2 ;
{
REAL angle ;
angle = c3v_vecs_angle ( vec1, vec2 ) ;
printf ( "angle between the vectors
is %lf.\n", angle ) ;
}
This
subroutine prints the angle between two vectors.
***>>
c3v_vecs_cos <<***
******
Summary ******
#include
<c3vdefs.h>
REAL
c3v_vecs_cos ( a, b );
******
Description ******
This
function computes the cosine of the angle between two vectors.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a, b | two vectors |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the cosine of the angle between two vectors.
******
Example ******
#include
<c3vdefs.h>
void
print_cosine ( vec1, vec2 )
PT3
vec1, vec2 ;
{
REAL cosine ;
cosine = c3v_vecs_cos ( vec1, vec2 ) ;
printf ( "cosine of the angle"
);
printf ( "between the vectors is
%lf.\n", cosine ) ;
}
This
subroutine prints the cosine of the angle between two vectors.
***>>
c3v_vecs_parallel <<***
******
Summary ******
#include
<c3vdefs.h>
BOOLEAN
c3v_vecs_parallel ( a, b );
******
Description ******
This
function determines if two vectors are parallel. Two vectors are
considered
parallel if the absolute value of the sine of the angle between
them is
less than or equal to the relative
tolerance.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a,b | two vectors |
------------------------------------------------------------------------------
******
Return Value ******
This
function returns TRUE if the vectors are paralled, and FALSE if the
vectors
are not parellel.
******
Example ******
#include
<c3vdefs.h>
void
check_parallel ( vec1, vec2 )
PT3
vec1, vec2 ;
{
if ( c3v_vecs_parallel ( vec1, vec2 ) )
printf ( "vectors are
parallel\n" ) ;
else
printf ( "vectors are not
parallel\n" ) ;
}
This
subroutine reports if two vectors are parallel.
***>>
c3v_vecs_sin <<***
******
Summary ******
#include
<c3vdefs.h>
REAL
c3v_vecs_sin ( a, b );
******
Description ******
This
function computes the sine of the angle between two vectors.
******
Input ******
------------------------------------------------------------------------------
|
PT3 | a, b | two vectors |
------------------------------------------------------------------------------
******
Return Value ******
The
return value is the sine of the angle between the two input vectors.
******
Example ******
#include
<c3vdefs.h>
void
print_sine ( vec1, vec2 )
PT3
vec1, vec2 ;
{
REAL sine ;
sine = c3v_vecs_sin ( vec1, vec2 ) ;
printf ( "sine of the angle between
" );
printf ( "the vectors is
%lf.\n", sine ) ;
}
This
subroutine prints the sine of the angle between two vectors.