Skip to content
New issue

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

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

Already on GitHub? # to your account

Read Hatch Edge CircularArc wrong coordinates #524

Closed
gleeuwdrent opened this issue Jan 10, 2025 · 2 comments · May be fixed by #525
Closed

Read Hatch Edge CircularArc wrong coordinates #524

gleeuwdrent opened this issue Jan 10, 2025 · 2 comments · May be fixed by #525
Labels
bug Something isn't working

Comments

@gleeuwdrent
Copy link

gleeuwdrent commented Jan 10, 2025

Bug description
I am reading a DWG with a hatch which is defined with Edges and contains CircularArc. If I create coordinates from the start, mid (halfway) and end point of the circular arcs, they do not always correspond with the geometry of the arc in the DWG.
It looks like the angles of the arc are not correct.

To Reproduce
I use this code to print the coordinates:

foreach(var path in hatch.Paths)
{
	foreach(Hatch.BoundaryPath.Edge item in path.Edges)
	{
		if (item.Type == Hatch.BoundaryPath.EdgeType.CircularArc)
		{
			Hatch.BoundaryPath.Arc arc = (Hatch.BoundaryPath.Arc) item;
			XY startPoint = CalculatePoint(arc.StartAngle, arc.Radius, arc.Center);
			XY midPoint = CalculatePoint(arc.StartAngle + 0.5 * (arc.EndAngle - arc.StartAngle), arc.Radius, arc.Center);
			XY endPoint = CalculatePoint(arc.EndAngle, arc.Radius, arc.Center);
			Console.WriteLine($ "POINT {startPoint}");
			Console.WriteLine($ "POINT {midPoint}");
			Console.WriteLine($ "POINT {endPoint}");
		}
	}
}

And this method to calculate coordinate from arc properties:

public static XY CalculatePoint(double angle, double radius, XY center)
{
    double x = center.X + radius * Math.Cos(angle);
    double y = center.Y + radius * Math.Sin(angle);
    return new XY(x, y);
}

Screenshots
If I create points from the coordinates in AutoCAD, you can see that some of the arcs are recreated well, but some are wrong.
image

Additional context
See attached drawing for the dwg.
hatch.zip

@gleeuwdrent gleeuwdrent added the bug Something isn't working label Jan 10, 2025
@DomCR
Copy link
Owner

DomCR commented Jan 11, 2025

Hi @gleeuwdrent,

The problem is not with the data, is how is stored and changes depending on the flag CounterClockWise.

I've found that the proper way to convert the boundary arcs into Entities.Arc is using the following method:

public ACadSharp.Entities.Arc ConvertToArc()
{
	if (this.CounterClockWise)
	{
		return new ACadSharp.Entities.Arc
		{
			Center = (XYZ)this.Center,
			Radius = this.Radius,
			StartAngle = this.StartAngle,
			EndAngle = this.EndAngle
		};
	}

	return new ACadSharp.Entities.Arc
	{
		Center = (XYZ)this.Center,
		Radius = this.Radius,
		StartAngle = 2 * Math.PI - this.EndAngle,
		EndAngle = 2 * Math.PI - this.StartAngle
	};
}

The Arc entity has the method PolygonalVertexes which you can use to get the 3 points you need by setting the precision to 3.

I'll add the method to the library and the other boundaries so its easier to get the equivalent entities from it.

Thanks for the report, let me know if this helps.

@DomCR DomCR linked a pull request Jan 11, 2025 that will close this issue
@gleeuwdrent
Copy link
Author

Thanks, this solves my issue!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants