-
Notifications
You must be signed in to change notification settings - Fork 34
/
ICurveFieldGeo.java
160 lines (129 loc) · 5.1 KB
/
ICurveFieldGeo.java
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*---
iGeo - http://igeo.jp
Copyright (c) 2002-2013 Satoru Sugihara
This file is part of iGeo.
iGeo is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, version 3.
iGeo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with iGeo. If not, see <http://www.gnu.org/licenses/>.
---*/
package igeo;
/**
3D vector filed defined by a NURBS curve.
@author Satoru Sugihara
*/
public class ICurveFieldGeo extends IFieldGeo implements I3DFieldI{
public ICurveI curve;
public ICurveI fieldCurve;
public ICurveFieldGeo(ICurveI crv, ICurveI fieldCrv){ curve = crv; fieldCurve = fieldCrv; }
/** get original field value out of curve parameter u */
public IVecI get(IVecI v, double u){ return fieldCurve.pt(u); }
/** get original field value out of curve parameter u */
public IVecI get(IVecI pos, IVecI v, double u){ return get(pos,u); }
//public IVecI get(double u){ return fieldCurve.tan(u).len(100); }
/** get 3D vector field value */
public IVecI get(IVecI v){ return get(v,null); }
/** get 3D vector field value */
public IVecI get(IVecI pos, IVecI vel){
double u = curve.u(pos);
double r = intensity;
if(decay == Decay.Linear){
double dist = curve.pt(u).dist(pos);
if(dist >= threshold) return new IVec(); // zero
if(threshold>0) r *= (threshold-dist)/threshold;
}
else if(decay == Decay.Gaussian){
double dist = curve.pt(u).dist(pos);
if(threshold>0) r *= Math.exp(-2*dist*dist/(threshold*threshold));
}
else if(decay == Decay.Custom && customDecay!=null){
double dist = curve.pt(u).dist(pos);
r = customDecay.decay(intensity, dist, threshold);
}
IVecI vec = get(pos,vel,u);
if(bidirectional && vec.get().dot(vel) < 0){ r=-r; }
if(constantIntensity){
double len = vec.len();
if(len<IConfig.tolerance){ return vec.zero(); }
return vec.len(r);
}
return vec.mul(r);
/*
switch(decay){
case None:{
if(constantIntensity){
IVecI vec = get(v,curve.u(v));
double len = vec.len();
if(len<IConfig.tolerance){ return vec.zero(); }
return vec.len(intensity);
}
return get(v,curve.u(v)).mul(intensity); // variable intensity
}
case Linear:{
double u = curve.u(v);
double dist = curve.pt(u).dist(v);
if(dist >= threshold) return new IVec(); // zero
if(constantIntensity){
IVecI vec = get(v,u);
double len = vec.len();
if(len<IConfig.tolerance){ return vec.zero(); }
return vec.len(intensity*dist/threshold);
}
return get(v,u).mul(intensity*dist/threshold);
}
case Gaussian:{
double u = curve.u(v);
double dist = curve.pt(u).dist(v);
if(constantIntensity){
IVecI vec = get(v,u);
double len = vec.len();
if(len<IConfig.tolerance){ return vec.zero(); }
return vec.len(intensity*Math.exp(-2*dist*dist/(threshold*threshold)));
}
return get(v,u).mul(intensity*Math.exp(-2*dist*dist/(threshold*threshold)));
}
}
return new IVec(); // should not reach here.
*/
}
/** if output vector is besed on constant length (intensity) or variable depending geometry when curve or surface tangent is used */
public ICurveFieldGeo constantIntensity(boolean b){ super.constantIntensity(b); return this; }
/** if bidirectional is on, field force vector is flipped when velocity of particle is going opposite */
public ICurveFieldGeo bidirectional(boolean b){ super.bidirectional(b); return this; }
/** set no decay */
public ICurveFieldGeo noDecay(){ super.noDecay(); return this; }
/** set linear decay; When distance is equal to threshold, output is zero.*/
public ICurveFieldGeo linearDecay(double threshold){
super.linearDecay(threshold); return this;
}
public ICurveFieldGeo linear(double threshold){
super.linear(threshold); return this;
}
/** set Gaussian decay; Threshold is used as double of standard deviation (when distance is eqaul to threshold, output is 13.5% of original).
*/
public ICurveFieldGeo gaussianDecay(double threshold){
super.gaussianDecay(threshold); return this;
}
public ICurveFieldGeo gaussian(double threshold){
super.gaussian(threshold); return this;
}
public ICurveFieldGeo gauss(double threshold){
super.gauss(threshold); return this;
}
public ICurveFieldGeo threshold(double t){ super.threshold(t); return this; }
public ICurveFieldGeo intensity(double i){ super.intensity(i); return this; }
public void del(){
if(curve!=null && curve==fieldCurve){
if(curve instanceof IObject){ ((IObject)curve).del(); }
}
else{
if(curve!=null && curve instanceof IObject){ ((IObject)curve).del(); }
if(fieldCurve!=null && fieldCurve instanceof IObject){ ((IObject)fieldCurve).del(); }
}
}
}