vector.c

Go to the documentation of this file.
00001 /*                        V E C T O R . C
00002  * BRL-CAD
00003  *
00004  * Copyright (c) 2004-2006 United States Government as represented by
00005  * the U.S. Army Research Laboratory.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License
00009  * as published by the Free Software Foundation; either version 2 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this file; see the file named COPYING for more
00019  * information.
00020  */
00021 
00022 /** \addtogroup plot */
00023 /*@{*/
00024 /** @file vector.c
00025  *
00026  *  @author
00027  *      Michael John Muuss
00028  *
00029  *  @par Source
00030  *      SECAD/VLD Computing Consortium, Bldg 394
00031  *@n    The U. S. Army Ballistic Research Laboratory
00032  *@n    Aberdeen Proving Ground, Maryland  21005-5066
00033  *
00034  */
00035 
00036 
00037 #ifndef lint
00038 static const char RCSid[] = "@(#)$Header: /cvsroot/brlcad/brlcad/src/libbn/vector.c,v 14.11 2006/09/07 01:19:17 lbutler Exp $ (BRL)";
00039 #endif
00040 
00041 #include "common.h"
00042 
00043 
00044 
00045 #include <stdio.h>
00046 #include <math.h>
00047 
00048 #include "machine.h"
00049 #include "vmath.h"
00050 #include "plot3.h"
00051 #include "bu.h"
00052 #include "bn.h"
00053 
00054 /**
00055  *                      T P _ 3 V E C T O R
00056  *@brief
00057  *  Draw a vector between points "from" and "to", with the option
00058  *  of having an arrowhead on either or both ends.
00059  *
00060  *  The fromheadfract and toheadfract values indicate the length
00061  *  of the arrowheads relative to the length of the vector to-from.
00062  *  A typical value is 0.1, making the head 10% of the size of the vector.
00063  *  The sign of the "fract" values indicates the pointing direction.
00064  *  Positive points towards the "to" point, negative points towards "from".
00065  *  Upon return, the virtual pen is left at the "to" position.
00066  */
00067 void
00068 tp_3vector(FILE *plotfp, fastf_t *from, fastf_t *to, double fromheadfract, double toheadfract)
00069 {
00070         register fastf_t        len;
00071         register fastf_t        hooklen;
00072         vect_t  diff;
00073         vect_t  c1, c2;
00074         vect_t  h1, h2;
00075         vect_t  backup;
00076         point_t tip;
00077 
00078         pdv_3line( plotfp, from, to );
00079         /* "pen" is left at "to" position */
00080 
00081         VSUB2( diff, to, from );
00082         if( (len = MAGNITUDE(diff)) < SMALL )  return;
00083         VSCALE( diff, diff, 1/len );
00084         bn_vec_ortho( c1, diff );
00085         VCROSS( c2, c1, diff );
00086 
00087         if( fromheadfract != 0 )  {
00088                 hooklen = fromheadfract*len;
00089                 VSCALE( backup, diff, -hooklen );
00090 
00091                 VSCALE( h1, c1, hooklen );
00092                 VADD3( tip, from, h1, backup );
00093                 pdv_3move( plotfp, from );
00094                 pdv_3cont( plotfp, tip );
00095 
00096                 VSCALE( h2, c2, hooklen );
00097                 VADD3( tip, from, h2, backup );
00098                 pdv_3move( plotfp, tip );
00099         }
00100         if( toheadfract != 0 )  {
00101                 hooklen = toheadfract*len;
00102                 VSCALE( backup, diff, -hooklen );
00103 
00104                 VSCALE( h1, c1, hooklen );
00105                 VADD3( tip, to, h1, backup );
00106                 pdv_3move( plotfp, to );
00107                 pdv_3cont( plotfp, tip );
00108 
00109                 VSCALE( h2, c2, hooklen );
00110                 VADD3( tip, to, h2, backup );
00111                 pdv_3move( plotfp, tip );
00112         }
00113         /* Be certain "pen" is left at "to" position */
00114         if( fromheadfract != 0 || toheadfract != 0 )
00115                 pdv_3cont( plotfp, to );
00116 
00117 }
00118 
00119 void
00120 PL_FORTRAN(f3vect, F3VECT)(fp, fx, fy, fz, tx, ty, tz, fl, tl )
00121 FILE    **fp;
00122 float   *fx;
00123 float   *fy;
00124 float   *fz;
00125 float   *tx;
00126 float   *ty;
00127 float   *tz;
00128 float   *fl;
00129 float   *tl;
00130 {
00131         point_t from, to;
00132 
00133         VSET( from, *fx, *fy, *fz );
00134         VSET( to, *tx, *ty, *tz );
00135         tp_3vector( *fp, from, to, *fl, *tl );
00136 }
00137 
00138 /*@}*/
00139 /*
00140  * Local Variables:
00141  * mode: C
00142  * tab-width: 8
00143  * c-basic-offset: 4
00144  * indent-tabs-mode: t
00145  * End:
00146  * ex: shiftwidth=4 tabstop=8
00147  */

Generated on Mon Sep 18 01:24:47 2006 for BRL-CAD by  doxygen 1.4.6