Sign in to follow this  

line-line equation help

This topic is 4021 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
since this is homework (or so the link would indicate)
and seems to be a simple matter of algebraic manipulation to solve some equations

I'll tell you that my general approach would be...

pick the end of one line segment and define it as Origin
draw vectors from that Origin to the endpoints of the second line segment
use vector projection to represent the 2nd segment in a new coordinate system using 1st segment as x axis
solve x intercept
?profit?


keep in mind tho, that's a more geometric approach than algebraic
also I have the benefit of my vector math libaray and I'd be solving this in code not on paper...

Share this post


Link to post
Share on other sites
There's a standard approach to solving simultaneous equations that should prove useful. First you put your equations into general form:

Ax + By = C
Dx + Ey = F

Where 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]

Share this post


Link to post
Share on other sites

(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)))))))))))

Share this post


Link to post
Share on other sites

This topic is 4021 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this