Skip to content

Commit 68d8dff

Browse files
committed
Fixed projection delta in sAt-Function for clothoids
1 parent 53d647d commit 68d8dff

File tree

7 files changed

+84
-48
lines changed

7 files changed

+84
-48
lines changed

TRA.Lib/Trasse.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public void SaveCSV(StreamWriter outputFile)
301301
/// <value>List of all Plottables of this element</value>
302302
List<IPlottable> Plottables = new();
303303
/// <value>Callout for right-click selected Coordinate and s-projection</value>
304-
static ScottPlot.Plottables.Callout selectedS;
304+
static ProjectionArrow selectedS;
305305
/// <value>Plot for TRA-Details heading and hurvature </value>
306306
ScottPlot.WinForms.FormsPlot PlotT;
307307
/// <value>Plot for GRA-Details elevation and slope </value>
@@ -675,18 +675,21 @@ private void Plot2D_MouseClick(object sender, MouseEventArgs e)
675675
Coordinates coordinates = Plot2D.Plot.GetCoordinates(new Pixel(e.X, e.Y));
676676
TrassenElementExt element = GetElementFromPoint(coordinates.Y, coordinates.X);
677677
if (element == null) { return; }
678-
double s = element.GetSAtPoint(coordinates.Y, coordinates.X);
678+
double s = element.GetSAtPoint(coordinates.Y, coordinates.X,0);
679679
if (Double.IsNaN(s)) return;
680-
(double X, double Y, _) = element.GetPointAtS(s);
680+
(double X, double Y, double H) = element.GetPointAtS(s);
681+
coordinates = new Coordinates(Y + 10 * Math.Sin(H + 0.5 * Math.PI), X + 10 * Math.Cos(H + 0.5 * Math.PI));
681682
if (selectedS == null)
682683
{
683-
selectedS = Plot2D.Plot.Add.Callout(s.ToString(), Y + 10, X + 10, Y, X);
684+
//selectedS = Plot2D.Plot.Add.Callout(s.ToString(), Y + 10, X + 10, Y, X);
685+
selectedS = new ProjectionArrow(coordinates, new Coordinates(Y, X));
686+
Plot2D.Plot.Add.Plottable(selectedS);
684687
}
685688
else
686689
{
687-
selectedS.TextCoordinates = coordinates;
688-
selectedS.TipCoordinates = new Coordinates(Y, X);
689-
selectedS.Text = s.ToString();
690+
selectedS.Base = coordinates;
691+
selectedS.Tip = new Coordinates(Y, X);
692+
//selectedS.Text = s.ToString();
690693
}
691694
Plot2D.Refresh();
692695
}

