1 / 7

Lecture 04: Intersection

Lecture 04: Intersection. January 29, 2013 COMP 150-2 Visualization. Admin. Citing other people’s work Online references Grading

chad
Download Presentation

Lecture 04: Intersection

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 04:Intersection January 29, 2013 COMP 150-2Visualization

  2. Admin • Citing other people’s work • Online references • Grading • Note: the “posting online” requirement will be judged during the time of the demo. If the page doesn’t load, the student will not receive credit. There will be no “real time debugging”! • Grading Rubric • frame.setResizable(true); • Caveat – does not work in a browser!!

  3. Testing for 2D Intersections • With known geometry (e.g. with a circle, or with a square) • With known geometry, but rotated/translated/scaled/sheared (affine transforms) • Transformation stack – inverse transform • Isomorphic shapes (applies to invertible deformation) • With geometry made up of defined line segments • With unknown geometry

  4. Line-Line Intersection • Given two points P(Px, Py), Q(Qx, Qy) • Solve for the line equation: • ax + by = c • Start by finding y = mx + d • Note that m is the slope… • Plug in the numbers, solve for m and d • Rearrange to find a, b, c • General form: • (py – qy)x + (qx – px)y = (qxpy - pxqy)

  5. Line-Line Intersection • Given ax + by = c for two line segments, find it they intersect • a1x + b1y = c1 • a2x + b2y = c2 • Multiply the top equation by b2, bottom by b1 • a1b2 x + b1b2 y = c1b2 • a2b1 x + b1b2 y = c2b1 • Subtract bottom by top • (a1b2 –a2b1)x = (c1b2 –c2b1) • X = (c1b2 – c2b1) / (a1b2 – a2b1); • Multiply the top equation by a2, bottom by a1 • a1a2 x + b1a2 y = c1a2 • a1a2 x + b2a1 y = c2a1 • Same as above, get • Y = (c1a2 – c2a1) / (b1a2 – b2a1), //which is the same as • Y = (c2a1 – c1a2) / (b2a1 – b1a2); //rearrange the det • Y = (c2a1 – c1a2) / (a1b2 – a2b1);

  6. Line-Line Intersection double det = A1*B2 - A2*B1 if(det== 0) { //Lines are parallel } else { double x = (B2*C1 - B1*C2)/det double y = (A1*C2 - A2*C1)/det } //need to check for the range if doing line-segment to line-segment test

  7. Questions?

More Related