C++/MFC project [6] - drawing elliptical arc

1. Drawing ellipse arc function——Arc() function

When drawing an elliptical arc, four points are needed: P1(x1,y1) P2(x2,y2) P3(x3,y3) P4(x4,y4). Among them, P1 and P2 are the diagonal vertices of a rectangle, and the ellipse arc we want to draw will be intercepted on the inscribed ellipse of this rectangle.

As shown in the figure below, starting from the center point of the rectangle, draw two rays in the direction of P3 and P4 respectively, and the elliptical arc is the part between the two rays (the default drawing direction is counterclockwise). If P3 (P4) happens to be on the elliptical arc, draw the arc with this point as the starting point (end point).

1、Arc(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4)

The meaning of the parameter is the coordinates of four points, (x1, y1) (x2, y2) are the diagonal vertices of the rectangle, (x3, y3) (x4, y4) are the two points that lead out the ray.

2、Arc(LPCRECT lpRect, POINT pStart, POINT pEnd)

Passing the parameter Rect has been used in the previous example , so I won't repeat it here. The meanings of pStart and pEnd are the same as those of P3 and P4 above.

Two, examples

Requirements: In the client area, from twelve o’clock to three o’clock, use black solid line to draw an elliptical arc counterclockwise; from twelve o’clock to three o’clock, use blue dotted line to draw an elliptical arc, and two segments constitute a complete oval.

CPoint Twelve(rect.CenterPoint().x, rect.Height() / 2), Three(rect.Width() / 2, rect.CenterPoint().y);//获取客户区参数
pDC->Arc(rect, Twelve, Three);//起点为十二点方向,终点为三点方向,逆时针绘制椭圆弧
pDC->SetArcDirection(AD_CLOCKWISE);//设置方向函数参数为顺时针
CPen NewPen, * OldPen;//新画笔,旧画笔指针
NewPen.CreatePen(PS_DASHDOT, 1, RGB(0, 0, 255));//点划线,宽度1像素,蓝色
OldPen = pDC->SelectObject(&NewPen);//新画笔选入设备上下文并保留原指针
pDC->Arc(rect, Twelve, Three);//绘制十二点到三点的椭圆弧,方向为顺时针
pDC->SelectObject(OldPen);//恢复原设备上下文

The result of the operation is as follows

It can be seen that when drawing an elliptical arc, you can also use the rect object combined with the hour number to pass parameters, which saves the process of defining POINT class objects.

Guess you like

Origin blog.csdn.net/zhou2622/article/details/129894301
arc