The Cuik KD-Tree Library


vector.c
Go to the documentation of this file.
1 #include "vector.h"
2 
3 #include "definitions.h"
4 
5 #include <assert.h>
6 
17 double VectorSquaredDistanceTopologyMin(double t2,unsigned int s,unsigned int *tp,
18  double *v1,double *v2)
19 {
20  unsigned int i;
21  double n,v;
22 
23  n=0.0;
24  if (tp==NULL)
25  {
26  for(i=0;((i<s)&&(n<t2));i++)
27  {
28  v=v1[i]-v2[i];
29  n+=(v*v);
30  }
31  }
32  else
33  {
34  for(i=0;((i<s)&&(n<t2));i++)
35  {
36  v=v1[i]-v2[i];
37  if ((tp[i]==TOPOLOGY_S)&&((v<-M_PI)||(v>M_PI)))
38  PI2PI(v);
39  n+=(v*v);
40  }
41  }
42  return(n);
43 }
44 
45 double VectorNorm(unsigned int s,double *v)
46 {
47  unsigned int i;
48  double n;
49 
50  n=0.0;
51  for(i=0;i<s;i++)
52  n+=(v[i]*v[i]);
53  n=sqrt(n);
54 
55  return(n);
56 }
57 
58 void VectorNormalize(unsigned int s,double *v)
59 {
60  unsigned int i;
61  double n;
62 
63  n=VectorNorm(s,v);
64 
65  assert(n>1e-6);
66 
67  for(i=0;i<s;i++)
68  v[i]/=n;
69 }
double VectorNorm(unsigned int s, double *v)
Norm of a vector.
Definition: vector.c:45
void VectorNormalize(unsigned int s, double *v)
Normalizes a vector.
Definition: vector.c:58
#define PI2PI(a)
Forces an angle go be in [-pi,pi].
Definition: definitions.h:75
Definition of constants and macros used in several parts of the library.
#define TOPOLOGY_S
One of the possible topologies.
Definition: definitions.h:188
Definition of basic operations between points.
#define M_PI
Pi.
Definition: definitions.h:24
double VectorSquaredDistanceTopologyMin(double t2, unsigned int s, unsigned int *tp, double *v1, double *v2)
Computes the squared distance of two points.
Definition: vector.c:17