SVG: preventing transparent gaps between adjacent polygons

Consider the following small SVG showing two adjacent triangles:

<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" version="1.1">
   <polygon points="10,0  60,0  35,50" style="fill:#cc4444;"/>
   <polygon points="35,50 85,50 60,0" style="fill:#cc3333;"/>
</svg>

In my browser, it looks like this

svg

Pay attention to the white line between the polygons. Although I understand that the mixing used is the reason, this behavior is very annoying when you try to make, for example, a mathematical surface, as shown here .

What is the right solution in SVG to close these gaps? One way is to give the polygons small strokewith the same color, but it looks more like a hack for me, and in a graph with a lot of polygons it significantly increases the file size.

+4
source
1

shape-rendering="crispEdges" <svg> , . , , . , . - , , , .

<!-- Standard SVG -->
<svg width="180" height="180" viewBox="0 0 180 180">
<g transform="translate(90,90)">
<path d="M0 0 0.00 -90.00 70.36 -56.11Z" fill="#323232" />
<path d="M0 0 70.36 -56.11 87.74 20.03Z" fill="#4b4b4b" />
<path d="M0 0 87.74 20.03 39.05 81.09Z" fill="#646464" />
<path d="M0 0 39.05 81.09 -39.05 81.09Z" fill="#7d7d7d" />
<path d="M0 0 -39.05 81.09 -87.74 20.03Z" fill="#969696" />
<path d="M0 0 -87.74 20.03 -70.36 -56.11Z" fill="#afafaf" />
<path d="M0 0 -70.36 -56.11 0.00 -90.00Z" fill="#c8c8c8" />
</g>
</svg>

<!-- Crisp edges -->
<svg width="180" height="180" viewBox="0 0 180 180" shape-rendering="crispEdges">
<g transform="translate(90,90)">
<path d="M0 0 0.00 -90.00 70.36 -56.11Z" fill="#323232" />
<path d="M0 0 70.36 -56.11 87.74 20.03Z" fill="#4b4b4b" />
<path d="M0 0 87.74 20.03 39.05 81.09Z" fill="#646464" />
<path d="M0 0 39.05 81.09 -39.05 81.09Z" fill="#7d7d7d" />
<path d="M0 0 -39.05 81.09 -87.74 20.03Z" fill="#969696" />
<path d="M0 0 -87.74 20.03 -70.36 -56.11Z" fill="#afafaf" />
<path d="M0 0 -70.36 -56.11 0.00 -90.00Z" fill="#c8c8c8" />
</g>
</svg>

<!-- Null filter -->
<svg width="180" height="180" viewBox="0 0 180 180">
<defs>
<filter id="null">
<feBlend mode="normal" in="SourceGraphic"/>
</filter>
</defs>
<g transform="translate(90,90)" filter="url(#null)">
<path d="M0 0 0.00 -90.00 70.36 -56.11Z" fill="#323232" />
<path d="M0 0 70.36 -56.11 87.74 20.03Z" fill="#4b4b4b" />
<path d="M0 0 87.74 20.03 39.05 81.09Z" fill="#646464" />
<path d="M0 0 39.05 81.09 -39.05 81.09Z" fill="#7d7d7d" />
<path d="M0 0 -39.05 81.09 -87.74 20.03Z" fill="#969696" />
<path d="M0 0 -87.74 20.03 -70.36 -56.11Z" fill="#afafaf" />
<path d="M0 0 -70.36 -56.11 0.00 -90.00Z" fill="#c8c8c8" />
</g>
</svg>
Hide result
+7

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


All Articles