Skip to content

Commit 42fb839

Browse files
committed
Added a curvature-dependent Interpolation delta
1 parent 8ee8240 commit 42fb839

File tree

4 files changed

+111
-17
lines changed

4 files changed

+111
-17
lines changed

TRA.Lib/Trasse.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,30 @@ internal TrassenElementExt GetElementFromPoint(double X, double Y)
158158
}
159159
return null;
160160
}
161-
162-
public Interpolation Interpolate(double delta = 1.0)
161+
/// <summary>
162+
/// Interpolate 2D Points allog the Trasse
163+
/// </summary>
164+
/// <param name="delta">distance along geometry between interpolation points</param>
165+
/// <param name="allowedTolerance">maximal allowed distance between geometry and interpolated polyline, if set to zero this value is ignored</param>
166+
/// <returns>Interpolation: array of 2D coordinates, along with heading and curvature for each point</returns>
167+
public Interpolation Interpolate(double delta = 1.0, double allowedTolerance = 0.01)
163168
{
164169
Interpolation interpolation = new Interpolation(0);
165170
foreach (TrassenElementExt element in Elemente)
166171
{
167-
interpolation.Concat(element.Interpolate(delta));
172+
interpolation.Concat(element.Interpolate(delta, allowedTolerance));
168173
}
169174
return interpolation;
170175
}
171-
public Interpolation Interpolate3D(TRATrasse stationierungsTrasse = null, double delta = 1.0)
176+
177+
/// <summary>
178+
/// Interpolate 3D Points allog the Trasse using .GRA for elevation interpolation
179+
/// </summary>
180+
/// <param name="stationierungsTrasse">optinal TrasseS to get mileage s. If nothing is set either a prvipusly set is used or values s from this Trasse are directly used (depending on the GRA-files this does not match)</param>
181+
/// <param name="delta">distance along geometry between interpolation points</param>
182+
/// <param name="allowedTolerance">maximal allowed distance between geometry and interpolated polyline, if set to zero this value is ignored</param>
183+
/// <returns>Interpolation: array of 3D coordinates, along with heading and curvature for each point</returns>
184+
public Interpolation Interpolate3D(TRATrasse stationierungsTrasse = null, double delta = 1.0, double allowedTolerance = 0.01)
172185
{
173186
Interpolation interp = new Interpolation(0);
174187
TRATrasse trasseS = stationierungsTrasse != null ? stationierungsTrasse : TrasseS; //if a valid trasse is provided use that one, else try to use a previously assigned
@@ -178,7 +191,7 @@ public Interpolation Interpolate3D(TRATrasse stationierungsTrasse = null, double
178191
}
179192
foreach (TrassenElementExt element in Elemente)
180193
{
181-
ref Interpolation Interpolation = ref element.Interpolate(delta);
194+
ref Interpolation Interpolation = ref element.Interpolate(delta, allowedTolerance);
182195
if (GradientenElemente == null)
183196
{
184197
interp.Concat(Interpolation);

TRA.Lib/TrassenElementExt.cs

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Globalization;
33
using System.Collections.ObjectModel;
44
using System.Collections.Specialized;
5+
using ScottPlot.Finance;
56

67
#if USE_SCOTTPLOT
78
using SkiaSharp;
@@ -236,21 +237,56 @@ void AddWarningCallout(string text, double X, double Y)
236237
WarningCallouts.Add(new GeometryWarning(text, X, Y,this));
237238
}
238239

239-
public ref Interpolation Interpolate(double delta = 1.0)
240+
/// <summary>
241+
/// Interpolate the underlying geometry
242+
/// </summary>
243+
/// <param name="delta">distance along geometry between interpolation points</param>
244+
/// <param name="allowedTolerance">maximal allowed distance between geometry and interpolated polyline, if set to zero this value is ignored</param>
245+
/// <returns>Interpolation: array of coordinates, along with heading and curvature for each point</returns>
246+
public ref Interpolation Interpolate(double delta = 1.0, double allowedTolerance = 0.001)
240247
{
241248
Transform2D transform = new Transform2D(x, y, t);
242249
if (TrassenGeometrie == null) { AddWarningCallout("No Gemetry for interpolation " + kz.ToString() + "set, maybe not implemented yet", Xstart,Ystart); return ref Interpolation; }
243250

244-
int num = (int)Math.Abs(l / delta);
245-
if (l < 0 && delta > 0) { delta = -delta; } //set delta negative for negative lengths
246-
Interpolation = new Interpolation(num + 1);
251+
List<double> Xlst = new List<double>();
252+
List<double> Ylst = new List<double>();
253+
List<double> Slst = new List<double>();
254+
List<double> Tlst = new List<double>();
255+
List<double> Klst = new List<double>();
247256

248-
for (int i = 0; i <= num; i++)
257+
double s_ = 0;
258+
double delta_ = delta;
259+
bool done = false;
260+
do
249261
{
250-
Interpolation.S[i] = S + i * delta;
251-
(Interpolation.X[i], Interpolation.Y[i], Interpolation.T[i], Interpolation.K[i]) = TrassenGeometrie.PointAt(i < num ? i * delta : l);
252-
if (transform != null) { transform.Apply(ref Interpolation.X[i], ref Interpolation.Y[i], ref Interpolation.T[i]); }
262+
double x_, y_, t_, k_;
263+
if (s_ > l) { s_ = l; done = true; }
264+
(x_, y_, t_, k_) = TrassenGeometrie.PointAt(s_);
265+
if (transform != null) { transform.Apply(ref x_, ref y_, ref t_); }
266+
Xlst.Add(x_);
267+
Ylst.Add(y_);
268+
Slst.Add(s_);
269+
Tlst.Add(t_);
270+
Klst.Add(k_);
271+
//Calc curvature dependent delta:
272+
if (k_ != 0 && allowedTolerance != 0)
273+
{
274+
double r = 1 / Math.Abs(k_);
275+
delta_ = 2 * r * Math.Acos(1 - (allowedTolerance / r));
276+
}
277+
else
278+
{
279+
delta_ = delta;
280+
}
281+
s_ = s_ + Math.Min(delta_, delta); //Use smalest delta
253282
}
283+
while (!done);
284+
Interpolation.X = Xlst.ToArray();
285+
Interpolation.Y = Ylst.ToArray();
286+
Interpolation.S = Slst.ToArray();
287+
Interpolation.T = Tlst.ToArray();
288+
Interpolation.K = Klst.ToArray();
289+
254290
PlausibilityCheck();
255291
return ref Interpolation;
256292
}

TRA.Tool/InterpolationPanel.Designer.cs

Lines changed: 46 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TRA.Tool/InterpolationPanel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,21 @@ private void btn_Interpolate_Click(object sender, EventArgs e)
3737
TrassenPanel panel = (TrassenPanel)owner.Controls[idx];
3838
if (panel.trasseS != null)
3939
{
40-
panel.trasseS.Interpolate((double)num_InterpDist.Value);
40+
panel.trasseS.Interpolate((double)num_InterpDist.Value, (double)num_allowedTolerance.Value * 100);
4141
#if USE_SCOTTPLOT
4242
panel.trasseS.Plot();
4343
#endif
4444
}
4545
if (panel.trasseL != null)
4646
{
47-
panel.trasseL.Interpolate3D(null, (double)num_InterpDist.Value);
47+
panel.trasseL.Interpolate3D(null, (double)num_InterpDist.Value, (double)num_allowedTolerance.Value * 100);
4848
#if USE_SCOTTPLOT
4949
panel.trasseL.Plot();
5050
#endif
5151
}
5252
if (panel.trasseR != null)
5353
{
54-
panel.trasseR.Interpolate3D(null, (double)num_InterpDist.Value);
54+
panel.trasseR.Interpolate3D(null, (double)num_InterpDist.Value, (double)num_allowedTolerance.Value * 100);
5555
#if USE_SCOTTPLOT
5656
panel.trasseR.Plot();
5757
#endif

0 commit comments

Comments
 (0)