TRA.Lib/TrassenElementExt.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public void Relocate(double x, double y, double deltaGamma = double.NaN, double
191191
if (!double.IsNaN(deltaK_start))
192192
{
193193
// TODO decide if we need to change the length and if yes, do we want to update the stationvalues s
194-
l = l;// * (deltaK_start + deltaK_end) / 2;
194+
l = l * (deltaK_start + deltaK_end) / 2;
195195
if (Double.IsNaN(deltaK_end)) { deltaK_end = deltaK_start; }
196196
switch (this.TrassenGeometrie)
197197
{
@@ -229,7 +229,7 @@ public bool PlausibilityCheck(bool bCheckRadii = false)
229229
{
230230
if (s + l != successor.s) { AddWarningCallout("length missmatch. element is not connected to successor", Xend, Yend); }
231231
}
232-
//Length and geomtrical Length Check
232+
//Length and geometrical Length Check
233233
if(TrassenGeometrie is Gerade)
234234
{
235235
double geoL = Math.Sqrt(Math.Pow(Xend-Xstart,2)+Math.Pow(Yend-Ystart,2));
@@ -331,9 +331,8 @@ public double GetSAtPoint(double X, double Y, double T = double.NaN)
331331
/// <returns>Hochwert X,Rechtswert Y, Heading T</returns>
332332
public (double, double, double) GetPointAtS(double S)
333333
{
334-
(double X, double Y, _, _) = TrassenGeometrie.PointAt(S - s);
334+
(double X, double Y, double T, _) = TrassenGeometrie.PointAt(S - s);
335335
Transform2D transform = new Transform2D(x, y, t);
336-
double T = 0.0;
337336
transform.Apply(ref X, ref Y, ref T);
338337
return (X, Y, T);
339338
}

TRA.Lib/Trasseninterpolation.cs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public class Klothoid : TrassenGeometrie
118118
/// </summary>
119119
/// <param name="r1">First radius NaN is interpreted as zero(straight)</param>
120120
/// <param name="r2">Second radius NaN is interpreted as zero(straight)</param>
121-
/// <param name="length">Length of the Clothoid. NaN and 0 is results in stragiht line (radii have no effect)</param>
121+
/// <param name="length">Length of the Clothoid. NaN and 0 is results in straight line (radii have no effect)</param>
122122
public Klothoid(double r1, double r2, double length)
123123
{
124124
this.r1 = Double.IsNaN(r1) ? 0 : r1; //interpreting NaN radius as zero (straight line)
@@ -176,7 +176,7 @@ public override (double X, double Y, double t, double k) PointAt(double s)
176176
Complex Cs = Cs1 * Cs2;
177177

178178
//Tangent at point
179-
double theta = gamma * Math.Pow(s, 2) / 2 + curvature1 * s;
179+
double theta = gamma * s * s * 0.5 + curvature1 * s;
180180
return (Cs.Real, dir * Math.Sign(gamma) * Cs.Imaginary, theta, curvature1 + gamma * s);
181181
}
182182

@@ -231,14 +231,13 @@ public override double sAt(double X, double Y, double t = double.NaN)
231231
double s = 0.0;
232232
double d = double.PositiveInfinity; //distance between point and normal
233233
Vector2 v1, v2;
234-
Vector2 vt = new();
235-
int prevSign = 0;
234+
v1 = new Vector2();
236235
if (!Double.IsNaN(t))
237236
{
238237
double x, y;
239238
(x, y) = Math.SinCos(t);
240-
vt = new Vector2((float)y, (float)x);
241-
prevSign = Math.Sign(X * vt.Y - Y * vt.X);
239+
v1 = new Vector2((float)y, (float)x);
240+
delta = Math.Sign(X * v1.Y - Y * v1.X)*delta;
242241
}
243242

244243
int maxIterations = 1000;
@@ -249,32 +248,30 @@ public override double sAt(double X, double Y, double t = double.NaN)
249248
v2 = new Vector2((float)(X - X_), (float)(Y - Y_)); //vector from current position to Point of interest
250249
if (Double.IsNaN(t))
251250
{
252-
v1 = new Vector2((float)Math.Sin(t_), (float)Math.Cos(t_)); //normal at current position
253-
double scalarCross = v2.X * v1.Y - v2.Y * v1.X;
254-
if (Math.Sign(scalarCross) != Math.Sign(delta))
251+
v1 = new Vector2((float)Math.Cos(t_), (float)Math.Sin(t_)); //normal at current position
252+
double vectorDot = Vector2.Dot(v1,v2) / v2.Length();
253+
if (Math.Sign(vectorDot) != Math.Sign(delta))
255254
{
256255
delta = -0.5 * delta;
257-
}
258-
// Compute d by cross product
259-
d = Math.Abs(scalarCross) / (float)v1.Length();
256+
}
257+
d = Math.Abs(vectorDot);
260258
}
261259
else
262260
{
263-
double scalarCross = v2.X * vt.Y - v2.Y * vt.X;
264-
if (Math.Sign(scalarCross) != prevSign)
261+
double scalarCross = v2.X * v1.Y - v2.Y * v1.X;
262+
double vectorDot = 1-(Vector2.Dot(v2,v1) / v2.Length()); //Result is reached when both vectors are parallel
263+
if (Math.Sign(scalarCross) != Math.Sign(delta))
265264
{
266265
delta = -0.5 * delta;
267-
prevSign = Math.Sign(scalarCross);
268-
}
269-
double ang = Math.Acos(Vector2.Dot(vt, v2 / v2.Length()));
270-
d = (ang > 0.5 * Math.PI ? Math.PI - ang : ang) * v2.Length();
266+
}
267+
d = Math.Abs(vectorDot);
271268
}
272269
s = s + delta;
273270
i++;
274271
}
275272
if (i == maxIterations)
276273
{
277-
TrassierungLog.Logger?.LogWarning("Could not Interpolate a valid solution on Clothoid geometry", this);
274+
TrassierungLog.Logger?.LogWarning("Could not Interpolate a valid solution on Clothoid geometry" + d, this);
278275
return double.NaN;
279276
}
280277
return s;

TRA.Tool/MainForm.Designer.cs

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TRA.Tool/MainForm.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using LowDistortionProjection;
33
using Microsoft.Extensions.Logging;
44
using System;
5+
using System.Windows.Forms;
56
using TRA_Lib;
67

78
namespace TRA.Tool
@@ -17,15 +18,6 @@ public MainForm()
1718
// Handle TreeView events
1819
treeView.ItemDrag += TreeView_ItemDrag;
1920

20-
ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
21-
{
22-
builder.AddProvider(new TextBoxLoggerProvider(tb_Log));
23-
});
24-
// Create logger
25-
logger = loggerFactory.CreateLogger<MainForm>();
26-
TrassierungLog.AssignLogger(loggerFactory);
27-
SrsLogger.Instance.ConfigureLogger(logger);
28-
2921
// Create a Panel to indicate the drop location
3022
dropIndicatorPanel = new Panel
3123
{
@@ -190,6 +182,24 @@ private void btn_AddTransformation_Click(object sender, EventArgs e)
190182
panel.Invalidate();
191183
}
192184
}
185+
186+
private void clearToolStripMenuItem_Click(object sender, EventArgs e)
187+
{
188+
tb_Log.Clear();
189+
}
190+
191+
private void MainForm_Shown(object sender, EventArgs e)
192+
{
193+
ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
194+
{
195+
builder.AddProvider(new TextBoxLoggerProvider(tb_Log));
196+
});
197+
// Create logger
198+
logger = loggerFactory.CreateLogger<MainForm>();
199+
TrassierungLog.AssignLogger(loggerFactory);
200+
egbt22lib.LoggingInitializer.InitializeLogging(loggerFactory);
201+
SrsLogger.Instance.ConfigureLogger(logger);
202+
}
193203
}
194204

