TA的每日心情![](source/plugin/dsu_paulsign/img/emot/kx.gif) | 开心 昨天 15:23 |
---|
签到天数: 69 天 [LV.6]常住居民II
管理员
- 积分
- 2704
|
AcGePoint2d pt1 pt2 pt3;
AcGePoint2d center.
Lets find the center point of the Arc:
double yDeltaA = pt2.y - pt1.y;
double xDeltaA = pt2.x - pt1.x;
double yDeltaB = pt3.y - pt2.y;
double xDeltaB = pt3.x - pt2.x;
//case for vertical or horizontal
if (fabs(xDeltaA) <= fuzz && fabs(yDeltaB) <= fuzz){
center.x = (pt2.x + pt3.x)/2.0;
center.y = (pt1.y + pt2.y)/2.0;
} else {
double aSlope=yDeltaA/xDeltaA;
double bSlope=yDeltaB/xDeltaB;
// checking whether the given points are colinear.
if (fabs(aSlope-bSlope) <= fuzz) return false;
center.x = (aSlope*bSlope*(pt1.y - pt3.y) + bSlope*(pt1.x + pt2.x)
- aSlope*(pt2.x+pt3.x))/(2* (bSlope-aSlope));
center.y = -1*(center.x - (pt1.x+pt2.x)/2.0)/aSlope+(pt1.y+pt2.y)/2.0;
}
Now to calculate the bulge we need the included angle.
The bulge is calculates as tan(includedAngle/4.0);
So get the Angles:
double startang = acutAngle(asPtn2d(center), asPtn2d(pt1));
double endang = acutAngle(asPtn2d(center), asPtn2d(pt3));
We now need to know the clock but there are 2 posibilities!
Your function is fine here but change it to accept to a AcGePoint2d
clock1 = cwisept (pt1, pt2, pt3);
clock2 = cwisept (pt1, center, pt3);
The diff_angle function normalises the angle
if (clock1 == clock2) {
includedAngle = 2.0*_PI-diff_angle(startang, endang);
} else {
includedAngle = diff_angle(endang, startang);
}
double bulge = tan(includedAngle/4.0);
That it!
So to make it!
AcDbPolyline *plx = new AcDbPolyline;
plx->addVertexAt(0, pt1, bulge);
plx->addVertexAt(1, pt3, 0.0);
now Append the entity to the database and you are done!
Regards Gary.
[url]www.drcauto.com[/url]
#define ANG360 (2.0*_PI)
double diff_angle(double a1x, double a2x )
{
double delta;
double a1, a2;
a1 = fmod(a1x, ANG360);
a2 = fmod(a2x, ANG360);
if(fabs(a1) > _PI ) {
if( a1 < 0.0 )
a1 += ANG360;
else
a1 -= ANG360;
}
if (fabs(a2) > _PI) {
if( a2 < 0.0 )
a2 += ANG360;
else
a2 -= ANG360;
}
delta = a1 - a2;
if(delta > ANG360) {
delta = fmod(delta, ANG360);
}
if(fabs(delta) > _PI) {
if(delta < 0.0 )
delta += ANG360;
else
delta -= ANG360;
}
return delta;
} |
|