# Trigonometry - Line Length

**URL:** <https://forum.kirupa.com/t/trigonometry-line-length/299757>\
**Category:** flash\
**Created:** [November 10, 2009, 5:02pm UTC](https://forum.kirupa.com/t/trigonometry-line-length/299757 "2009-11-10T17:02:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nasher268](https://avatars.discourse-cdn.com/v4/letter/n/977dab/32.png) [@nasher268](https://forum.kirupa.com/u/nasher268)\
**Post date:** [November 10, 2009, 5:02pm UTC](https://forum.kirupa.com/t/trigonometry-line-length/299757/1 "2009-11-10T17:02:53Z")

</div>

Flash 8 - AS2

I have 2 points moving around on the screen, p1 and p2, every step I want the distance between these points to be 100 .  
I know that the distance between the points is the square root of the distance x squared and distance y squared but how would I change those points to make them 100 apart.

I have had a go but it failed :\*(  
Here is my attempt:

```auto
line.onEnterFrame = function() {
		dx = this.p2._x-this.p1._x;
		dy = this.p2._y-this.p1._y;
		dist = Math.sqrt(dx*dx+dy*dy);
		if (dist != 100) {
			dist -= 100;
			dist /= 2;
			angle = Math.atan2(dy, dx)*180/Math.PI;
			x = Math.cos(angle*Math.PI/180)*dist;
			y = Math.sin(angle*Math.PI/180)*dist*-1;
			this.p1._x += x;
			this.p1._y += y;
			this.p2._x -= x;
			this.p2._y -= y;
		}
		this.clear();
		this.lineStyle(10, 0x000000);
		this.moveTo(this.p1._x, this.p1._y);
		this.lineTo(this.p2._x, this.p2._y);
	};

```

Thanks for any help.
