svg transform 座标变换方式

转自:http://xofun.iteye.com/blog/1689597

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轴方向向下。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章