已知圆弧、扇形的中心点ptCT、起始点ptDrawStart、终点ptDrawEnd、选择框的LT/RB点、起始角度StartAngle、圆弧或扇形对应的角度SweepAngle、半径Radius等
一、点选
在while循环中,根据SweepAngle角度的自增或自减,然后来根据中心点、偏移角度、起点算得偏移后的pt点,然后拿pt点与传进来的点ptReserve(如果对线被旋转缩放过,会进代码中的反旋转缩放回来)点计算距离。如果两点距离小于等于线宽,则判定是在圆弧或扇形上的弧线点。
扇形还需通过点是否在两边直线上,可以判定点是否在两点线段上来判定是否在两边直线上。
如果扇形是填充的,点在扇形里面怎么判断呢?也可以通过上面的while(SweepAngle)循环中判断该点是否在中心点与弧线上点的两点线段直线上。
1 //点旋转 2 //CPoint ptReserve; 3 //ReservePoint(pt, ptReserve); 4 CPoint ptReserve = pt; 5 if (m_dbAngle != 0 || m_dbXZoomScale != 1 || m_dbYZoomScale != 1) 6 {//根据旋转缩放后的点求旋转缩放前的点,如果没有旋转缩放不会进 7 double y = (m_xform.eDy - pt.y + pt.x* m_xform.eM12/m_xform.eM11 - m_xform.eDx*m_xform.eM12/m_xform.eM11)/(m_xform.eM21*m_xform.eM12/m_xform.eM11-m_xform.eM22); 8 double x = (pt.x - y*m_xform.eM21 - m_xform.eDx)/m_xform.eM11; 9 ptReserve = CPoint((int) x, (int) y); 10 } 11 12 if (m_bSelectFrameIsShow) 13 { 14 if (m_pWBImageButton != NULL) 15 { 16 if (m_pWBImageButton->IsInButtonArea(pt)) //判断点是否在选择框的按钮上 17 { 18 return WB_PS_SELECTBUTTON; 19 } 20 } 21 22 if (m_pRectSelect != NULL && m_pRectSelect->PointIn(pt)) //判断点是否在选择框内 23 { 24 return WB_PS_SELECTFRAME; 25 } 26 27 return WB_PS_NONE; 28 } 29 XAutoLock lock(m_csSectorItemLock); 30 if (m_pWBSectorItem->bIsFillSolid || !m_bHaveFillRgn) //如果是填充的,或者没有填充区域 31 { 32 if (PointIn(ptReserve)) 33 { 34 return WB_PS_OBJ; 35 } 36 return WB_PS_NONE; 37 } 38 else 39 { 40 41 int nWidth = m_pWBSectorItem->nWidth/2; 42 double dbZoomScale = GetXZoomScale() > GetYZoomScale() ? GetXZoomScale() : GetYZoomScale(); 43 nWidth = (int)((nWidth * dbZoomScale) > WB_OBJECT_SELECT_SEGMENT ? (nWidth * dbZoomScale) : WB_OBJECT_SELECT_SEGMENT); 44 45 double dSweepAngle = m_pWBSectorItem->dSectorSweepAngle; 46 CPoint ptTemp; 47 CPoint ptDrawStart = m_pWBSectorItem->ptDrawStart; 48 double dDistan = 0; 49 //根据选择角度的自增、自减,通过起点旋转得到旋转角度后的点,判断这些点到中心点的距离是否为半径大小 50 if (dSweepAngle > 0) 51 { 52 while(dSweepAngle > 0) 53 { 54 PointRotationPoint(m_pWBSectorItem->ptSectorCT,dSweepAngle, ptDrawStart, ptTemp); 55 if (CalDistancePointToPoint(ptTemp, ptReserve) < nWidth) 56 { 57 return WB_PS_OBJ; 58 } 59 dSweepAngle -= 1; 60 } 61 } 62 else 63 { 64 while(dSweepAngle < 0) 65 { 66 PointRotationPoint(m_pWBSectorItem->ptSectorCT, dSweepAngle, ptDrawStart, ptTemp); 67 if (CalDistancePointToPoint(ptTemp, ptReserve) < nWidth) 68 { 69 return WB_PS_OBJ; 70 } 71 dSweepAngle += 1; 72 } 73 } 74 //判断是否在边线上 75 if (CWBObject::PointInLine(ptReserve, m_pWBSectorItem->ptDrawStart, m_pWBSectorItem->ptSectorCT, m_pWBSectorItem->nWidth) 76 || CWBObject::PointInLine(ptReserve, m_pWBSectorItem->ptDrawEnd, m_pWBSectorItem->ptSectorCT, m_pWBSectorItem->nWidth)) 77 { 78 return WB_PS_OBJ; 79 } 80 else 81 { 82 return WB_PS_NONE; 83 } 84 85 }