public void CatenaryTest3() { var c = new Catenary(new Vector2(15, 100), 300, 50, 1.15, 770); var g = new Catenary(c); Assert.IsTrue(g.Equals(c)); }
public override void OnInspectorGUI() { Catenary catenary = (Catenary)target; DrawDefaultInspector(); if (catenary.lockEditing == false) { if (GUI.changed) { catenary.Regenerate(); } if (GUILayout.Button("Create RopeEnds") && catenary.p1 == null && catenary.p2 == null) { CreateRopeStart(catenary); CreateRopeEnd(catenary); } if (GUILayout.Button("Destroy Rope Ends")) { DestroyImmediate(catenary.p1.gameObject); catenary.p1 = null; DestroyImmediate(catenary.p2.gameObject); catenary.p2 = null; } if (GUILayout.Button("Unassign previous ends")) { catenary.p1 = null; catenary.p2 = null; } } }
public void CatenaryTest() { Span s = new Span(new Vector2(15, 100), 300, 50); var c = new Catenary(s, 1.15, 770); Assert.IsTrue(c.IsOK); Assert.IsTrue(s.Equals(c)); Assert.AreEqual(1.15, c.CableWeight); Assert.AreEqual(770, c.HorizontalTension); Assert.AreEqual(669.5652, c.CatenaryConstant, 1e-4); CollectionAssert.AreEqual(new Vector2(54.832, 98.815), c.SagPoint, Extensions.AbsComparer(1e-3)); Assert.AreEqual(98.8149, c.Clearance, 1e-4); CollectionAssert.AreEqual(new Vector2(-770, 45.833), c.StartTension, Extensions.AbsComparer(1e-3)); CollectionAssert.AreEqual(new Vector2(770, 306.78), c.EndTension, Extensions.AbsComparer(1e-3)); Assert.AreEqual(0.2240, c.Eta, 1e-4); Assert.AreEqual(0.8160, c.GeometricStrainPct, 1e-4); Assert.IsFalse(c.IsStartTowerUplift); Assert.IsFalse(c.IsEndTowerUplift); CollectionAssert.AreEqual(new Vector2(54.832, 98.815), c.LowestPosition, Extensions.AbsComparer(1e-3)); Assert.AreEqual(17.1019, c.MaximumSag, 1e-4); Assert.AreEqual(17.1012, c.MidSag, 1e-4); Assert.AreEqual(306.6199, c.TotalLength, 1e-4); Assert.AreEqual(352.6128, c.TotalWeight, 1e-4); }
private void moveDnButton_Click(object sender, EventArgs e) { int N = rulingspanDataGrid.SelectedRows.Count; int[] movers = new int[N]; for (int j = 0; j < N; j++) { movers[j] = rulingspanDataGrid.SelectedRows[j].Index; } Array.Sort(movers); rs.Spans.RaiseListChangedEvents = false; for (int i = movers.Length - 1; i >= 0; i--) { if (movers[i] < rs.Spans.Count - 1) { Catenary cat = rs[movers[i]]; rs.Spans.RemoveAt(movers[i]); rs.Spans.Insert(movers[i] + 1, cat); } } rs.UpdateAllCatenary(); rs.UpdateSpanEnds(); RefreshAndPaintGrid(); rs.Spans.RaiseListChangedEvents = true; rulingspanDataGrid.ClearSelection(); for (int i = 0; i < movers.Length; i++) { if (movers[i] < rs.Spans.Count - 1) { rulingspanDataGrid.Rows[movers[i] + 1].Selected = true; } } }
public void ToStringTest() { var c = new Catenary(new Vector2(15.55555555, 100), 300, 50, 1.155555555, 770.050610824); var t = c.ToString(); var e = "Start=(15.556,100), Step=(300,50), H=770.051, w=1.156"; Assert.AreEqual(e, t); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (ReadLicense()) { CheckLicense(); if (!_isDemo) { saveSpansButton.Enabled = true; importSpansButton.Enabled = true; } } string path = Properties.Settings.Default.lastSave; if (File.Exists(path)) { try { RulingSpan = RulingSpan.OpenFile(path); fileLabelStatusBar.Text = Path.GetFileName(path); } catch (System.IO.FileLoadException ex) { Debug.WriteLine(ex.ToString()); } } if (rs.Spans.Count == 0) { Catenary A = new Catenary(150 * Vector2.UnitY, 400, 12, 0.75, 3000); Catenary B = new Catenary(A.EndPosition, 1400, -10, 0.75, 3000); Catenary C = new Catenary(B.EndPosition, 700, -20, 0.75, 3000); rs.AddSpans(A, B, C); } rs.Spans.RaiseListChangedEvents = true; var icon_green = Properties.Resources.flag_green; foreach (var item in ProjectUnits.PredefinedUnits) { var mi = item.ToMenuItem(icon_green, (tsi, pev) => { rs.SetProjectUnits(pev.NewProjectUnits); unitsDropDown.Text = rs.Units.ToString(); RefreshAndPaintGrid(); }); unitsDropDown.DropDownItems.Add(mi); } unitsDropDown.Text = rs.Units.ToString(); }
public void CatenaryTest2() { Span s = new Span(new Vector2(15, 100), 300, 50); var c = new Catenary(new Vector2(15, 100), new Vector2(300, 50), 1.15, 770); Assert.IsTrue(c.IsOK); Assert.IsTrue(s.Equals(c)); Assert.AreEqual(1.15, c.CableWeight); Assert.AreEqual(770, c.HorizontalTension); }
public override void OnInspectorGUI() { DrawDefaultInspector(); if (GUI.changed) { Catenary catenary = (Catenary)target; catenary.Regenerate(); } }
public void SetClearancePointTest() { var c = new Catenary(new Vector2(15, 100), 300, 50, 1.15, 770); var point = new Vector2(50.0, 95.0); c.SetClearancePoint(point); var x = point.X; var actual = new Vector2(x, c.CatenaryFunction(x)); CollectionAssert.AreEqual(point, actual, Extensions.AbsComparer(1e-3)); }
public void CreateRopeStart(Catenary catenary) { ropeStart = Instantiate(catenary.RopeStart); ropeStart.name = catenary.gameObject.name + " Start "; catenary.p1 = ropeStart.transform; RopeGizmo temp = catenary.p1.GetComponent <RopeGizmo>(); temp.thisCatenary = catenary; temp.gizmoColor = thisRopeGizmos; Selection.activeGameObject = ropeStart; }
public void RulingSpanTest() { var projectUnits = new ProjectUnits(ProjectUnitSystem.NewtonMeterSecond); var cat1 = Catenary.Default(projectUnits); var cat2 = Catenary.Default(projectUnits); var cat3 = Catenary.Default(projectUnits); var rs = new RulingSpan( projectUnits, cat1, cat2, cat3); Assert.IsTrue(rs.IsOk); }
/// <summary> /// Copies configuration of other catenary /// </summary> /// <param name="other"> /// A <see cref="Catenary"/> - other catenary. /// </param> public void CopyConfigurationFrom(Catenary other) { CS = other.CS; CE = other.CE; T1 = other.T1; T2 = other.T2; P1 = other.P1; P2 = other.P2; W = other.W; L = other.L; N = other.N; }
private void catenaryPictureBox_Paint(object sender, PaintEventArgs e) { Style style = Style.Default; style.SetGraphicsQuality(e.Graphics); Vector2 min = Catenary.StartPosition, max = Catenary.EndPosition; Catenary.GetBounds(ref min, ref max); Canvas canvas = new Canvas(pictureBox.ClientRectangle, min, max); CatenaryGraphics.RenderOne(e.Graphics, canvas, Catenary, style); }
public void Cat_GivenLength() { double H = 5000.0, w = 0.75, S = 1400, h = -10; var span = new Span(Vector2.UnitY * h, S, h); var cat = new Catenary(span, w, H); double L = 1405; cat.TotalLength = L; Assert.AreEqual(L, cat.TotalLength, 1e-1); double H_expect = 3601.178; Assert.AreEqual(H_expect, cat.HorizontalTension, 1e-1); }
public void CreateRopeEnd(Catenary catenary) { ropeEnd = Instantiate(catenary.RopeEnd); ropeEnd.name = catenary.gameObject.name + " End "; catenary.p2 = ropeEnd.transform; RopeGizmo temp = catenary.p2.GetComponent <RopeGizmo>(); temp.thisCatenary = catenary; temp.gizmoColor = thisRopeGizmos; Vector3 tempPosition = ropeEnd.transform.position; tempPosition.x += 10; ropeEnd.transform.position = tempPosition; Selection.activeGameObject = ropeEnd; }
public void Cat_GivenSag() { double H = 5000.0, w = 0.75, S = 1400, h = -10; var span = new Span(Vector2.UnitY * h, S, h); var cat = new Catenary(span, w, H); double D_expect = 65; cat.MaximumSag = D_expect; Assert.AreEqual(D_expect, cat.MaximumSag, 1e-5); double H_expect = 2835.082; Assert.AreEqual(H_expect, cat.HorizontalTension, 1e-1); }
/// <summary> /// Draws GUI parts. /// </summary> /// <param name="catenary"> /// A <see cref="Catenary"/> /// </param> void DisplayCatenaryInfo(Catenary catenary) { GUI.Box(new Rect(boardX, boardY, boardWidth, boardHeight), "Catenary Information"); boardX += 5; boardY += 20; boardWidth = 190; boardHeight = 20; GUI.Label(new Rect(boardX, boardY, boardWidth, boardHeight), "P1: " + catenary.P1); boardY += 20; GUI.Label(new Rect(boardX, boardY, boardWidth, boardHeight), "P2: " + catenary.P2); boardY += 20; GUI.Label(new Rect(boardX, boardY, boardWidth, boardHeight), "Length: " + catenary.L); boardY += 20; GUI.Label(new Rect(boardX, boardY, boardWidth, boardHeight), "Vertices: " + catenary.N); }
public void Cat_GivenAverageTension() { double H = 5000.0, w = 0.75, S = 1400, h = -10; var span = new Span(Vector2.UnitY * h, S, h); var cat = new Catenary(span, w, H); double P_expect = 3000; cat.AverageTension = P_expect; Assert.AreEqual(P_expect, cat.AverageTension, 1e-3); double H_expect = 2984.443; Assert.AreEqual(H_expect, cat.HorizontalTension, 1e-1); }
public string[] TableRow(Catenary item) { return(new string[] { item.StartX.ToString("0.#"), item.StartY.ToString("0.#"), item.StepX.ToString("0.#"), item.StepY.ToString("0.#"), item.CableWeight.ToString("0.###"), item.AverageTension.ToString("0.#"), item.TotalLength.ToString("0.#"), item.MaximumSag.ToString("0.##"), item.Clearance.ToString("0.#"), item.CatenaryConstant.ToString("0.#"), (item.GeometricStrainPct / 100).ToString("0.###%"), item.IsUpliftCondition?"y":"n" }); }
public void Cat_GivenHTension() { double H = 5000.0, w = 0.75, S = 1200, h = 100; var span = new Span(Vector2.UnitX * h, S, 0); var cat = new Catenary(span, w, H); double a = H / w, η = w * S / (2 * H); double D_expect = a * (Math.Cosh(η) - 1); double L_expect = 2 * a * Math.Sinh(η); double T_expect = H * Math.Cosh(η); double ε_expect = 100 * (L_expect / S - 1); Assert.AreEqual(a, cat.CatenaryConstant); Assert.AreEqual(η, cat.Eta); Assert.AreEqual(D_expect, cat.MaximumSag, 1e-12); Assert.AreEqual(L_expect, cat.TotalLength, 1e-12); Assert.AreEqual(T_expect, cat.MaxTension, 1e-12); Assert.AreEqual(ε_expect, cat.GeometricStrainPct, 1e-12); }
public void Cat_GivenClearance() { double H = 5000.0, w = 0.75, S = 1400, h = -10; var span = new Span(Vector2.UnitY * 100, S, h); var cat = new Catenary(span, w, H); double C_expect = 64; cat.Clearance = C_expect; double H_expect = 5970.4; Assert.AreEqual(H_expect, cat.HorizontalTension, 1e-1); cat.SetClearancePoint(new Vector2(300, 60)); Assert.AreEqual(3278.9, cat.HorizontalTension, 1e-1); }
public void Render(Graphics g, RectangleF target) { Canvas canvas = GetCanvasFor(target); Style.SetGraphicsQuality(g); Catenary catenary = RulingSpan.FindCatenaryFromX(mouse_over.X); foreach (var item in RulingSpan.Spans) { RenderOne(g, canvas, item, Style, catenary == item); } if (!mouse_dn.IsZero) { catenary = RulingSpan.FindCatenaryFromX(mouse_dn.X); if (catenary != null) { double y = catenary.CatenaryFunction(mouse_dn.X); PointF A = canvas.Map(mouse_dn.X, y); PointF M = canvas.Map(mouse_dn); string text = Math.Abs(y - mouse_dn.Y).ToString("0.#"); Style.VerticalArrow(g, M.X, M.Y, A.Y, text, false); } using (Pen pen = Style.MakePen(Color.Red)) { PointF M = canvas.Map(mouse_dn); g.DrawEllipse(pen, M.X - Style.PointWidth / 2, M.Y - Style.PointWidth / 2, Style.PointWidth, Style.PointWidth); using (Font font = Style.MakeFont(SystemFonts.DialogFont)) { string text = string.Format("x:{0:0}\ny:{1:0.#}", mouse_dn.X, mouse_dn.Y); StringFormat sf = new StringFormat(); SizeF sz = g.MeasureString(text, font, M, sf); g.FillRectangle(Brushes.White, M.X - sz.Width - 4, M.Y - 4, sz.Width + 2, sz.Height + 2); g.DrawString(text, font, Brushes.Red, M.X - sz.Width - 2, M.Y - 2, sf); } } } }
/// <summary> /// Shows all the Catenary information. /// </summary> /// <param name="catenary"> /// A <see cref="Catenary"/> /// </param> void ShowAll(Catenary catenary) { ResetPosition(); DisplayCatenaryInfo(catenary); }
public static void RenderOne(Graphics g, Canvas canvas, Catenary catenary, Style style, bool selected = false) { PointF A = canvas.Map(catenary.StartPosition); PointF B = canvas.Map(catenary.EndPosition); PointF A0 = canvas.Map(catenary.StartBase); PointF B0 = canvas.Map(catenary.EndBase); PointF C = canvas.Map(catenary.LowestPosition); PointF C0 = canvas.Map(new Vector2(catenary.CenterX, 0)); SizeF em; if (A0.IsFinite() && B0.IsFinite() && A.IsFinite() && B.IsFinite()) { // Ground using (Font font = style.MakeFont(SystemFonts.DialogFont)) { g.DrawLine(Pens.Black, A0, B0); var txt = string.Format("{0:0.#}", catenary.StepX); em = g.MeasureString("M", font); float y = canvas.Target.Top + em.Height; style.HorizontalArrow(g, y, A.X, B.X, txt, true); g.DrawLine(Pens.Black, A.X, A.Y - style.PointWidth / 2, A.X, y - 0.75f * em.Height); g.DrawLine(Pens.Black, B.X, B.Y - style.PointWidth / 2, B.X, y - 0.75f * em.Height); } // Top dimensions // Diagonals using (Pen pen = style.MakePen(Color.LightGray)) { pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; g.DrawLine(pen, A, B); } // Poles using (Pen pen = style.MakePen(Color.BurlyWood)) { pen.Width = 3; g.DrawLine(pen, A0, A); g.DrawLine(pen, A0.X - 4, A0.Y, A0.X + 4, A0.Y); g.DrawLine(pen, B0, B); g.DrawLine(pen, B0.X - 4, B0.Y, B0.X + 4, B0.Y); using (Font font = style.MakeFont(SystemFonts.DialogFont)) { var txt1 = string.Format("{0:0.#}", catenary.StartPosition.Y); var txt2 = string.Format("{0:0.#}", catenary.EndPosition.Y); var sf = new StringFormat(style.StringFormat) { FormatFlags = StringFormatFlags.DirectionVertical }; SizeF sz1 = g.MeasureString(txt1, font, A0, sf); SizeF sz2 = g.MeasureString(txt2, font, B0, sf); g.DrawString(txt1, font, Brushes.Black, A0.X - sz1.Width / 2, A0.Y + style.PointWidth / 2); g.DrawString(txt2, font, Brushes.Black, B0.X - sz2.Width / 2, B0.Y + style.PointWidth / 2); } } } // Curves Func <double, Vector2> f = catenary.ParametricCurve; bool finite = true; using (Pen pen = style.MakePen(Color.Blue)) { const int N = 64; PointF[] points = new PointF[N + 1]; for (int i = 0; i <= N; i++) { points[i] = canvas.Map(f(((double)i) / N)); if (!points[i].IsFinite()) { finite = false; break; } } pen.Width = selected?4f:style.PenWidth; if (finite) { g.DrawCurve(pen, points); } } if (A.IsFinite() && B.IsFinite() && C.IsFinite()) { // Points using (SolidBrush brush = style.MakeSolidBrush(Color.Red)) { g.FillEllipse(brush, A.X - style.PointWidth / 2, A.Y - style.PointWidth / 2, style.PointWidth, style.PointWidth); g.FillEllipse(brush, B.X - style.PointWidth / 2, B.Y - style.PointWidth / 2, style.PointWidth, style.PointWidth); if (catenary.IsCenterInSpan) { brush.Color = Color.Plum; g.FillEllipse(brush, C.X - style.PointWidth / 2, C.Y - style.PointWidth / 2, style.PointWidth, style.PointWidth); } } // Clearance using (Pen pen = style.MakePen(Color.Black)) { g.DrawEllipse(pen, A.X - style.PointWidth / 2, A.Y - style.PointWidth / 2, style.PointWidth, style.PointWidth); g.DrawEllipse(pen, B.X - style.PointWidth / 2, B.Y - style.PointWidth / 2, style.PointWidth, style.PointWidth); if (catenary.IsCenterInSpan) { g.DrawEllipse(pen, C.X - style.PointWidth / 2, C.Y - style.PointWidth / 2, style.PointWidth, style.PointWidth); var txt = string.Format("{0:0.#}", catenary.CenterY); style.VerticalArrow(g, C.X, C0.Y, C.Y + style.PointWidth / 2, txt, false); } } } // Sag if (catenary.IsOK) { Vector2 d = catenary.SagPosition; double t = (d.X - catenary.StartPosition.X) / catenary.StepX; Vector2 h = catenary.StartPosition + t * (catenary.EndPosition - catenary.StartPosition); PointF D = canvas.Map(d); PointF H = canvas.Map(h); if (D.IsFinite() && H.IsFinite()) { var txt = string.Format("{0:0.#}", catenary.MaximumSag); style.VerticalArrow(g, D.X, H.Y, D.Y, txt, false); } } }