1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43:
| procedure TForm1.SetNewPosition(Point1:TPoint; Point2:TPoint; k:Integer); VAR x,y,y2,y2tmp,x2: Integer; a,l: Real; begin x := Point1.X - Point2.X; If x < 0 Then x := -x;
y := Point1.Y - Point2.Y; If y < 0 Then y := -y;
l := sqrt( sqr(x) + sqr(y) ); l := l-k;
a := ( arctan(x/y) ); a := RadToDeg(a);
If (Point1.X <> Point2.X) or (Point1.Y <> Point2.Y) Then begin y2 := round(cos(DegToRad(a)) * l); y2tmp := y2;
If (Point1.Y < Point2.Y) Then y2 := round(Point1.Y + (y-y2)); If (Point1.Y > Point2.Y) Then y2 := round(Point1.Y - (y-y2));
x2 := round(tan(DegToRad(a)) * y2tmp); If (Point1.X > Point2.X) Then x2 := round(Point1.X - (x-x2)); If (Point1.X < Point2.X) Then x2 := round(Point1.X + (x-x2));
Shape1.Left := x2; Shape1.Top := y2; end; |