Riviera Kid 142 Report post Posted December 12, 2006 line-line intersection tutorial i am having trouble solving the expressions for U.b and U.a. As far as i can see this is a simultaeneous equation but i cant seam to get it. I cant get this Cheers 0 Share this post Link to post Share on other sites
jyk 2094 Report post Posted December 12, 2006 Do you mean you're having trouble working out the given solution by hand? If so, perhaps you could post what you've got so far, and explain where you're getting stuck. 0 Share this post Link to post Share on other sites
Riviera Kid 142 Report post Posted December 12, 2006 sorry im an eejit, ive got it now.b(X.4 - X.3) = X.1-X.3 + a(X.2-X.1)b(Y.4 - Y.3) = Y.1-Y.3 + a(Y.2-Y.1) b = X.1-X.3 + (a(X.2-X.1))/(X.4 - X.3)b = Y.1-Y.3 + (a(Y.2-Y.1))/(Y.4 - Y.3)X.1-X.3 + (a(X.2-X.1))/(X.4 - X.3) = Y.1-Y.3 + (a(Y.2-Y.1))/(Y.4 - Y.3)(X.1-X.3 + (a(X.2-X.1)))*(Y.4 - Y.3) = (Y.1-Y.3 + (a(Y.2-Y.1))) * (X.4 - X.3)(X.1-X.3)(Y.4 - Y.3) + (a(X.2-X.1)(Y.4 - Y.3)) = (Y.1-Y.3)(X.4 - X.3) + (a(Y.2-Y.1)(X.4 - X.3))(a(X.2-X.1)(Y.4 - Y.3))- (a(Y.2-Y.1)(X.4 - X.3)) = (Y.1-Y.3)(X.4 - X.3) -(X.1-X.3)(Y.4 - Y.3)a((X.2-X.1)(Y.4 - Y.3)-(Y.2-Y.1)(X.4 - X.3)) = (Y.1-Y.3)(X.4 - X.3) -(X.1-X.3)(Y.4 - Y.3)a = (Y.1-Y.3)(X.4 - X.3) -(X.1-X.3)(Y.4 - Y.3) / ((X.2-X.1)(Y.4 - Y.3)-(Y.2-Y.1)(X.4 - X.3)) could be a mistake in there but its ok, i get the idea. Back in high school i was really good at this, bah.[Edited by - Riviera Kid on December 12, 2006 11:59:41 AM] 0 Share this post Link to post Share on other sites
haphazardlynamed 340 Report post Posted December 12, 2006 since this is homework (or so the link would indicate)and seems to be a simple matter of algebraic manipulation to solve some equationsI'll tell you that my general approach would be...pick the end of one line segment and define it as Origindraw vectors from that Origin to the endpoints of the second line segmentuse vector projection to represent the 2nd segment in a new coordinate system using 1st segment as x axissolve x intercept?profit?keep in mind tho, that's a more geometric approach than algebraicalso I have the benefit of my vector math libaray and I'd be solving this in code not on paper... 0 Share this post Link to post Share on other sites
Zipster 2359 Report post Posted December 12, 2006 There's a standard approach to solving simultaneous equations that should prove useful. First you put your equations into general form:Ax + By = CDx + Ey = FWhere all the variables are on one side, and all constants combine on the other side. The values A, B, D, and E form a 2x2 matrix. You invert this matrix, multiply with the column vector formed by C and F, and you have your solution:x = [(E*C) - (B*F)] / [(A*E) - (D*B)]y = [(A*F) - (D*C)] / [(A*E) - (D*B)]You could also use substitution or elimination once your equations are in the fist form, which is probably what you'd be familiar since that's what's taught in most linear algebra classes (at least pre-university).Edit: typos[Edited by - Zipster on December 12, 2006 3:17:20 PM] 0 Share this post Link to post Share on other sites
pTymN 464 Report post Posted December 12, 2006 (defun get-intersect-point (pntA pntB pntC pntD) "line A-B line C-D intersection test" (let* ((Ax (vector2d-x pntA)) (Ay (vector2d-y pntA)) (Bx (vector2d-x pntB)) (By (vector2d-y pntB)) (Cx (vector2d-x pntC)) (Cy (vector2d-y pntC)) (Dx (vector2d-x pntD)) (Dy (vector2d-y pntD)) (Bx-Ax (- Bx Ax)) (By-Ay (- By Ay)) (Dx-Cx (- Dx Cx)) (Dy-Cy (- Dy Cy)) (denominator (- (* Bx-Ax Dy-Cy) (* By-Ay Dx-Cx))) (Ax-Cx (- (vector2d-x pntA) (vector2d-x pntC))) (Ay-Cy (- (vector2d-y pntA) (vector2d-y pntC))) (rNumerator (- (* Ay-Cy Dx-Cx) (* Ax-Cx Dy-Cy)))) (cond ((= denominator 0) (cond ((OR (/= rNumerator 0) (AND (= By Cy Dy) (OR (AND (< Bx Cx) (< Bx Dx)) (AND (> Bx Cx) (> Bx Dx)))) (AND (< By Cy) (< By Dy)) (AND (> By Cy) (> By Dy))) NIL) (t pntB))) (t (let ((r (/ rNumerator denominator))) (cond ((AND (> r 0) (< r 1)) (let* ((sNumerator (- (* Ay-Cy Bx-Ax) (* Ax-Cx By-Ay))) (s (/ sNumerator denominator))) (cond ((AND (>= s 0) (<= s 1)) (let ((temp (make-vector2d))) (vector2d- pntB pntA temp) (vector2d* temp r temp) (vector2d+ pntA temp temp) temp))))))))))) 0 Share this post Link to post Share on other sites