在 Google 应用程序脚本中获取直线旋转角度

get straight line rotation angle in Google apps script

试图用getRotation()方法获取直线的旋转角度但它总是返回0.0

试过这个方法: https://developers.google.com/apps-script/reference/slides/line#getrotation

获取输出: 从顶部或底部在线移动总是旋转 0.0.

function lineRotation() {
  var selection = SlidesApp.getActivePresentation().getSelection();
  if(selection.getPageElementRange() !== null){

   var pageElements = selection.getPageElementRange().getPageElements()

   // Iterate each page elements
   pageElements.forEach(function(item, index) {
    if(pageElements[index].getPageElementType() == 'LINE'){
    
      var rotation = pageElements[index].asLine().getRotation();
  
 }else{
   SlidesApp.getUi().alert('Please select line.');
 }
});

  }else{
   SlidesApp.getUi().alert('Please select elements.');
  }
 }

所需的期望输出:从顶部或底部移动的角度线旋转。

更新: 未来范围 - 我想要旋转并设置线的旋转。如果线倾角 < 45° ==> 水平旋转或线倾角 > 45° ==> 垂直旋转。 https://prnt.sc/uervkw(线路截图)

旋转!=线的角度:

检查Line rotation

Like other page elements, a line's rotation isn't the vertical angle of the line, but the rotation of its bounding box. When you create a line with specified start and end points, its rotation is always 0°.

如果你想得到一条线的实际旋转,根据它的起点和终点,你必须得到这些点的位置。

您可以通过getStart() and getEnd(). Both these two methods return a Point, whose coordinates can be accessed via getX() and getY()获得这些职位。

根据这些坐标,您可以使用一些基本的三角函数计算出您想要的线与轴之间的角度。