Skip to main content
Known Participant
February 16, 2011
Question

Way to tell perfect circle from an ellipse?

  • February 16, 2011
  • 3 replies
  • 2890 views

Hi,

I need to tell in my script whether a pathItem is a perfect circle. I have already a simple algorithm but I'm still missing the final test which requires a "bit" of geometry knowledge. My algorithm so far tests if all of the conditions are fulfilled:

  • pathPoints.length==4
  • all points are smooth
  • width == height (calculated using geometricBounds)

The missing test should examine the bezier curve handles, they should be placed at a precise location for each point. Is anyone in the knowledge how to test them? (Well, I would love the test to handle rotated circles as well, but I could live without that.)

I'm on CS3.

Thanks,

Artur

PS> OK, I have read somewhere that bezier curves are unable to reproduce a circle in a perfect way, but let's save that conversation for another day 😉

This topic has been closed for replies.

3 replies

moniuchAuthor
Known Participant
February 16, 2011

Hi guys,

Thanks for your replies.

The area method is tempting, because it would be simple to deal with rotated shapes, but I sort of smell that would not be bulletproof. I imagine a shape made out of a circle by a whirl filter, wherethe area is equal to that of a perfect circle.

As per the traingulation suggestion, I like it much more. I would rather compare all the 8 distances between each handle and its anchor. I think there is a specified distance for a Bezier handle that makes a circle.This would be safest way to go.

Thanks for the hint. Have no idea how you got that 'circumference/12', but it's a good kick!  ...a back-to-school kick ;-)

Have a nice day,

Artur

Muppet_Mark-QAl63s
Inspiring
February 16, 2011

I've read before now that you create a smooth bezier curve by using 1/3 of the curvature which by my guess work/math is circumference/12. Another thing you may want to check out/consider is circle rotated or not the path points anchor should create a perfect square ditto the left handles ditto the right too. If this is correct then you only need measure either side? Geometry is a long forgotten thing with me. But google is you math mate…

Inspiring
February 16, 2011

Draw a circle of 100 pt diameter, center on (0,0), and look at the values Illustrator uses for the control points?

I must admit that 'might be rotated' needs a bit more math than I can think of off Top of Head. In any case, both bezier control points should be aligned with their anchor point, exactly in the middle. See this image (bezier control points come courtesy of my drawArtHandles script ).

Muppet_Mark-QAl63s
Inspiring
February 16, 2011

There should be a right angle between the circle centre, a path point and bezier handle. The distance of the handle should be 'circumference / 12' from the path point. You should be able to work some triangulation from that?

Inspiring
February 16, 2011

Hi Artur,

maybe it is "unfuzzy" enough to compare the pathItem.area(and width/height, and...) with the perfect circle area?

chris