Understanding of GDI + drawing arc interface

Source: Internet
Author: User
Tags in degrees

Author: Zhu Jinchan
Source: http://blog.csdn.net/clever101


GDI + Drawing class graphics drawing arc interface DrawArc
Status DrawArc (in const pen* Pen,
In const rect& Rect,
In REAL StartAngle,
In REAL SweepAngle)


The tutorial explains this interface in this way:
Pen: Brushes
Rect: Defines the rectangle for the arc
StartAngle: The angle measured in degrees clockwise from the x-axis to the starting point of the arc.

SweepAngle: The angle, in degrees, measured clockwise from the startangle parameter to the end point of the arc.


The pen parameter is very good understanding, the so-called arc, the essence is the ellipse part, gdi/gdi+ often uses the ellipse's external rectangle to determine the ellipse shape, therefore the Rect parameter also is very good to understand, only has some questions to some other parameters: first which line represents the x-axis, the second section arc has the two ends, Which end represents the starting point of the arc and which ending point.

So determined to figure out the problem, wrote the following code:


CDC *PDC = Pview->getdc (); Graphics GP (PDC->M_HDC); REAL startangle = 60.0f; Set the starting angle to 60 degrees REAL sweepAngle = 150.0f; Set the rotation angle to 150 degrees Rect ellipseRect2 (10,10,500,500); Gp. DrawEllipse (&greenpen,245,245,2,2); Gp. DrawArc (&bluepen,ellipserect2,startangle,sweepangle); Gp. DrawRectangle (&pen (color::blue), ellipseRect2); Gp. RELEASEHDC (PDC->M_HDC); Pview->releasedc (PDC);


The effect diagram is as follows:



Analyzed the effect diagram, roughly understand the meaning of the parameters of the DrawArc function, and then draw the following image:




Looking at the figure above, we should understand that the so-called X-axis is the center of the external rectangle of the horizontal line, the beginning of the arc is on the right side, the end point is on the left, The above-mentioned sweepangle is the angle (in degrees) measured clockwise from the startangle parameter to the end point of the arc. I think it is more accurate to say that the line that is connected to the center point of the external rectangle and the arc starting point is scanned to the angle of the center point of the bounding rectangle and the starting point of the arc, and sweep has the meaning of scanning.

Thought of here, I think if the scanning angle of more than 360 degrees, you can draw a circle out, and if the starting angle is negative, the arc should be within the first quadrant. Actually, it does. There is also the case that when sweepangle is negative, what is the case? I found that when sweepangle is negative, the arc is scanned counterclockwise. As in the following code:


REAL startangle = 0.0f; REAL sweepAngle = -60.0f; Notice:the SweepAngle is minus Rect ellipseRect2 (10,10,250,250); Gp. DrawEllipse (&greenpen,120,120,2,2); Gp. DrawArc (&bluepen,ellipserect2,startangle,sweepangle); Gp. DrawRectangle (&pen (color::blue), ellipseRect2);


Normal 0 7.8 lbs 0 2 false false MicrosoftInternetExplorer4/* Style definitions */table. msonormaltable {mso-style-name: general form; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; Mso-style-parent: ""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; Mso-pagination:widow-orphan; font-size:10.0pt; Font-family: "Times New Roman"; Mso-fareast-font-family: "Times New Roman"; Mso-ansi-language: #0400; Mso-fareast-language: #0400; Mso-bidi-language: #0400;}

The effect diagram is as follows:










Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.