Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(civil3d): alignment arc logic fixed #320

Merged
merged 4 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,6 @@ private void ExtractPartProperties(CDB.Part part, Dictionary<string, object?> di
catchmentProperties["featureLineIds"] = GetSpeckleApplicationIdsFromCollection(site.GetFeatureLineIds());
}

if (site.GetParcelIds().Count > 0)
{
catchmentProperties["parcelIds"] = GetSpeckleApplicationIdsFromCollection(site.GetParcelIds());
}

return catchmentProperties;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;
using Speckle.Sdk;

namespace Speckle.Converters.Civil3dShared.ToSpeckle.Raw;

Expand All @@ -22,37 +21,30 @@ IConverterSettingsStore<Civil3dConversionSettings> 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this assumption correct, or is there a chance a civil arc won't be laying on the 2d plane?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They appear to always be of type Arc2d

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 sagitta as radius minus distance between arc center and chord midpoint
double sagitta = target.Radius - target.CenterPoint.GetDistanceTo(chordMid);

// 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
// 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)
{
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));
}
midScalingVectorX *= -1;
midScalingVectorY *= -1;
}
catch (Exception e) when (!e.IsFatal()) { } // continue with original midpoint if GreaterThan180 doesn't apply to this arc

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);
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 =
Expand All @@ -74,21 +66,22 @@ public SOG.Arc Convert(CDB.AlignmentSubEntityArc target)
},
midPoint = new()
{
x = midPoint.X,
y = midPoint.Y,
x = midPointX,
y = midPointY,
z = 0,
units = units
},
plane = _planeConverter.Convert(plane),
radius = target.Radius,
angleRadians = target.Delta,
length = target.Length,
units = units,

// additional alignment subentity props
["startStation"] = target.StartStation,
["endStation"] = target.EndStation,
["startDirection"] = target.StartDirection,
["endDirection"] = target.EndDirection,
["delta"] = target.Delta,
["deflectedAngle"] = target.DeflectedAngle,
["minumumRadius"] = target.MinimumRadius
};
Expand Down
Loading