Google 幻灯片旋转矩形 35 度
Google Slides Rotate Rectangle 35 degrees
我正在尝试了解 Google 幻灯片 API 旋转功能。
3000000 是对象的宽度和高度。
如果我们想逆时针旋转Rectangle 35度,
试图理解文档中的示例参数,以及如何旋转 https://developers.google.com/slides/samples/transform
- 下面的-0.5和0.3是多少?它们是如何推导出来的?
- 此外,-2000000 和 -550000 是什么?
最后好奇是否有任何 shorthand 方法可以做到这一点?三个请求15行,就为了旋转一个矩形?
{
"requests": [
{
"updatePageElementTransform": {
"objectId": pageElementId,
"applyMode": "RELATIVE",
"transform": {
"scaleX": 1,
"scaleY": 1,
"translateX": -2000000 - 0.5 * 0.3 * 3000000,
"translateY": -550000 - 0.5 * 0.12 * 3000000,
"unit": "EMU"
}
}
},
{
"updatePageElementTransform": {
"objectId": pageElementId,
"applyMode": "RELATIVE",
"transform": {
"scaleX": cos(35 * (pi/180)),
"scaleY": cos(35 * (pi/180)),
"shearX": sin(35 * (pi/180)),
"shearY": -sin(35 * (pi/180)),
"unit": "EMU"
}
}
},
{
"updatePageElementTransform": {
"objectId": pageElementId,
"applyMode": "RELATIVE",
"transform": {
"scaleX": 1,
"scaleY": 1,
"translateX": 2000000 + 0.5 * 0.3 * 3000000,
"translateY": 550000 + 0.5 * 0.12 * 3000000,
"unit": "EMU"
}
}
}
]
}
顺便说一下,刚刚打开了 shorthand 旋转的功能请求,现在会尝试弄清楚 https://issuetracker.google.com/u/2/issues/183986639
答案:
在幻灯片中完成形状转换时,所有操作都是从页面原点的参照系完成的。这个点就是页面的左上点。
更多信息:
在 Transform Operations 页面的顶部,它指出页面上的示例假定存在定义的箭头形状:
For these examples, assume that there exists an example arrow shape page element with the following size and transform data (which can be found with a presentations.pages.get request):
{
"objectId": pageElementId,
"size": {
"width": {
"magnitude": 3000000,
"unit": "EMU"
},
"height": {
"magnitude": 3000000,
"unit": "EMU"
}
},
"transform": {
"scaleX": 0.3,
"scaleY": 0.12,
"shearX": 0,
"shearY": 0,
"translateX": 2000000,
"translateY": 550000,
"unit": "EMU"
},
"shape": {
"shapeType": "RIGHT_ARROW"
}
}
所以回答你的前两个问题:
- 0.3取自箭头的缩放系数。
- -2000000 和 -550000 用于将形状转换为页面原点
- -0.5 用于将平移距离减半(因为我们从形状的中心而不是顶点进行旋转)
此外,来自 Sizing and Positioning Page Elements 的文档(强调我自己的):
Rotation transforms rotate a page element around a point, using the scaling and shear parameters. The basic rotation transform matrix has the following form, where the angle of rotation (in radians) is measured from the X-axis, moving counterclockwise:
As with scaling, you can use this matrix form directly as a RELATIVE transform to rotate an element, but this causes the element to be rotated about the origin of the page. To rotate the element about its center or a different point, shift to that reference frame.
如此简单的回答:是的,您可以在一个请求中完成,但是您必须自己进行计算以转移到元素的参考系,然后将 that 请求发送到API 相反。
参考文献:
我正在尝试了解 Google 幻灯片 API 旋转功能。
3000000 是对象的宽度和高度。 如果我们想逆时针旋转Rectangle 35度,
试图理解文档中的示例参数,以及如何旋转 https://developers.google.com/slides/samples/transform
- 下面的-0.5和0.3是多少?它们是如何推导出来的?
- 此外,-2000000 和 -550000 是什么?
最后好奇是否有任何 shorthand 方法可以做到这一点?三个请求15行,就为了旋转一个矩形?
{
"requests": [
{
"updatePageElementTransform": {
"objectId": pageElementId,
"applyMode": "RELATIVE",
"transform": {
"scaleX": 1,
"scaleY": 1,
"translateX": -2000000 - 0.5 * 0.3 * 3000000,
"translateY": -550000 - 0.5 * 0.12 * 3000000,
"unit": "EMU"
}
}
},
{
"updatePageElementTransform": {
"objectId": pageElementId,
"applyMode": "RELATIVE",
"transform": {
"scaleX": cos(35 * (pi/180)),
"scaleY": cos(35 * (pi/180)),
"shearX": sin(35 * (pi/180)),
"shearY": -sin(35 * (pi/180)),
"unit": "EMU"
}
}
},
{
"updatePageElementTransform": {
"objectId": pageElementId,
"applyMode": "RELATIVE",
"transform": {
"scaleX": 1,
"scaleY": 1,
"translateX": 2000000 + 0.5 * 0.3 * 3000000,
"translateY": 550000 + 0.5 * 0.12 * 3000000,
"unit": "EMU"
}
}
}
]
}
顺便说一下,刚刚打开了 shorthand 旋转的功能请求,现在会尝试弄清楚 https://issuetracker.google.com/u/2/issues/183986639
答案:
在幻灯片中完成形状转换时,所有操作都是从页面原点的参照系完成的。这个点就是页面的左上点。
更多信息:
在 Transform Operations 页面的顶部,它指出页面上的示例假定存在定义的箭头形状:
For these examples, assume that there exists an example arrow shape page element with the following size and transform data (which can be found with a presentations.pages.get request):
{ "objectId": pageElementId, "size": { "width": { "magnitude": 3000000, "unit": "EMU" }, "height": { "magnitude": 3000000, "unit": "EMU" } }, "transform": { "scaleX": 0.3, "scaleY": 0.12, "shearX": 0, "shearY": 0, "translateX": 2000000, "translateY": 550000, "unit": "EMU" }, "shape": { "shapeType": "RIGHT_ARROW" } }
所以回答你的前两个问题:
- 0.3取自箭头的缩放系数。
- -2000000 和 -550000 用于将形状转换为页面原点
- -0.5 用于将平移距离减半(因为我们从形状的中心而不是顶点进行旋转)
此外,来自 Sizing and Positioning Page Elements 的文档(强调我自己的):
Rotation transforms rotate a page element around a point, using the scaling and shear parameters. The basic rotation transform matrix has the following form, where the angle of rotation (in radians) is measured from the X-axis, moving counterclockwise:
As with scaling, you can use this matrix form directly as a RELATIVE transform to rotate an element, but this causes the element to be rotated about the origin of the page. To rotate the element about its center or a different point, shift to that reference frame.
如此简单的回答:是的,您可以在一个请求中完成,但是您必须自己进行计算以转移到元素的参考系,然后将 that 请求发送到API 相反。