Показать сообщение отдельно
Старый 10.07.2011, 12:59
Scorp2008 вне форума Посмотреть профиль Отправить личное сообщение для Scorp2008 Найти все сообщения от Scorp2008
  № 3  
Ответить с цитированием
Scorp2008

Регистрация: Dec 2009
Сообщений: 42
Функция та есть, вон она:

Код AS3:
		public static function InterLineLine(p1, p2, p3, p4) {
			var distAB, theCos, theSin, newX, ABpos;
			var NO = -1;
			//  Fail if either line segment is zero-length.
			var Ax, Ay, Bx, By, Cx, Cy, Dx, Dy;
			Ax = p1.x;
			Ay = p1.y;
			Bx = p2.x;
			By = p2.y;
			Cx = p3.x;
			Cy = p3.y;
			Dx = p4.x;
			Dy = p4.y;
			//  Fail if either line segment is zero-length.
			if (Ax == Bx && Ay == By || Cx == Dx && Cy == Dy) {
				return -1;
			}
			//  Fail if the segments share an end-point.                  
			if (Ax == Cx && Ay == Cy || Bx == Cx && By == Cy || Ax == Dx && Ay == Dy || Bx == Dx && By == Dy) {
				return -2;
			}
			//  (1) Translate the system so that point A is on the origin.                  
			Bx -= Ax;
			By -= Ay;
			Cx -= Ax;
			Cy -= Ay;
			Dx -= Ax;
			Dy -= Ay;
			//  Discover the length of segment A-B.
			distAB = Math.sqrt(Bx*Bx+By*By);
			//  (2) Rotate the system so that point B is on the positive X axis.
			theCos = Bx/distAB;
			theSin = By/distAB;
			newX = Cx*theCos+Cy*theSin;
			Cy = Cy*theCos-Cx*theSin;
			Cx = newX;
			newX = Dx*theCos+Dy*theSin;
			Dy = Dy*theCos-Dx*theSin;
			Dx = newX;
			//  Fail if segment C-D doesn't cross line A-B.
			if (Cy<0 && Dy<0 || Cy>=0 && Dy>=0) {
				return -3;
			}
			//  (3) Discover the position of the intersection point along line A-B.                  
			ABpos = Dx+(Cx-Dx)*Dy/(Dy-Cy);
			//  Fail if segment C-D crosses line A-B outside of segment A-B.
			if (ABpos<0 || ABpos>distAB) {
				return -4;
			}
			//  (4) Apply the discovered position to line A-B in the original coordinate system.                  
			var oX = Ax+ABpos*theCos;
			var oY = Ay+ABpos*theSin;
			//  Success.
			return {x:oX, y:oY};
		}
А вот насчёт остального я полный нуб, не знаю как использовать совсем А функции эти мне передал знакомый, который использовал эти функции с своих играх, но он мне помочь не может занят весь, еле выпросил сами функции.