{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

homework7

# homework7 - ComputerScience106:MATLAB...

This preview shows pages 1–2. Sign up to view the full content.

Computer Science 106: MATLAB Optional problems: all work due by 4/23 Optional 1: intersecting lines (see: http://bloggingmath.wordpress.com/2009/05/29/line‐segment‐intersection/) Another Euler project problem #165: A straight line can be described by a slope and a point: y = m*(x – Px) +Py You may be more familiar with the form where Px is 0 and Py is where the line intersects the y‐axis. A better representation for our purposes is to write the line in the form L = p +t* r with 0 <= t <= 1 if we have two endpoints for a line, (x1,y1) and (x2,y2), the vector p is just (x1,y1) and the vector r is (x2‐x1, y2‐y1). Similarly, a second line segment M = q +u* s with 0 <= s <= 1 The two lines with t and u taking any values will intersect at a point where p +t* r = q +u* s. This point is found by solving for t and u. To find t, we can take the cross product of each line segment with s: (p + t*r) x s = (q + u*s) x s = q x s + u*(s x s) = q x s (since s x s = 0) so t = (q – p) x s/(r x s) and similarly u = (q – p) x r/ (r x s)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}