Cut one SVG <path> from another

I have several SVG paths that look like this:

M204.21121687607624,196.94037184487675L329.92080751248244,195.46306542867487A130,130,0,0,0,244.46261863233696,77.83995929783192Z
M198.39145828733604,195.04941765207442L235.83285625620988,75.03597952801854A130,130,0,0,0,97.55860203112616,119.9640082076644Z

Now I want to add another path, but instead of adding it to the form, cut it from the previous paths. How can i do this?

I could not find information about this in the SVG docs - thanks for your help!

+3
source share
5 answers

You can do this in one way:

M 0,0 l 0,10 10,0 0,-10 -10,0 z m 2,2 l 6,0 0,6 -6,0 0,-6 z

This will draw a 10x10 square with a 6x6 hole cut from the middle

+6
source

SVG . , , .

+1

, ( ), . fill-rule:evenodd ( ), .

, 10x10, 6x6:

<svg xmlns="http://wwww3org/2000/svg" height="200" viewBox="0,0,10,10">
  <path d="M 0,0 h 10 v 10 h -10 z
           M 2,2 v  6 h  6 v  -6 z" /> 
</svg>

, , , :

Track orientation

Stack Snippets

svg path.shape {
  fill: green;
  stroke: #1b1b1b;
  stroke-width: .5px;
}
svg path.arrow {
  fill: yellow;
  stroke: black;
  stroke-width: .1px;
}
svg text {
  font-size: .8px;
  font-family: monospace;
  stroke: navy;
  stroke-width: .1px;
  text-anchor: middle;
  alignment-baseline: middle;
}
svg circle {
  r: .5;
  stroke: navy;
  stroke-width: .1px;
  fill: yellow;
}
<svg xmlns="http://wwww3org/2000/svg" height="200" viewBox="-2,-2,14,14">

  <defs>
    <marker id='arrow' orient="auto"  
          refX='-.9' refY='1'
          markerWidth='2' markerHeight='2' >
      <!-- triangle pointing right (+x) -->
      <path d='M 0,0 V 2 L 1,1 Z' class="arrow"/>
    </marker>
  </defs>    

  <path d="M 0,0 h 10 v 10 h -10 z
           M 2,2 h  6 v  6 h  -6 z"  
        marker-mid='url(#arrow)' class="shape" />
                             
    <circle cx="0" cy="0" />                  
    <text    x="0"  y="0" > 1</text>    
    <circle cx="10" cy="0" />                  
    <text    x="10"  y="0" > 2</text>  
    <circle cx="10" cy="10" />                  
    <text    x="10"  y="10" > 3</text>  
    <circle cx="0" cy="10" />                  
    <text    x="0"  y="10" > 4</text>  
    <circle cx="2" cy="2" />                  
    <text    x="2"  y="2" > 5</text>  
    <circle cx="8" cy="2" />                  
    <text    x="8"  y="2" > 6</text>  
    <circle cx="8" cy="8" />                  
    <text    x="8"  y="8" > 7</text>  
    <circle cx="2" cy="8" />                  
    <text    x="2"  y="8" > 8</text>  
</svg>

<svg xmlns="http://wwww3org/2000/svg" height="200" viewBox="-2,-2,14,14">
 
  <path d="M 0,0 h 10 v 10 h -10 z
           M 2,2 v  6 h  6 v  -6 z" 
        marker-mid='url(#arrow)' class="shape" /> 
   
    <circle cx="0" cy="0" />                  
    <text    x="0"  y="0" > 1</text>    
    <circle cx="10" cy="0" />                  
    <text    x="10"  y="0" > 2</text>  
    <circle cx="10" cy="10" />                  
    <text    x="10"  y="10" > 3</text>  
    <circle cx="0" cy="10" />                  
    <text    x="0"  y="10" > 4</text>  
    <circle cx="2" cy="2" />                  
    <text    x="2"  y="2" > 5</text>  
    <circle cx="2" cy="8" />                  
    <text    x="2"  y="8" > 6</text>      
    <circle cx="8" cy="8" />                  
    <text    x="8"  y="8" > 7</text>  
    <circle cx="8" cy="2" />                  
    <text    x="8"  y="2" > 8</text>  
</svg>

SVG

:

  • M 100,150 () - 100,150 (x, y)
  • M 100,150 (). 100 150 , .

:

  • M x,y - M x,y
  • L x,y - L x,y
  • H x - H x
  • V y - V y
  • Z|z - , ( M)
    : Z - ,

:

  • C cX1,cY1 cX2,cY2 eX,eY - C, , eX,eY
  • S cX2,cY2 eX,eY - S, S|C, eX,eY
  • Q cX2,cY2 eX,eY - Q uadratic Curve eX,eY
  • T eX,eY - T, eX,eY
  • A rX,rY rotation, arc, sweep, eX,eY - A rc rX rY. rotation 0 | 1 arc sweep eX,eY

. , - , . regex ([0-9]*)(\.[0-9]*) $1 . \s*([a-zA-z])\s* \n$1.

:

+1

Vector graphics editors usually provide this for you. In Inkscape, select two paths, and then what operation you want to perform in the Path menu. Illustrator has the same functionality.

0
source

What you are looking for is a collection of operations called logical operations. See this question for more details: Logical operations on the SVG path

0
source

Source: https://habr.com/ru/post/1761399/


All Articles