Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.

Channels ▼


Ellipse Specification Using Vectors

Robert is a software engineer and award-winning independent animator. He can be reached at [email protected].

Over the years, I've made heavy use of graphical editing programs and sometimes needed to use ellipse drawing functions. What I've found is that ellipse drawing functions in graphical editing programs typically use bounding boxes for specifying ellipses. This method serves well if the task requires fitting the ellipse within the confines of a box, or if it's not necessary to align the edge of the ellipse with precision. On occasion, however, I've had a need to use an ellipse (or a portion thereof) to approximate a freeform curve. In such cases, bounding boxes serve poorly. Why? Because the outer corner of the bounding box that specifies the ellipse is far enough away from the curve of interest that "eyeballing" placement of the nearest corner of the bounding box to specify an ellipse that approximates the freeform curve is error prone and usually produces erroneous results, as in Figure 1.

The problem is that ellipse curves specified by bounding boxes are physically disconnected from the opposite corners of the box that are actually under user control. This physical disconnect robs users of the ability to place the edge of the ellipse precisely against the freeform curve of interest. To give users the control needed to produce ellipses that approximate the curvature of a freeform curve, it is more expedient to specify an ellipse using points that interpolate (lie on the actual ellipse) rather than exterpolate (in which the ellipse is tied to the points but detached from them). This lets users click directly on the curve and anchor the ellipse to the freeform curve of interest from the outset. One approach is to specify an ellipse from a vector the user specifies. In Figure 2, the user clicks on some point lying upon the freeform curve and drags the end of the vector—along with the corresponding ellipse—until it closely approximates the freeform curve.

Figure 1: "Eyeballing" placement of the nearest corner of the bounding box.

Figure 2: Approximating with a vector-based ellipse.

You can implement this scheme using a uniform interpolating trigonometric spline (TSpline) whose control points lie at the corners of a rectangle. Alternatively, you can use the corners of a rhombus (see "Implementing Uniform Trigonometric Spline Curves"; www.ddj.com/architect/184410198). Both approaches inscribe (rather than circumscribe) the ellipse. In either case, a single vector is sufficient to define the four control points that specify an ellipse formed of a TSpline. For this algorithm, the most practical choice is to implement the TSpline ellipse that is specified by an inscribed rectangle.

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.