Drawing multiple circular arcs dynamically using SVG

后端 未结 1 1114
心在旅途
心在旅途 2021-01-20 16:34

I\'ve got SVG image (code below):

\"SVG




        
1条回答
  •  时光取名叫无心
    2021-01-20 17:20

    SVG arcs are drawn with A rx ry rotation large-arc-flag sweep-flag x y The key parameters here are rx and ry: the radii of the arc and x and y which are the final point in the arc.

    For example, if you have a circle centred on (cx, cy) with radius r, you can create and arc around it, d units from the edge of the circle with:

    This arc will be in the lower, right quadrant because of where it starts (cx, cy+r+d) and ends (cx+r+d, cy).

    So call the radius of the inner arc r and the radius of the outer arc r + d. Now we need to know where to start and stop the arc. The x-coordinate of the start and stop points is d units to the left of the cx. We can find the y-coordinate by using Pythagoras's theorem to calculate the height of the triangle with a hypotenuse of r+d and a base of d: h = sqrt((r + d)^2 - d^2).

    The code for the arc will therefore be:

    d="M cx-d, 50 L cx-d, cy-h A r+d r+d 0 0 0 cx-d, cy+h L cx-d, 240"

    For example, with (cx, cy) = (100, 150), r = 50, and d = 10

    
    
    
    

    Does that make sense?

    0 讨论(0)
提交回复
热议问题