From e00cdc8200e56b878080b07d153d69f231d74412 Mon Sep 17 00:00:00 2001 From: Claire Kuang Date: Wed, 23 Oct 2024 13:27:23 +0100 Subject: [PATCH 1/3] fixing alignment arc calculations --- .../Properties/ClassPropertiesExtractor.cs | 5 --- ...gnmentSubentityArcToSpeckleRawConverter.cs | 45 ++++++++----------- 2 files changed, 18 insertions(+), 32 deletions(-) diff --git a/Converters/Civil3d/Speckle.Converters.Civil3dShared/ToSpeckle/Properties/ClassPropertiesExtractor.cs b/Converters/Civil3d/Speckle.Converters.Civil3dShared/ToSpeckle/Properties/ClassPropertiesExtractor.cs index 333ac8044..8fd6d7052 100644 --- a/Converters/Civil3d/Speckle.Converters.Civil3dShared/ToSpeckle/Properties/ClassPropertiesExtractor.cs +++ b/Converters/Civil3d/Speckle.Converters.Civil3dShared/ToSpeckle/Properties/ClassPropertiesExtractor.cs @@ -252,11 +252,6 @@ private void ExtractPartProperties(CDB.Part part, Dictionary di catchmentProperties["featureLineIds"] = GetSpeckleApplicationIdsFromCollection(site.GetFeatureLineIds()); } - if (site.GetParcelIds().Count > 0) - { - catchmentProperties["parcelIds"] = GetSpeckleApplicationIdsFromCollection(site.GetParcelIds()); - } - return catchmentProperties; } diff --git a/Converters/Civil3d/Speckle.Converters.Civil3dShared/ToSpeckle/Raw/AlignmentSubentityArcToSpeckleRawConverter.cs b/Converters/Civil3d/Speckle.Converters.Civil3dShared/ToSpeckle/Raw/AlignmentSubentityArcToSpeckleRawConverter.cs index 5c6d9c563..c4559d2eb 100644 --- a/Converters/Civil3d/Speckle.Converters.Civil3dShared/ToSpeckle/Raw/AlignmentSubentityArcToSpeckleRawConverter.cs +++ b/Converters/Civil3d/Speckle.Converters.Civil3dShared/ToSpeckle/Raw/AlignmentSubentityArcToSpeckleRawConverter.cs @@ -1,6 +1,5 @@ using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Sdk; namespace Speckle.Converters.Civil3dShared.ToSpeckle.Raw; @@ -22,37 +21,29 @@ IConverterSettingsStore settingsStore public SOG.Arc Convert(CDB.AlignmentSubEntityArc target) { + // alignment arcs do not have the same properties as autocad arcs. + // we're assuming they are always 2d arcs on the xy plane to calculate the midpoint string units = _settingsStore.Current.SpeckleUnits; - // calculate midpoint of chord as between start and end point - AG.Point2d chordMid = - new((target.StartPoint.X + target.EndPoint.X) / 2, (target.StartPoint.Y + target.EndPoint.Y) / 2); + // calculate start and end angles from center + double startAngle = Math.Atan2( + target.StartPoint.Y - target.CenterPoint.Y, + target.StartPoint.X - target.CenterPoint.X + ); + double endAngle = Math.Atan2(target.EndPoint.Y - target.CenterPoint.Y, target.EndPoint.X - target.CenterPoint.X); - // calculate sagitta as radius minus distance between arc center and chord midpoint - double sagitta = target.Radius - target.CenterPoint.GetDistanceTo(chordMid); + // calculate midpoint angle + double midAngle = !target.Clockwise + ? startAngle + ((endAngle - startAngle) / 2) + : endAngle - ((endAngle - startAngle) / 2); - // get unit vector from arc center to chord mid - AG.Vector2d midVector = target.CenterPoint.GetVectorTo(chordMid); - AG.Vector2d unitMidVector = midVector.DivideBy(midVector.Length); - - // get midpoint of arc by moving chord mid point the length of the sagitta along mid vector - // if greater than 180 >, move in other direction of distance radius + radius - sagitta - // in the case of an exactly perfect half circle arc...🤷‍♀️ - AG.Point2d midPoint = chordMid.Add(unitMidVector.MultiplyBy(sagitta)); - try - { - if (target.GreaterThan180) // this can throw : The property gets an invalid value according to the entity's constraint type. - { - midPoint = chordMid.Add(unitMidVector.Negate().MultiplyBy(2 * target.Radius - sagitta)); - } - } - catch (Exception e) when (!e.IsFatal()) { } // continue with original midpoint if GreaterThan180 doesn't apply to this arc + // calculate midpoint coordinates + double midX = target.CenterPoint.X + target.Radius * Math.Cos(midAngle); + double midY = target.CenterPoint.Y + target.Radius * Math.Sin(midAngle); // find arc plane (normal is in clockwise dir) var center3 = new AG.Point3d(target.CenterPoint.X, target.CenterPoint.Y, 0); - AG.Plane plane = target.Clockwise - ? new AG.Plane(center3, AG.Vector3d.ZAxis.MultiplyBy(-1)) - : new AG.Plane(center3, AG.Vector3d.ZAxis); + AG.Plane plane = new AG.Plane(center3, AG.Vector3d.ZAxis); // create arc SOG.Arc arc = @@ -74,8 +65,8 @@ public SOG.Arc Convert(CDB.AlignmentSubEntityArc target) }, midPoint = new() { - x = midPoint.X, - y = midPoint.Y, + x = midX, + y = midY, z = 0, units = units }, From 59e21188ef38918a9a9e94eea6085eff8d302cfd Mon Sep 17 00:00:00 2001 From: Claire Kuang Date: Wed, 23 Oct 2024 18:36:53 +0100 Subject: [PATCH 2/3] fixes alignment arc conversions --- ...gnmentSubentityArcToSpeckleRawConverter.cs | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/Converters/Civil3d/Speckle.Converters.Civil3dShared/ToSpeckle/Raw/AlignmentSubentityArcToSpeckleRawConverter.cs b/Converters/Civil3d/Speckle.Converters.Civil3dShared/ToSpeckle/Raw/AlignmentSubentityArcToSpeckleRawConverter.cs index c4559d2eb..1da4c8444 100644 --- a/Converters/Civil3d/Speckle.Converters.Civil3dShared/ToSpeckle/Raw/AlignmentSubentityArcToSpeckleRawConverter.cs +++ b/Converters/Civil3d/Speckle.Converters.Civil3dShared/ToSpeckle/Raw/AlignmentSubentityArcToSpeckleRawConverter.cs @@ -25,21 +25,22 @@ public SOG.Arc Convert(CDB.AlignmentSubEntityArc target) // we're assuming they are always 2d arcs on the xy plane to calculate the midpoint string units = _settingsStore.Current.SpeckleUnits; - // calculate start and end angles from center - double startAngle = Math.Atan2( - target.StartPoint.Y - target.CenterPoint.Y, - target.StartPoint.X - target.CenterPoint.X - ); - double endAngle = Math.Atan2(target.EndPoint.Y - target.CenterPoint.Y, target.EndPoint.X - target.CenterPoint.X); + // calculate the mid vector (center to PI point (intersection of tangents) + // note: what is the PI point for a perfect half circle? + AG.Point2d piPoint = target.PIPoint; + double midVectorX = piPoint.X - target.CenterPoint.X; + double midVectorY = piPoint.Y - target.CenterPoint.Y; + double midVectorMag = Math.Sqrt(Math.Pow(midVectorX, 2.0) + Math.Pow(midVectorY, 2)); + double midScalingVectorX = target.Radius * midVectorX / midVectorMag; + double midScalingVectorY = target.Radius * midVectorY / midVectorMag; + if (target.Delta > Math.PI) + { + midScalingVectorX *= -1; + midScalingVectorY *= -1; + } - // calculate midpoint angle - double midAngle = !target.Clockwise - ? startAngle + ((endAngle - startAngle) / 2) - : endAngle - ((endAngle - startAngle) / 2); - - // calculate midpoint coordinates - double midX = target.CenterPoint.X + target.Radius * Math.Cos(midAngle); - double midY = target.CenterPoint.Y + target.Radius * Math.Sin(midAngle); + double midPointX = target.CenterPoint.X + midScalingVectorX; + double midPointY = target.CenterPoint.Y + midScalingVectorY; // find arc plane (normal is in clockwise dir) var center3 = new AG.Point3d(target.CenterPoint.X, target.CenterPoint.Y, 0); @@ -65,13 +66,14 @@ public SOG.Arc Convert(CDB.AlignmentSubEntityArc target) }, midPoint = new() { - x = midX, - y = midY, + x = midPointX, + y = midPointY, z = 0, units = units }, plane = _planeConverter.Convert(plane), radius = target.Radius, + angleRadians = target.Delta, length = target.Length, // additional alignment subentity props @@ -79,7 +81,6 @@ public SOG.Arc Convert(CDB.AlignmentSubEntityArc target) ["endStation"] = target.EndStation, ["startDirection"] = target.StartDirection, ["endDirection"] = target.EndDirection, - ["delta"] = target.Delta, ["deflectedAngle"] = target.DeflectedAngle, ["minumumRadius"] = target.MinimumRadius }; From 9c6262e4333485b47eaced4624bdd47a49bd9313 Mon Sep 17 00:00:00 2001 From: Claire Kuang Date: Wed, 23 Oct 2024 19:04:57 +0100 Subject: [PATCH 3/3] adds units --- .../ToSpeckle/Raw/AlignmentSubentityArcToSpeckleRawConverter.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Converters/Civil3d/Speckle.Converters.Civil3dShared/ToSpeckle/Raw/AlignmentSubentityArcToSpeckleRawConverter.cs b/Converters/Civil3d/Speckle.Converters.Civil3dShared/ToSpeckle/Raw/AlignmentSubentityArcToSpeckleRawConverter.cs index 1da4c8444..f7c62dbeb 100644 --- a/Converters/Civil3d/Speckle.Converters.Civil3dShared/ToSpeckle/Raw/AlignmentSubentityArcToSpeckleRawConverter.cs +++ b/Converters/Civil3d/Speckle.Converters.Civil3dShared/ToSpeckle/Raw/AlignmentSubentityArcToSpeckleRawConverter.cs @@ -75,6 +75,7 @@ public SOG.Arc Convert(CDB.AlignmentSubEntityArc target) radius = target.Radius, angleRadians = target.Delta, length = target.Length, + units = units, // additional alignment subentity props ["startStation"] = target.StartStation,