`
米奇风
  • 浏览: 5026 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

D3.js 探水之旅

阅读更多
svg transform 坐标变换方式
坐标变换的使用方式:


代码:
<g transform="...">  <!--other elements>  ...</g>
1、平移变换(translate)
平移表达式transform="translate(x,y)",即新坐标系的原点在原坐标系的(x,y)处。坐标轴的方向不变。

2、旋转变换(rotate)
transform="rotate(angle cx,cy)"。angle代表旋转角度,缺省单位是“度”,瞬时针为正,逆时针为负。(cx,cy)是旋转中心所在的坐标。若省略旋转中心坐标,则缺省值是(0,0)。

3、伸缩变换(scale)
transform="scale(sx,sy)",sx,sy分别代表x轴方向和y方向拉伸或缩小的比例因子。拉伸:大于1;缩小:小于1。若省略sy,即sy=sx,作等比例缩放。

4、歪斜变换(skew)
transform="skewX(x-angle)"或transform="skewY(y-angle)",x-angle,y-angle分别代表沿x轴和y轴歪斜的角度。

5、矩阵变换(matrix)
transform="matrix(a b c d e f)",这里的六个参数分别是变换矩阵中的六个参数。特点是灵活性大,无论多么复杂的变换,只需进行一次矩阵运算即可。
二维坐标变换基本公式:
      x a c e x1
y = b d f * y1
     1 0 0 1  1
其中 ,x,y是旧坐标,x1,y1是新坐标。

在将svg图形格式转化为其它格式图形的工作中,坐标变换是首当其冲的一件工作,下面我们结合svg规范看看svg
是如何处理坐标变换的,理解了这些,再将其转化成你想要的图形格式的变换方式也就不困难了。
1.svg采用的初始坐标系统是视图坐标系,即屏幕左上角为左边原点,y轴正方向朝下,x轴正方向朝右

2.The value of the transform attribute is a <transform-list>, which is defined as a list of transform  definitions, which are applied in the order provided.
  transform属性的值是一个变换列表,它们将根据在svg文件中的顺序依次起作用。

  解析transform值时,一定要根据各个变换出现的顺序进行处理,而不能根据变换的类型进行处理。

3.The transform attribute is applied to an element before processing any other coordinate or length values supplied for that element. In the element
  <rect x="10" y="10" width="20" height="20" transform="scale(2)"/>
  the x, y, width and height values are processed after the current coordinate system has been scaled uniformly by a factor of 2 by the transform attribute. Attributes x, y, width and height (and any   other attributes or properties) are treated as values in the new user coordinate system, not the   previous user coordinate system.
  如果一个元素使用了transform属性,那么坐标变换时首先要处理的就是transform属性,然后才是其它的坐标
  或者长度或高度的值。例如,在
    <rect x="10" y="10" width="20" height="20" transform="scale(2)"/>
  这样一个元素中,先要把当前的坐标系统进行乘2变换后,才会处理x,y,width和height属性。x,y,width和height(
  还有一些其它与坐标有关的属性)是在新的坐标系统终的值,而不再是原来的用户坐标系统中的值。

  解析处理元素坐标时,首先要处理transform属性,然后才是其它属性。

  http://www.neurobot.cn/node/88
  需要HTML5 SVG支持的浏览器(微软IE9以上,FireFox12以上,谷歌Chrome19以上,Safari5.1以上,Opera12以上,Android浏览器3以上)

0)浏览器的默认长度单位是px(pixels),当然可以明确指定其他的单位,包括em, pt, in, cm, and mm。

通常pixel的坐标体系是左上角为坐标系的原点,X轴方向向右,Y轴方向向下。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics