简体   繁体   English

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

[英]get straight line rotation angle in Google apps script

Trying to get rotation angle of straight line with getRotation() method but it always returning 0.0尝试使用getRotation()方法获取直线的旋转角度,但它始终返回0.0

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

Getting output: on line move from top or bottom always getting rotation 0.0.获取输出:从顶部或底部在线移动始终获得旋转 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.');
  }
 }

Desired output required: Line rotation in angle either it moved from top or bottom.所需的输出:从顶部或底部移动的角度线旋转。

Update : Future scope - I want to get rotation and set rotation of line.更新:未来范围 - 我想获得旋转并设置线的旋转。 If Line inclination < 45° ==> rotate horizontally or Line inclination > 45° ==> rotate vertically.如果线倾角 < 45° ==> 水平旋转或线倾角 > 45° ==> 垂直旋转。 https://prnt.sc/uervkw (line screenshot) https://prnt.sc/uervkw (线路截图)

Rotation != angle of the line:旋转 != 线的角度:

Check 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° .创建具有指定起点和终点的线时,其旋转始终为 0°

If you want to get the actual rotation of a line, based on its start and end points, you have to get the position of these points.如果你想得到一条线的实际旋转,基于它的起点和终点,你必须得到这些点的位置。

You can get these positions via getStart() and getEnd() .您可以通过getStart()getEnd()获得这些位置。 Both these two methods return a Point , whose coordinates can be accessed via getX() and getY() .这两种方法都返回一个Point ,可以通过getX()getY()访问其坐标。

Based on these coordinates, you can calculate the angle between the line and the axis you desire using some basic trigonometry.根据这些坐标,您可以使用一些基本的三角函数计算出线和轴之间的角度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM