Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Script: Automatically create ellipse shape that matches user-drawn outline points

Community Expert ,
Sep 29, 2024 Sep 29, 2024

I figured I'd share a Photoshop script I just finished that I'm simply calling "Path Points To Ellipse".

 

It's one that I've imagined for a long time, but was finally possible with the help of AI (I never would have figured this out otherwise lol. And it still took a bunch of fighting with it)

 

What It Does: Lets you draw at least 6 arbitrary path points with the pen tool, and it will automatically create an ellipse such that the points fall along its outline. Or at least as close as possible.

 

Features:

  • Works with any size or rotation angle
  • Will still create the closest match even if the points don't form a "valid" ellipse
  • Does NOT require any underlying image. It goes purely based off the points.
  • The script offers to automatically fetch required 'numeric.js' library file which is used for calculations

 

Use Case Ideas:

  • Creating a ellipse that matches a raster image without having to fuss around with the ellipse tool or free transform tool
  • Testing to see if something is truly an ellipse in the first place, based on the match of the resulting ellipse
  • Just roughly freehanding the points to get an ellipse close to a desired size

 

Demo: 

PathToEllipseExample-optimize.gif

Tips:

  • Based on my testing, it should even work if an ellipse/circular object has been warped by perspective
  • You can try using the content-aware tracing pen tool to quickly create the points automatically, then just use those for the script
  • The points can be drawn in any order. The algorithm doesn't look at the path, just the point coordinates
  • Obviously the more accurately place the points, the more accurate the result
    • While you could theoretically draw all the points close together on one part of the ellipse, it will be more accurate if the points are more spread out along the outline.
    • Though not necessary, it's probably most accurate if you at least place four of the points near the four most extreme "sides" of the original ellipse. Basically it makes the bounds more obvious to the algorithm.
    • You can use more than 6 points, that's the minimum required by the algorithm used.

Download:

 

How It Works (I had the help of the AI to summarize these points 😂😞

  • Uses the Direct Least Squares Fitting of Ellipses method 
  • Minimizes algebraic distance between points and ellipse, subject to an ellipticity constraint
  • Transforms the problem into a generalized eigenvalue problem, solved using linear algebra

 

TOPICS
Actions and scripting
950
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Sep 29, 2024 Sep 29, 2024

A wee heads up that Ellipse is also one of the many Lazy Nuzumi Pro presets as well as modulated Ellipse with saw, sine, square wave overlaid.  As ever, LNP is only available for Windows systems unfortunately

image.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 30, 2024 Sep 30, 2024
LATEST

Oh nice I hadn't heard of that tool but it seems really powerful, I'm definitely going to add that to my figurative toolbox. 🧐

 

Though playing around with it, it seems to serve a different purpose than my script. 

 

Unless I'm mistaken that's more for controlling the brush whereas my goal for the script was to create a pixel-perfect-matched vector shape. Also it seems you need to manully select the major/minor axis and adjust it, which is the same process I was trying to avoid by making the script in the first place. For example in cases where the major axis of the ellipse of something you want to 'trace' is not obvious, you'll still have to play around with it for a bit to line it up.

 

Here's a particularly challenging but random example -- say you wanted to create an ellipse shape layer that circumscribes an object like this stop sign taken at an odd angle. Becuase of the angle, you can't simply draw the ellipse between two of the edge points and expand the minor axis - it won't match. 

ThioJoe_2-1727711957648.png

 

With that photo's perspective, the major axis line actually lies between corner points, so you'd have to play around with it to get it to match. But with the script you can literally just click on each of the points and get a pixel-perfect match.

 

And the key is that it's still an ellipse shape vector -- that's really the main point of the script.

 

ThioJoe_0-1727711717916.png

 

The above example can still be done with the built in ellipse tool, but to get it pixel-perfect I personally had to adjust the skew which still took repeated re-adjustment, and when you adjust the skew Photoshop also makes you convert it to a path instead of an ellipse (being a path vs shape isn't a huge deal since they're both vectors but it's worth mentioning).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines