Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVG Half Circle: Why is it rotated?

Tags:

html

svg

I am experimenting with SVG elements. I am trying to create a simple half circle but my half circle is rotated for some reason? How can I get the half circle to not rotate?

enter image description here

My methodology is:

  • The SVG 'canvas' is 400 by 400px, th0e half circle will have a radius of 180px
  • MoveTo point: 20,200 - M20,200
  • LineTo: draw a line 360px long & does not change the y position - L360,0
  • ArcTo: draw an arc to complete the circle, the radius of the arc is 180px - A180,180 0 0,1 20,200

In code this is:

<svg width="400" height="400">
    <path d="M20,200 L360,0 A180,180 0 0,1 20,200 z"
        style="fill:#ff0000;
            fill-opacity: 1;
            stroke:black;
            stroke-width: 1"/>
</svg>

PS: If I want to create a pie chart that is only 275degrees, would the best way be to make 2 paths, one 180degrees(the half circle above) & another path of 90 degrees? Or is it possible to create this with 1 Path? Is so would anyone be kind enough to show an example SVG code?

like image 954
sazr Avatar asked Jan 09 '12 04:01

sazr


People also ask

How do you draw a half circle in SVG?

How do you make a half circle in SVG? <svg> with <circle> element is used to create the circles based on center point and a radius. We can aslo create a half circle in SVG using the radius value as a percentage. i.e from 0% to 100%.

How do I draw a circle around SVG?

Code explanation: The cx and cy attributes define the x and y coordinates of the center of the circle. If cx and cy are omitted, the circle's center is set to (0,0) The r attribute defines the radius of the circle.

Which tag of SVG is used to draw a circle?

<circle> The <circle> SVG element is an SVG basic shape, used to draw circles based on a center point and a radius.


1 Answers

When using the lineto command, uppercase-L (L) specifies an absolute coordinate while lowercase-L (l) specifies a relative move. It seems like you wanted to use the relative command.

As far as an example, the pie-chart-like one on the W3 path's page uses a single path:

<path d="M300,200 h-150 a150,150 0 1,0 150,-150 z"
    fill="red" stroke="blue" stroke-width="5" />

produces the red part in this image:

example image

Note the liberal use of lowercase (relative) commands.

like image 56
Nick T Avatar answered Oct 23 '22 22:10

Nick T