1

I want to draw an ellipse made out of many sections, such as this: simple_ellipse

The goal is to define with variables the outside and inside diameters, and number of segments, and have the program automatically determine the size and arrangement of the segments.

I have been using rmagick to draw a square made of squares in the past, but I have realized that it becomes much more complicated when you need to factor in the inside and outside curves of the segments.

I could see how I could make one image and "copy/paste" it around.

I am hoping there might be another gem/library which I could use for this that would have some built-in circle methods.

It seems like I could draw them using RVG (ruby vector graphics). I could use the polygon method, but that would require calculating the exact x/y coordinates of the points. I could also use a "path": http://www.w3.org/TR/SVG11/paths.html which would allow bezier curves and elliptical arcs

Any of these methods seem like they would involve a lot of calculation.

My idea is to:

  1. calculate an inside circle, and an outside circle
  2. use the points on those to get the 4 "corners",

This would still need to account for the curved edges. If I picked values larger than the "corners", then I could draw in an inside and outside circle to trim them down.

However, that seems like it is beating the problem with a stick.

Ideally, I would like to move on to more advanced drawings as well, such as: medium_difficulty_elipse

or even enter image description here

Is there any library/gem or even a process which I may be overlooking, that would make this simpler?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Buddy Lamers
  • 239
  • 1
  • 2
  • 6
  • https://github.com/JulienLeonard/XRVG – Hsiu Chuan Tsao Mar 08 '17 at 05:52
  • 2
    It's not an ellipse, it's an [annulus](https://en.wikipedia.org/wiki/Annulus_(mathematics)). With [polar coordinates](https://en.wikipedia.org/wiki/Polar_coordinate_system), it really wouldn't be hard to calculate the corresponding coordinates. You'll have to use `r*cos(alpha)` and `r*sin(alpha)`, and that's about it. – Eric Duminil Mar 08 '17 at 09:23
  • This might interest you http://stackoverflow.com/questions/11479185/svg-donut-slice-as-path-element-annular-sector – Eric Duminil Mar 08 '17 at 09:25

1 Answers1

0

Not sure if this fits the bill, but it may be worth a look:

convert  -size 600x50  xc:black xc:yellow                    \
      \( -size 200x100 xc:lime xc:cyan xc:magenta +append \) \
         -size 600x25 xc:red -size 600x10 xc:blue -append result.png

enter image description here

Now go polar, by changing the last line!

convert -size 600x50 xc:black xc:yellow                    \
    \( -size 200x100 xc:lime xc:cyan xc:magenta +append \) \
      -size 600x25 xc:red -size 600x10 xc:blue -append     \
      -background none -virtual-pixel none -distort polar 0 result.png

enter image description here

Or with spacers:

convert -size 600x50 xc:black xc:yellow xc:none[600x20\!] \( -size 180x100 xc:lime xc:none[20x100\!] xc:cyan xc:none[20x100\!] xc:magenta xc:none[20x100\!] +append \) xc:none[600x30\!] -size 600x25 xc:red -size 600x10 xc:blue -append -background none -virtual-pixel none -distort polar 0 result.png

enter image description here

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432