Hi
The following mockup image shows a full circle for which I know the origin coords (ox,oy) and radius.
I don't want to draw the whole circle, however, I just want to draw the black solid section of the circle's circumference (x1,y1 to x4,y4). I've been looking at the documentation on arcs, bezier curves etc but am not sure how to approach this.
Furthermore, what I ultimately want to do is draw a filled shaped that goes from x1,y1 -> x2,y2 -> x3,y3 -> x4,y4 and incorporates the arc (the line/stroke colour would be the same all the way round unlike the mockup above). I figure the "path" draw method is the one I need for this purpose but don't know how to do the arc part of it.
Can anyone help on this please?
Arcs, Beziers & Paths
Re: Arcs, Beziers & Paths
I am not great at maths but this method should work:
Code: Select all
convert -size 200x160 xc:White -stroke black -strokewidth 1 -fill red -draw " polyline 50,50 50,100 150,100 150,10 bezier 50,50 100,15 150,10 " output.jpg
Re: Arcs, Beziers & Paths
Yes, I see that looks about right.. where did you get the coords "100,15" from? I note they represent a point in space above the arc/curve but how do you calculate that in my example?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Arcs, Beziers & Paths
This following will draw just the arc. see see http://www.imagemagick.org/Usage/draw/#circles
convert -size 100x60 xc: -stroke red -fill none -draw "ellipse 50,30 25,25 225 255" show:
where "ellipse xcenter,ycenter radius,radius angle, angle"
where angle is measured as 0 pointing due east (right) and increases clockwise. So I have a center at 50,30 a radius=25 and the perimeter is drawn between 225deg and 255deg.
You can then draw straight lines for the other sections. The you can floodfill the interior of the area you want given any point inside the region (for example just average the 4 x coords and the 4 y coords and use that as the start point for the floofill). See http://www.imagemagick.org/Usage/draw/#color
You can do all the drawing in one command (which is unix syntax and assumes you have done all the calculations ahead of time and put those values into variables)
convert -size WidthxHeight xc: -stroke black -fill none -draw "ellipse $ox,$oy $radius,$radius, $ang1,$ang4 line $x4,$y4 $x3,$y3 line $x3,$y3 $x2,$y2 line $x2,$y2 $x1,$y1 color $xave,$yave floofill" show:
radius=`convert xc: -format "%[fx:hypot(($y1-$oy),($x1-$ox))]" info:
Given your diagram, the Width and Height are the size of your image, the angles are
ang1=`convert xc: -format "%[fx:180+atan(abs($y1-$oy),abs($x1-$ox))]" info:
ang4=`convert xc: -format "%[fx:180+atan(abs($y4-$oy),abs($x4-$ox))]" info:
If you only want the filled area, you can add -trim +repage to trim the image down to the bounding box around the filled area.
convert -size 100x60 xc: -stroke red -fill none -draw "ellipse 50,30 25,25 225 255" show:
where "ellipse xcenter,ycenter radius,radius angle, angle"
where angle is measured as 0 pointing due east (right) and increases clockwise. So I have a center at 50,30 a radius=25 and the perimeter is drawn between 225deg and 255deg.
You can then draw straight lines for the other sections. The you can floodfill the interior of the area you want given any point inside the region (for example just average the 4 x coords and the 4 y coords and use that as the start point for the floofill). See http://www.imagemagick.org/Usage/draw/#color
You can do all the drawing in one command (which is unix syntax and assumes you have done all the calculations ahead of time and put those values into variables)
convert -size WidthxHeight xc: -stroke black -fill none -draw "ellipse $ox,$oy $radius,$radius, $ang1,$ang4 line $x4,$y4 $x3,$y3 line $x3,$y3 $x2,$y2 line $x2,$y2 $x1,$y1 color $xave,$yave floofill" show:
radius=`convert xc: -format "%[fx:hypot(($y1-$oy),($x1-$ox))]" info:
Given your diagram, the Width and Height are the size of your image, the angles are
ang1=`convert xc: -format "%[fx:180+atan(abs($y1-$oy),abs($x1-$ox))]" info:
ang4=`convert xc: -format "%[fx:180+atan(abs($y4-$oy),abs($x4-$ox))]" info:
If you only want the filled area, you can add -trim +repage to trim the image down to the bounding box around the filled area.