Back to index

radiance  4R0+20100331
Functions | Variables
fvect.c File Reference
#include "copyright.h"
#include <math.h>
#include "fvect.h"

Go to the source code of this file.

Functions

double fdot (FVECT v1, FVECT v2)
double dist2 (FVECT p1, FVECT p2)
double dist2line (FVECT p, FVECT ep1, FVECT ep2)
double dist2lseg (FVECT p, FVECT ep1, FVECT ep2)
void fcross (FVECT vres, FVECT v1, FVECT v2)
void fvsum (FVECT vres, FVECT v0, FVECT v1, double f)
double normalize (FVECT v)
int closestapproach (RREAL t[2], FVECT rorg0, FVECT rdir0, FVECT rorg1, FVECT rdir1)
void spinvector (FVECT vres, FVECT vorig, FVECT vnorm, double theta)

Variables

static const char RCSid [] = "$Id: fvect.c,v 2.11 2009/05/07 21:38:35 greg Exp $"

Function Documentation

int closestapproach ( RREAL  t[2],
FVECT  rorg0,
FVECT  rdir0,
FVECT  rorg1,
FVECT  rdir1 
)

Definition at line 136 of file fvect.c.

{
       double dotprod = DOT(rdir0, rdir1);
       double denom = 1. - dotprod*dotprod;
       double o1o2_d1;
       FVECT  o0o1;

       if (denom <= FTINY) {              /* check if lines are parallel */
              t[0] = t[1] = 0.0;
              return(0);
       }
       VSUB(o0o1, rorg0, rorg1);
       o1o2_d1 = DOT(o0o1, rdir1);
       t[0] = (o1o2_d1*dotprod - DOT(o0o1,rdir0)) / denom;
       t[1] = o1o2_d1 + t[0]*dotprod;
       return(1);
}
double dist2 ( FVECT  p1,
FVECT  p2 
)

Definition at line 25 of file fvect.c.

{
       FVECT  delta;

       delta[0] = p2[0] - p1[0];
       delta[1] = p2[1] - p1[1];
       delta[2] = p2[2] - p1[2];

       return(DOT(delta, delta));
}

Here is the caller graph for this function:

double dist2line ( FVECT  p,
FVECT  ep1,
FVECT  ep2 
)

Definition at line 41 of file fvect.c.

{
       double  d, d1, d2;

       d = dist2(ep1, ep2);
       d1 = dist2(ep1, p);
       d2 = d + d1 - dist2(ep2, p);

       return(d1 - 0.25*d2*d2/d);
}

Here is the call graph for this function:

Here is the caller graph for this function:

double dist2lseg ( FVECT  p,
FVECT  ep1,
FVECT  ep2 
)

Definition at line 58 of file fvect.c.

{
       double  d, d1, d2;

       d = dist2(ep1, ep2);
       d1 = dist2(ep1, p);
       d2 = dist2(ep2, p);

       if (d2 > d1) {                     /* check if past endpoints */
              if (d2 - d1 > d)
                     return(d1);
       } else {
              if (d1 - d2 > d)
                     return(d2);
       }
       d2 = d + d1 - d2;

       return(d1 - 0.25*d2*d2/d);  /* distance to line */
}

Here is the call graph for this function:

Here is the caller graph for this function:

void fcross ( FVECT  vres,
FVECT  v1,
FVECT  v2 
)

Definition at line 84 of file fvect.c.

{
       vres[0] = v1[1]*v2[2] - v1[2]*v2[1];
       vres[1] = v1[2]*v2[0] - v1[0]*v2[2];
       vres[2] = v1[0]*v2[1] - v1[1]*v2[0];
}

Here is the caller graph for this function:

double fdot ( FVECT  v1,
FVECT  v2 
)

Definition at line 15 of file fvect.c.

{
       return(DOT(v1,v2));
}

Here is the caller graph for this function:

void fvsum ( FVECT  vres,
FVECT  v0,
FVECT  v1,
double  f 
)

Definition at line 97 of file fvect.c.

{
       vres[0] = v0[0] + f*v1[0];
       vres[1] = v0[1] + f*v1[1];
       vres[2] = v0[2] + f*v1[2];
}

Here is the caller graph for this function:

double normalize ( FVECT  v)

Definition at line 111 of file fvect.c.

{
       double  len, d;
       
       d = DOT(v, v);
       
       if (d == 0.0)
              return(0.0);
       
       if (d <= 1.0+FTINY && d >= 1.0-FTINY)
              len = 0.5 + 0.5*d;   /* first order approximation */
       else
              len = sqrt(d);

       v[0] *= d = 1.0/len;
       v[1] *= d;
       v[2] *= d;

       return(len);
}
void spinvector ( FVECT  vres,
FVECT  vorig,
FVECT  vnorm,
double  theta 
)

Definition at line 162 of file fvect.c.

{
       double  sint, cost, normprod;
       FVECT  vperp;
       int  i;
       
       if (theta == 0.0) {
              if (vres != vorig)
                     VCOPY(vres, vorig);
              return;
       }
       cost = cos(theta);
       sint = sin(theta);
       normprod = DOT(vorig, vnorm)*(1.-cost);
       fcross(vperp, vnorm, vorig);
       for (i = 0; i < 3; i++)
              vres[i] = vorig[i]*cost + vnorm[i]*normprod + vperp[i]*sint;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const char RCSid[] = "$Id: fvect.c,v 2.11 2009/05/07 21:38:35 greg Exp $" [static]

Definition at line 2 of file fvect.c.