我用Arc函数画了一段弧,我想直接得到这段弧的两个端点坐标,在windows下好像没有这样的函数,难道需要自己计算吗?
请问,如果需要自己算,怎么算呢?

解决方案 »

  1.   

    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
    );因此,你要用Arc画一段弧,肯定先要知道2个端点的坐标啊!!
      

  2.   


    你用下面的代码画一下就知道了,arc函数中的后两个点不是弧的端点坐标。
    弧的中心点向由这两个点构成的直线引的射线构成的弧 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);
      

  3.   

    椭圆公式没忘吧?
    r = (a * b) / sqrt(cos(A)*cos(A)*b*b + sin(A)*sin(A)*a*a);
    其中
    a,b是椭圆长短轴,(这个是已知吧?)
    角度A是就是你说的射线的角度,(那么cos(A)和sin(A)也已知了)
    r就是你说的中心点到弧端点的长度,
    那么端点坐标就好求了吧。(注意坐标转换!)
      

  4.   

    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);
    double radio; POINT pt; radio = (a*b)*1.0 / sqrt( (sin(angle)*sin(angle))*(a*a) + (cos(angle)*cos(angle))*(b*b)  ) ; long dx,dy;
    dx = (long)(radio*cos(angle));
    dy = (long)(radio*sin(angle)); 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);
      

  5.   

    椭圆参数方程
     x = a * cosA
     y = b * sinA
    A的角度可以根据,nXStart,nYStart和包围矩形中心成的角度来计算
    这个角度可以是atan2(dx,dy)函数自己算得到
      

  6.   

    计算角度 不能用  atan 
    应该用 atan2否则在x的负半轴上计算就会出现错误的
      

  7.   

    谢谢 happy__888([顾问团]寻开心) , atan 在x的负半轴上确实计算错误,应该用 atan2
      

  8.   

    我感觉arc函数不能画出所有形状的弧,比如说我用和短轴a的x坐标重合的线的端点作为arc的后两个坐标参数,那么画出的弧是向右开口的半个弧。我怎样用arc画出向左开口的半个弧呢