`

两点间直线

 
阅读更多
function getLineDot(a, b){
		var dot = [],
		    x1 = a.x,
			x2 = b.x,
			y1 = a.y,
			y2 = b.y;
		var r = Math.floor(Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
		var theta = Math.atan((x2-x1)/(y2-y1));
		if(((y2-y1)<0 && (x2-x1)>0)||((y2-y1)<0 && (x2-x1)<0))
			theta = Math.PI+theta;
		var dx = Math.sin(theta);
		var dy = Math.cos(theta);
		for(var i = 0; i < r;i++){
			dot.push({x:x1+i*dx,y:y1+i*dy});
		}
		return dot;
	  }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics