# 如何得到弧的端点坐标？

aspiregao 2005-04-06 07:16:32

...全文
153 点赞 收藏 10

10 条回复

hhoking 2005-04-08

r = (a * b) / sqrt(cos(A)*cos(A)*b*b + sin(A)*sin(A)*a*a);

a，b是椭圆长短轴，(这个是已知吧？)

r就是你说的中心点到弧端点的长度，

aspiregao 2005-04-08

pDC->Rectangle(100,100,300,300);
pDC->Ellipse(200-2, 200-2, 200+2, 200+2);

pDC->Arc(100,100,300,300,277,111,245,298);
pDC->MoveTo(277,111);
pDC->LineTo(245,298);

CPen pen(PS_SOLID,0, RGB(255,0,0));
CPen* OldPen = pDC->SelectObject(&pen);
pDC->MoveTo(200,200);
pDC->LineTo(277,111);
pDC->MoveTo(200,200);
pDC->LineTo(245,298);
pDC->SelectObject(OldPen);

aspiregao 2005-04-08

aspiregao 2005-04-08

aspiregao 2005-04-08

x = a * cosA
y = b * sinA
A的角度可以根据，nXStart，nYStart和包围矩形中心成的角度来计算

aspiregao 2005-04-08
to hhoking(妙手仁心)

#include <math.h>
#define PI 3.1415926

//得到弧的角度
double GetArcAngle(LPCRECT lpRect, POINT pt)
{
long a = abs((lpRect->right-lpRect->left)/2);
long b = abs((lpRect->bottom-lpRect->top)/2);

double tanval = 0;
double angle = 0;
tanval = (((lpRect->top+b)-pt.y)*1.0) / ((pt.x-(lpRect->left+a))*1.0) ;

angle = atan(tanval);

return angle;

}

//根据角度得到弧的端点坐标
POINT GetArcPoint(LPCRECT lpRect, double angle)
{
long a = abs((lpRect->right-lpRect->left)/2);
long b = abs((lpRect->bottom-lpRect->top)/2);

POINT pt;

radio = (a*b)*1.0 / sqrt( (sin(angle)*sin(angle))*(a*a) + (cos(angle)*cos(angle))*(b*b) ) ;

long dx,dy;

pt.x = lpRect->left+a + dx;
pt.y = lpRect->top+b - dy;

return pt;
}

CRect rect(100, 100, 400, 200);
POINT pt1;
pt1.x = 377;
pt1.y = 111;

POINT pt2;
pt2.x = 465;
pt2.y = 328;

long cx;
long cy;
cx = rect.left+ (rect.right-rect.left)/2;
cy = rect.top + (rect.bottom-rect.top)/2;

pDC->Rectangle(rect);
pDC->Ellipse(cx-2, cy-2, cx+2, cy+2);

pDC->Arc(&rect, pt1, pt2);
pDC->MoveTo(pt1);
pDC->LineTo(pt2);

CPen* OldPen;
CPen pen1(PS_SOLID,0, RGB(255,0,0));
OldPen = pDC->SelectObject(&pen1);
pDC->MoveTo(cx,cy);
pDC->LineTo(pt1);
pDC->MoveTo(cx,cy);
pDC->LineTo(pt2);
pDC->SelectObject(OldPen);

double angle1;
double angle2;

angle1 = GetArcAngle(&rect, pt1);
pt1 = GetArcPoint(&rect, angle1);

angle2 = GetArcAngle(&rect, pt2);
pt2 = GetArcPoint(&rect, angle2);

CPen pen(PS_SOLID,0, RGB(255,0,255));
OldPen = pDC->SelectObject(&pen);
pDC->MoveTo(pt1);
pDC->LineTo(pt2);
pDC->SelectObject(OldPen);

I_Love_CPP 2005-04-06
Arc
The Arc function draws an elliptical arc.

BOOL Arc(
HDC hdc, // handle to device context
int nLeftRect, // x-coord of rectangle's upper-left corner
int nTopRect, // y-coord of rectangle's upper-left corner
int nRightRect, // x-coord of rectangle's lower-right corner
int nBottomRect, // y-coord of rectangle's lower-right corner
int nXStartArc, // x-coord of first radial ending point
int nYStartArc, // y-coord of first radial ending point
int nXEndArc, // x-coord of second radial ending point
int nYEndArc // y-coord of second radial ending point
);

1.9w+

VC/MFC 图形处理/算法

2005-04-06 07:16