1 |
francois |
1061 |
#include "npoint.h" |
2 |
|
|
|
3 |
|
|
npoint::npoint(const npoint3 pt, const double w) |
4 |
|
|
{ |
5 |
|
|
for (int i=0;i<3;++i) coord[i]=pt[i]*w; |
6 |
|
|
coord[3]=w; |
7 |
|
|
} |
8 |
|
|
|
9 |
|
|
npoint::npoint(const npoint2 pt, const double w) |
10 |
|
|
{ |
11 |
|
|
for (int i=0;i<2;++i) coord[i]=pt[i]*w; |
12 |
|
|
coord[2]=0; |
13 |
|
|
coord[3]=w; |
14 |
|
|
} |
15 |
|
|
|
16 |
|
|
npoint::npoint(const double pt, const double w) |
17 |
|
|
{ |
18 |
|
|
coord[0]=pt*w; |
19 |
|
|
coord[1]=0; |
20 |
|
|
coord[2]=0; |
21 |
|
|
coord[3]=w; |
22 |
|
|
} |
23 |
|
|
|
24 |
|
|
npoint operator * (const double fact,const npoint other) |
25 |
|
|
{ |
26 |
|
|
npoint buf=other; |
27 |
|
|
for (int i=0;i<4;++i) buf[i]*=fact; |
28 |
|
|
return buf; |
29 |
|
|
} |
30 |
|
|
|
31 |
|
|
npoint3 crossprod(const npoint3 V1,const npoint3 V2) |
32 |
|
|
{ |
33 |
|
|
npoint3 buf; |
34 |
|
|
buf[0]=V1[1]* V2[2]-V1[2]* V2[1]; |
35 |
|
|
buf[1]=V1[2]* V2[0]-V1[0]* V2[2]; |
36 |
|
|
buf[2]=V1[0]* V2[1]-V1[1]* V2[0]; |
37 |
|
|
return buf; |
38 |
|
|
} |
39 |
|
|
|
40 |
|
|
|
41 |
|
|
npoint3 operator * (const double fact,const npoint3 other) |
42 |
|
|
{ |
43 |
|
|
npoint3 buf=other; |
44 |
|
|
for (int i=0;i<3;++i) buf[i]*=fact; |
45 |
|
|
return buf; |
46 |
|
|
} |
47 |
|
|
|
48 |
|
|
double operator * (const npoint3 p1, const npoint3 p2) |
49 |
|
|
{ |
50 |
|
|
double scalaire = p1.x() *p2.x() + p1.y() *p2.y() + p1.z() *p2.z(); |
51 |
|
|
|
52 |
|
|
return scalaire; |
53 |
|
|
|
54 |
|
|
} |
55 |
|
|
|
56 |
|
|
|
57 |
|
|
void npoint::print(std::ostream &os,int prec) const // sort les coordonees dans le flux os |
58 |
|
|
{ |
59 |
|
|
os.precision(prec); |
60 |
|
|
os.flags(std::ios::scientific); |
61 |
|
|
os<<coord[0]<<" "<<coord[1]<<" "<<coord[2]<<" "<<coord[3]; |
62 |
|
|
} |
63 |
|
|
|
64 |
|
|
void npoint3::print(std::ostream &os,int prec) const // sort les coordonees dans le flux os |
65 |
|
|
{ |
66 |
|
|
os.precision(prec); |
67 |
|
|
os.flags(std::ios::scientific); |
68 |
|
|
os<<coord[0]<<" "<<coord[1]<<" "<<coord[2]; |
69 |
|
|
} |
70 |
|
|
|
71 |
|
|
std::ostream& operator<<(std::ostream& stream, |
72 |
|
|
const npoint& pt) |
73 |
|
|
{ |
74 |
|
|
pt.print(stream,16); //assuming you define print for matrix |
75 |
|
|
return stream; |
76 |
|
|
} |
77 |
|
|
|
78 |
|
|
|
79 |
|
|
std::ostream& operator<<(std::ostream& stream, |
80 |
|
|
const npoint3& pt) |
81 |
|
|
{ |
82 |
|
|
pt.print(stream,16); //assuming you define print for matrix |
83 |
|
|
return stream; |
84 |
|
|
} |
85 |
|
|
|
86 |
|
|
npoint3::npoint3(const npoint2 p) |
87 |
|
|
{ |
88 |
|
|
coord[0]=p.u(); |
89 |
|
|
coord[1]=p.v(); |
90 |
|
|
coord[2]=0; |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
|
94 |
|
|
double crossprod(const npoint2 V1,const npoint2 V2) |
95 |
|
|
{ |
96 |
|
|
return V1[0]* V2[1]-V1[1]* V2[0]; |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
npoint2 operator * (const double fact,const npoint2 other) |
100 |
|
|
{ |
101 |
|
|
npoint2 buf=other; |
102 |
|
|
for (int i=0;i<2;++i) buf[i]*=fact; |
103 |
|
|
return buf; |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
double operator * (const npoint2 p1, const npoint2 p2) |
107 |
|
|
{ |
108 |
|
|
double scalaire = p1.u() *p2.u() + p1.v() *p2.v(); |
109 |
|
|
|
110 |
|
|
return scalaire; |
111 |
|
|
|
112 |
|
|
} |
113 |
|
|
|