00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00031 #include <stdio.h>
00032 #include <stdlib.h>
00033 #include <string.h>
00034 #include <math.h>
00035
00036
00037
00043 void normalize_vector(float u[3])
00044 {
00045 float d=sqrt(u[0]*u[0]+u[1]*u[1]+u[2]*u[2]);
00046 u[0]/=d;
00047 u[1]/=d;
00048 u[2]/=d;
00049 }
00050
00058 float scalar_product(float u[3], float v[3])
00059 {
00060 float p=u[0]*v[0]+u[1]*v[1]+u[2]*v[2];
00061 return p;
00062 }
00063
00071 void vectorial_product(float u[3], float v[3], float w[3])
00072 {
00073 w[0]=u[1]*v[2]-u[2]*v[1];
00074 w[1]=u[2]*v[0]-u[0]*v[2];
00075 w[2]=u[0]*v[1]-u[1]*v[0];
00076 }
00077
00085 float vector_norm(float u[3])
00086 {
00087 float d=sqrt(u[0]*u[0]+u[1]*u[1]+u[2]*u[2]);
00088 return d;
00089 }
00090
00101 float **sample_arclength(float A[3], float B[3], float O[3], int npoints)
00102 {
00103 float **P;
00104 float u[3], v[3], vv[3], w[3];
00105 float unorm, vvnorm, R, x, y;
00106 float angmax, stepang;
00107
00108 if (npoints == 1) return NULL;
00109
00110
00111 P=new float*[npoints];
00112 for (int n=0; n < npoints; n++) P[n]=new float[3];
00113
00114
00115 u[0]=A[0]-O[0];
00116 u[1]=A[1]-O[1];
00117 u[2]=A[2]-O[2];
00118 unorm=vector_norm(u);
00119
00120 vv[0]=B[0]-O[0];
00121 vv[1]=B[1]-O[1];
00122 vv[2]=B[2]-O[2];
00123 vvnorm=vector_norm(vv);
00124
00125
00126 R=unorm;
00127
00128
00129 angmax=acos((double) (scalar_product(u, vv)/(unorm*vvnorm)));
00130
00131
00132 normalize_vector(u);
00133 normalize_vector(vv);
00134 vectorial_product(u, vv, w);
00135 normalize_vector(w);
00136
00137 vectorial_product(w, u, v);
00138 normalize_vector(v);
00139
00140
00141
00142 stepang=angmax/(npoints-1);
00143
00144
00145
00146 P[0][0]=A[0];
00147 P[0][1]=A[1];
00148 P[0][2]=A[2];
00149 for (int n=1; n < npoints-1; n++) {
00150 x=R*cos((double) (n*stepang));
00151 y=R*sin((double) (n*stepang));
00152 P[n][0]=O[0]+x*u[0]+y*v[0];
00153 P[n][1]=O[1]+x*u[1]+y*v[1];
00154 P[n][2]=O[2]+x*u[2]+y*v[2];
00155 }
00156
00157 P[npoints-1][0]=B[0];
00158 P[npoints-1][1]=B[1];
00159 P[npoints-1][2]=B[2];
00160
00161
00162 return P;
00163 }
00164
00172 void delete_list3D(float **points, int npoints)
00173 {
00174 for (int n=0; n < npoints; n++) delete[] points[n];
00175 delete[] points;
00176 }
00177
00178