以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 SVG/GML/VRML/X3D/XAML 』  (http://bbs.xml.org.cn/list.asp?boardid=21)
----  svg中的polygon元素fill-ruler:nonzero和evenodd问题。  (http://bbs.xml.org.cn/dispbbs.asp?boardid=21&rootid=&id=33730)


--  作者:lgsh2008
--  发布时间:6/3/2006 12:16:00 PM

--  svg中的polygon元素fill-ruler:nonzero和evenodd问题。
svg中的polygon元素fill-ruler:nonzero和evenodd问题。
如何来计算多边形的点是在内部的还是外部的。
<svg width="200px" height="200px" viewBox="0 0 200 200">
<polygon style="fill-rule: nonzero; fill: yellow; stroke: black;"
points="48,16 16,96 96,48 0,48 80,96" />
<polygon style="fill-rule: evenodd; fill: #00ff00; stroke: black;"
points="148,16 116,96 196,48 100,48 180,96" />
</svg>
此主题相关图片如下:
按此在新窗口浏览图片
--  作者:lgsh2008
--  发布时间:6/3/2006 12:18:00 PM

--  
书上有这样的计算方法,但是我没明白意思

Explanation of the Fill Rules
For the sake of completeness, we are describing how these fill-rules work,
but you don't need to know the details in order to use them. The nonzero rule
determines whether a point is inside or outside a polygon by drawing a line from
the point in question to infinity. It counts how many times that line crosses the
polygon's lines, adding one if the polygon line is going right to left, and
subtracting one if the polygon line is going left to right. If the total comes out to
zero, the point is outside the polygon. If the total is nonzero (hence the name)
the point is inside the polygon.
The evenodd rule also draws a line from the point in question to infinity, but it
simply counts how many times that line crosses your polygon's lines. If the total
number of crossings is odd, then the point is inside; if even, then the point is
outside.


--  作者:tamefox
--  发布时间:6/4/2006 2:42:00 PM

--  
从该点画一条无线长的射线,计算该线与polygon线的交点,如果使用的是nonzero填充,则若色射线与polygon相交时polygon线的绘制方向为逆时针,则交点个数加一;若为顺时针,则交点个数减一。若最终交点个数为0,则该点在polygon的外部,否则在polygon的内部。如果使用evenodd填充,则交点数目为实际的交点数据。如果个数为奇数,则该点在polygon的内部,如果是偶数,则该点在polygon的外部。
其实你只要按照人家给的图,然后自己在纸上画一下就能明白,另外可以仔细看一下《基于XML的SVG应用指南》
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
46.875ms