Which API is used to draw a circle ?
2012
Which API is used to draw a circle ?
Answer: B. Ellipse ( ) — Concept: a raster 2D drawing interface identifies each primitive by the outline it is documented to paint, and fixes the individual shape through a bounding…
- A.
Circle ( )
- B.
Ellipse ( )
- C.
Round Rect ( )
- D.
Pie ( )
Attempted by 43 students.
Show answer & explanation
Correct answer: B
Concept: a raster 2D drawing interface identifies each primitive by the outline it is documented to paint, and fixes the individual shape through a bounding rectangle — the smallest axis-aligned rectangle that encloses that outline. Under such a scheme a circle needs no primitive of its own: it is the closed conic whose two axes are equal, so a square bounding rectangle handed to the conic primitive already produces it.
Application: in the Windows GDI drawing interface that conic primitive is Ellipse ( ), declared as BOOL Ellipse(HDC hdc, int left, int top, int right, int bottom).
Ellipse ( ) receives a device context together with the coordinates left, top, right and bottom — the top-left and bottom-right corners of the bounding rectangle.
The curve is inscribed in that rectangle and touches each of its four sides, so its horizontal axis measures right − left and its vertical axis measures bottom − top.
Passing arguments for which right − left equals bottom − top makes those two axes equal in length.
With both axes equal, every point of the curve stands at the same distance from the centre, which is exactly the defining property of a circle.
Ellipse(hdc, 10, 10, 110, 110) therefore paints a circle of diameter 100 centred at (60, 60).
Cross-check: comparing what each of the other GDI drawing calls is documented to paint shows that the conic primitive is the routine meant for this shape.
Drawing call | Outline it is documented to paint |
|---|---|
Ellipse ( ) | The closed conic inscribed in the given bounding rectangle; equal width and height make that conic a circle. |
Round Rect ( ) | A rectangle whose four corners are drawn from a separately sized corner ellipse, with straight edges running between those corners. |
Pie ( ) | A wedge: an elliptical arc closed by the two radii drawn from its ends to the centre. |
Circle ( ) | Not among the GDI drawing routines; the equal-axis case is already covered by the conic primitive. |
Hence the API used to draw a circle is Ellipse ( ), called with a square bounding rectangle. Degenerate arguments to the other calls — a corner ellipse as large as the whole rectangle, or coincident radial endpoints — can also end up tracing a conic, but Ellipse ( ) is the routine documented for that outline, and it is the answer recorded in the official key for this paper.