我在Inkscape中製作了一個徽標。爲了學習,我想通過SVG中的動畫支持來旋轉徽標中的輪子形狀。計算轉換矩陣應用後的路徑中心
這很容易實現旋轉,但我很難能夠指定正確的旋轉軸。這個形狀是一個齒輪,我想讓它圍繞它的中心旋轉。試錯法給出了xy座標(47.1275,1004.17)(其組件奇怪地是不對稱的,但我想這與Inkscape適用的轉換矩陣有關)是一個很好的近似值(請參見下面的animateTransform標籤),但是我將如何從第一原則得到那個?
<svg xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:cc="http://creativecommons.org/ns#" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 321.281 150.799" xmlns:dc="http://purl.org/dc/elements/1.1/">
<g transform="translate(-9.9178912,-891.57237)">
<g transform="matrix(1.9522781,0,0,1.9522781,4.6434311,-1008.1558)">
<animateTransform attributeType="xml" attributeName="transform" type="rotate" from="0 47.1275 1004.17" to="45 47.1275 1004.17" dur="2s" fill="freeze" additive="sum" repeatCount="indefinite" />
<g transform="matrix(0.65043772,0,0,0.65043772,-143.67477,980.4256)" stroke="#666" stroke-miterlimit="4" stroke-dasharray="none" stroke-width="7.68713093" fill="none">
<path stroke-linejoin="miter" d="m293.404-3.51576c-2.73916,0-5.41514,0.287192-8,0.8125v6.1875c-3.47484,0.838872-6.7198,2.18462-9.6875,4l-4.375-4.375c-2.24264,1.48612-4.29226,3.22977-6.1875,5.125s-3.63888,3.94486-5.125,6.1875l4.375,4.375c-1.81538,2.9677-3.16112,6.21265-4,9.6875h-6.1875c-0.5253,2.58486-0.8125,5.26083-0.8125,8s0.2872,5.41515,0.8125,8h6.1875c0.83888,3.47485,2.18462,6.7198,4,9.6875l-4.375,4.375c1.48612,2.24264,3.22976,4.29227,5.125,6.1875s3.94486,3.63888,6.1875,5.125l4.375-4.375c2.9677,1.81538,6.21266,3.16113,9.6875,4v6.1875c2.58486,0.525308,5.26082,0.8125,8,0.8125,2.73916,0,5.41514-0.287192,8-0.8125v-6.1875c3.47484-0.838872,6.7198-2.18462,9.6875-4l4.375,4.375c2.24264-1.48612,4.29226-3.22977,6.1875-5.125s3.63888-3.94486,5.125-6.1875l-4.375-4.375c1.81538-2.9677,3.16112-6.21266,4-9.6875h6.1875c0.5253-2.58485,0.8125-5.26083,0.8125-8s-0.2872-5.41515-0.8125-8h-6.1875c-0.83888-3.47485-2.18462-6.7198-4-9.6875l4.375-4.375c-1.48612-2.24264-3.22976-4.29227-5.125-6.1875s-3.94486-3.63888-6.1875-5.125l-4.375,4.375c-2.9677-1.81538-6.21266-3.16113-9.6875-4v-6.1875c-2.58486-0.525308-5.26084-0.8125-8-0.8125z" stroke-dashoffset="162" stroke="#666" stroke-linecap="butt" stroke-miterlimit="4" stroke-dasharray="none" stroke-width="7.68713093" fill="none"/>
</g>
</g>
</g>
</svg>
從我在規範讀過我想說應用的變換矩陣
1.9522781 0 4.6434311
0 1.9522781 -1008.1558
0 0 1
和
0.65043772 0 -143.67477
0 0.65043772 980.4256
0 0 1
他們是應用在XYZ座標後(-9.9178912,-891.57237,0)
翻譯轉換?
我想上面的正確分析會讓我看到描述的路徑的左上角點,或者可能是第一個句柄的座標。在那之後,是否必須解析路徑來決定邊界框,從而決定路徑的中心(因爲它涉及一個有點圓形的對象)?
這是不是所有的教訓,不要試圖手動對自由創建的形狀做動畫?
如果您將Inkscape設置爲將轉換應用於路徑值,它可能會看起來更清晰一些。嘗試'Inkscape Prefs>轉換>存儲轉換:優化'。 – 2011-04-12 13:08:17