-
Notifications
You must be signed in to change notification settings - Fork 0
/
euclid.cpp
65 lines (57 loc) · 1.73 KB
/
euclid.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*============================================================================
* Daniel J. Greenhoe
* alpha-scaled Euclidean metric routines
*============================================================================*/
/*=====================================
* headers
*=====================================*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<main.h>
#include<r1.h>
#include<r2.h>
#include<r3.h>
#include<r6.h>
#include<euclid.h>
/*-------------------------------------------------------------------------
* alpha-scaled Euclidean metric from <p> to <q>
*-------------------------------------------------------------------------*/
double ae_metric(double alpha, vectR2 p, vectR2 q){
vectR2 pq=p-q;
double d=pq.mag();
double ds=d*alpha;
return ds;
}
double ae_metric(double alpha, vectR3 p, vectR3 q){
vectR3 pq=p-q;
double d=pq.mag();
double ds=d*alpha;
return ds;
}
double ae_metric(double alpha, vectR6 p, vectR6 q){
vectR6 pq=p-q;
double d=pq.mag();
double ds=d*alpha;
return ds;
}
/*-------------------------------------------------------------------------
* Find the polar length of a point q with radial measure tq that is a
* distance <d> from the point <p> with polar coordinates (rp,tp)
* using search resolution <N>
*-------------------------------------------------------------------------*/
vectR3 ae_findq(double alpha, vectR3 p, double theta, double phi, double d, long int N){
double smallesterror=100000,rq,dd,errord;
vectR3 bestq;
vectR3 q;
for(rq=0; rq<=5; rq+=5.0/N){
q.polartoxyz(rq,theta,phi);
dd=ae_metric(alpha,p,q);
errord=fabs(d-dd);
if(errord<smallesterror){
bestq=q;
smallesterror=errord;
}
}
return bestq;
}