-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtwojet.C
74 lines (63 loc) · 2 KB
/
twojet.C
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* Copyright 1995 Geometry Center, University of Minnesota.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "twojet.h"
TwoJet operator+(const TwoJet x, const TwoJet y) {
return TwoJet(x.f+y.f, x.fu+y.fu, x.fv+y.fv, x.fuv + y.fuv);
}
TwoJet operator*(const TwoJet x, const TwoJet y) {
return TwoJet(
x.f*y.f,
x.f*y.fu + x.fu*y.f,
x.f*y.fv + x.fv*y.f,
x.f*y.fuv + x.fu*y.fv + x.fv*y.fu + x.fuv*y.f
);
}
TwoJet operator+(const TwoJet x, double d) {
return TwoJet( x.f + d, x.fu, x.fv, x.fuv);
}
TwoJet operator*(const TwoJet x, double d) {
return TwoJet( d*x.f, d*x.fu, d*x.fv, d*x.fuv);
}
TwoJet Sin(const TwoJet x) {
TwoJet t = x*(2*M_PI);
double s = sin(t.f);
double c = cos(t.f);
return TwoJet(s, c*t.fu, c*t.fv, c*t.fuv - s*t.fu*t.fv);
}
TwoJet Cos(const TwoJet x) {
TwoJet t = x*(2*M_PI);
double s = cos(t.f);
double c = -sin(t.f);
return TwoJet(s, c*t.fu, c*t.fv, c*t.fuv - s*t.fu*t.fv);
}
TwoJet operator^(const TwoJet x, double n) {
double x0 = pow(x.f, n);
double x1 = (x.f == 0) ? 0 : n * x0/x.f;
double x2 = (x.f == 0) ? 0 : (n-1)*x1/x.f;
return TwoJet(x0, x1*x.fu, x1*x.fv, x1*x.fuv + x2*x.fu*x.fv);
}
TwoJet Annihilate(const TwoJet x, int index) {
return TwoJet(x.f, index == 1 ? x.fu : 0, index == 0 ? x.fv : 0, 0);
}
TwoJet Interpolate(const TwoJet v1, const TwoJet v2, const TwoJet weight) {
return (v1) * ((weight) * (-1) + 1) + v2*weight;
}
void printJet(const TwoJet v) {
printf("%f (%f %f)\n",
v.f,
v.fu, v.fv
);
}