195205
public class TextBoxLogger : ILogger

TRA.Tool/MainForm.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,7 @@
5757
<resheader name="writer">
5858
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
5959
</resheader>
60+
<metadata name="contextMenuStrip_Log.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
61+
<value>17, 17</value>
62+
</metadata>
6063
</root>

TRA.Tool/TransformPanel.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,17 @@ private void btn_Transform_Click(object sender, EventArgs e)
8989
{
9090
double[][] points = { interp.Y, interp.X, interp.H };
9191
//Srs.ConvertInPlace(ref points, SRS_Source, SRS_Target);
92+
double[] gamma_i, k_i, gamma_o, k_o = new double[interp.X.Length];
93+
egbt22lib.Convert.DBRef_GK5_Gamma_k(points[0], points[1],out gamma_i,out k_i);
9294
egbt22lib.Convert.DBRef_GK5_to_EGBT22_Local(points[0], points[1], points[2],out points[0], out points[1]);
95+
egbt22lib.Convert.EGBT22_Local_Gamma_k(points[0], points[1], out gamma_o, out k_o);
9396
//Workaround to set values in place
9497
for (int i = 0; i < interp.X.Length; i++)
9598
{
9699
interp.X[i] = points[1][i];
97100
interp.Y[i] = points[0][i];
98101
interp.H[i] = points[2][i];
102+
interp.T[i] = interp.T[i]-DegreesToRadians(gamma_o[i] - gamma_i[i]);
99103
}
100104
}
101105
catch {
@@ -104,17 +108,15 @@ private void btn_Transform_Click(object sender, EventArgs e)
104108
//Transform Element
105109
try
106110
{
107-
double[][] coordinate = !Double.IsNaN(elementHeight) ?
108-
new double[][] { new double[] { element.Ystart }, new double[] { element.Xstart }, new double[] { elementHeight } }
109-
: new double[][]{ new double[] { element.Ystart }, new double[] { element.Xstart }, new double[] { 0.0 } };
110111
//Srs.ConvertInPlace(ref coordinate, SRS_Source, SRS_Target);
111-
double[] gamma_i, k_i,gamma_o,k_o;
112-
egbt22lib.Convert.DBRef_GK5_Gamma_k(coordinate[0], coordinate[1], out gamma_i, out k_i);
113-
egbt22lib.Convert.DBRef_GK5_to_EGBT22_Local(coordinate[0], coordinate[1],coordinate[2],out coordinate[0], out coordinate[1]);
114-
egbt22lib.Convert.EGBT22_Local_Gamma_k(coordinate[0], coordinate[1], out gamma_o, out k_o);
115-
double dK = (k_i[0] / k_o[0]);
112+
double gamma_i, k_i,gamma_o,k_o;
113+
double rechts, hoch;
114+
(gamma_i,k_i) = egbt22lib.Convert.DBRef_GK5_Gamma_k(element.Ystart, element.Xstart);
115+
(rechts, hoch) = egbt22lib.Convert.DBRef_GK5_to_EGBT22_Local(element.Ystart, element.Xstart, Double.IsNaN(elementHeight) ? 0.0 : elementHeight);
116+
(gamma_o,k_o) = egbt22lib.Convert.EGBT22_Local_Gamma_k(rechts, hoch);
117+
double dK = (k_i / k_o);
116118

117-
element.Relocate(coordinate[1][0], coordinate[0][0], DegreesToRadians(gamma_o[0] - gamma_i[0]), dK,previousdK);
119+
element.Relocate(hoch, rechts, DegreesToRadians(gamma_o - gamma_i), dK,previousdK);
118120
previousdK = element.ID == 0 ? double.NaN : dK; //reset prviousScale for next Element
119121
}
120122
catch {

0 commit comments

Comments
 (0)