线段长度计算以及相交、平移和旋转算法.pdfVIP

  • 2
  • 0
  • 约1.83千字
  • 约 1页
  • 2023-08-13 发布于上海
  • 举报

线段长度计算以及相交、平移和旋转算法.pdf

线段长度计算以及相交、平移和旋转算法 线段平移。 function Line(from, to, color, dasharray){ this.from = from ; this.to = to; this.color = typeof(color)==undefined?black:color; this.dasharray = typeof(dasharray)==undefined?false :dasharray; } 移动⽅法 Line.prototype.move = function(d){ var r = Math.atan2(this.to.x-this.from.x, this.to.y-this.from.y)+Math.PI/2; var x = Math.sin(r)*d, y = Math.cos(r)*d; var x1 = this.from.x+x, y1 = this.from.y+y; var x2 = this.to.x+x, y2 = this.to.y+y; return new Line(new Point(x1, y1),new Point(x2, y2)); }; 旋转 Line.prototype.rotate = function(alpha){ var l = Math.round(Math.sqrt( Math.pow((this.to.y-this.from.y), 2) + Math.pow((this.to.x-this.from.x), 2))); var r = Math.atan2(this.to.y-this.from.y, this.to.x-this.from.x)+Math.PI*alpha/180; var x = Math.cos(r)*l, y = Math.sin(r)*l; //var x2 = this. console.log(r: + r + , beta: + Math.round(180*(r/Math.PI)) + , length: + l); var x2 = this.from.x+x, y2 = this.from.y+y; return new Line(this.from, new Point(x2, y2)); }; 根据起点和⾓度、长度创建线段 var LineMaker = { make: function(from, alpha, l){ var to = new Point( from.x+l*Math.cos(Math.PI*alpha/180), from.y+l*Math.sin(Math.PI*alpha/180) ); return new Line(from, to); } }

文档评论(0)

1亿VIP精品文档

相关文档