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-2012 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  * version 2.1 as published by the Free Software Foundation.
00010  *
00011  * This library is distributed in the hope that it will be useful, but
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this file; see the file named COPYING for more
00018  * information.
00019  */
00020 /** @addtogroup plot */
00021 /** @{ */
00022 /** @file libbn/vector.c
00023  *
00024  */
00025 
00026 #include "common.h"
00027 
00028 #include <stdio.h>
00029 #include <math.h>
00030 
00031 #include "vmath.h"
00032 #include "plot3.h"
00033 #include "bu.h"
00034 #include "bn.h"
00035 
00036 /**
00037  * T P _ 3 V E C T O R
00038  *@brief
00039  * Draw a vector between points "from" and "to", with the option of
00040  * having an arrowhead on either or both ends.
00041  *
00042  * The fromheadfract and toheadfract values indicate the length of the
00043  * arrowheads relative to the length of the vector to-from.  A typical
00044  * value is 0.1, making the head 10% of the size of the vector.  The
00045  * sign of the "fract" values indicates the pointing direction.
00046  * Positive points towards the "to" point, negative points towards
00047  * "from".  Upon return, the virtual pen is left at the "to" position.
00048  */
00049 void
00050 tp_3vector(FILE *plotfp, fastf_t *from, fastf_t *to, double fromheadfract, double toheadfract)
00051 {
00052     register fastf_t len;
00053     register fastf_t hooklen;
00054     vect_t diff;
00055     vect_t c1, c2;
00056     vect_t h1, h2;
00057     vect_t backup;
00058     point_t tip;
00059 
00060     pdv_3line(plotfp, from, to);
00061     /* "pen" is left at "to" position */
00062 
00063     VSUB2(diff, to, from);
00064     if ((len = MAGNITUDE(diff)) < SMALL)  return;
00065     VSCALE(diff, diff, 1/len);
00066     bn_vec_ortho(c1, diff);
00067     VCROSS(c2, c1, diff);
00068 
00069     if (!ZERO(fromheadfract)) {
00070         hooklen = fromheadfract*len;
00071         VSCALE(backup, diff, -hooklen);
00072 
00073         VSCALE(h1, c1, hooklen);
00074         VADD3(tip, from, h1, backup);
00075         pdv_3move(plotfp, from);
00076         pdv_3cont(plotfp, tip);
00077 
00078         VSCALE(h2, c2, hooklen);
00079         VADD3(tip, from, h2, backup);
00080         pdv_3move(plotfp, tip);
00081     }
00082     if (!ZERO(toheadfract)) {
00083         hooklen = toheadfract*len;
00084         VSCALE(backup, diff, -hooklen);
00085 
00086         VSCALE(h1, c1, hooklen);
00087         VADD3(tip, to, h1, backup);
00088         pdv_3move(plotfp, to);
00089         pdv_3cont(plotfp, tip);
00090 
00091         VSCALE(h2, c2, hooklen);
00092         VADD3(tip, to, h2, backup);
00093         pdv_3move(plotfp, tip);
00094     }
00095     /* Be certain "pen" is left at "to" position */
00096     if (!ZERO(fromheadfract) || !ZERO(toheadfract))
00097         pdv_3cont(plotfp, to);
00098 
00099 }
00100 
00101 void
00102 PL_FORTRAN(f3vect, F3VECT)(FILE **fp, float *fx, float *fy, float *fz, float *tx, float *ty, float *tz, float *fl , float *tl)
00103 {
00104     point_t from, to;
00105 
00106     VSET(from, *fx, *fy, *fz);
00107     VSET(to, *tx, *ty, *tz);
00108     tp_3vector(*fp, from, to, *fl, *tl);
00109 }
00110 
00111 /** @} */
00112 /*
00113  * Local Variables:
00114  * mode: C
00115  * tab-width: 8
00116  * indent-tabs-mode: t
00117  * c-file-style: "stroustrup"
00118  * End:
00119  * ex: shiftwidth=4 tabstop=8
00120  */
Generated on Tue Dec 11 13:14:28 2012 for LIBBN by  doxygen 1.6.3