Calculating bulges for circle arcs

Calculating bulges for circle arcs

Anonymous
Not applicable
3,402 Views
2 Replies
Message 1 of 3

Calculating bulges for circle arcs

Anonymous
Not applicable

I have converted a circle into polyline segments for a program i am writing and want to calculate the bulges of each polyline in the circle. I have written the follow code to calculate the bulges of each section of the circle.

 

double getBulge( double r, AcGePoint3d a, AcGePoint3d b )
{

	double dist = sqrt( ( b.x - a.x ) * ( b.x - a.x ) + ( b.y - a.y ) * ( b.y - a.y ) );
	double angle = acos( ( ( 2 * r * r ) - ( dist * dist ) ) / ( 2 * r * r ) );
	double bulge = tan( angle * 0.25 );
	return bulge;
}

My problem is that sometimes the bulges are in the wrong direction on the circle see the following image. You can see that in the circles at the top of the screen shot the bulges are calculated correctly and for the circles at the bottom they are incorrect. Is there a way to figure out the direction of a bulge in a circle segment?

FORMPOST.pngFORMPOST2.png

 

0 Likes
Accepted solutions (1)
3,403 Views
2 Replies
Replies (2)
Message 2 of 3

tbrammer
Advisor
Advisor
Accepted solution

Your problem is that you calculate angle without sign. acos(c) will always return a positive number.

In your equations you only have r, but not the center of the arc. It is important to know whether the arc runs clockwise or counter-clockwise from a to b.

I think the bulge has to be positive for counter-clockwise and negative for clockwise arcs.

 

Try this:

	AcGePoint3d ct; //Center point
	AcGePoint3d a, b;
	AcGeVector3d va(a-ct), vb(b-ct), normal(AcGeVector3d::kXAxis);
	double angle = va.angleTo(vb, normal);

 


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

0 Likes
Message 3 of 3

Anonymous
Not applicable

Thank you that was the problem here is the updated code if anyone needs it.

 

double getBulge( AcDbCircle *circle, AcGePoint3d a, AcGePoint3d b )
{

	double dist = sqrt( ( b.x - a.x ) * ( b.x - a.x ) + ( b.y - a.y ) * ( b.y - a.y ) );
	double angle = atan2( a.y - circle->center().y, a.x - circle->center().x ) - atan2( b.y - circle->center().y, b.x - circle->center().x );

	if( angle < 0 )
	{
		//2*pi
		angle += 6.28319;
	}

	double bulge = tan( angle * 0.25 );
	return bulge;
}
0 Likes