Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Straightforward algorithm taking into account what you've done so far:</p> <ol> <li>For every shape store all vertices in an array (or list) in order they appear on the shape (clockwise or counter-clockwise doesn't make a difference). This allows you to easily iterate over edges of any given object, because edges are in that case <strong>(P<sub>1</sub>, P<sub>2</sub>)</strong>, <strong>(P<sub>2</sub>, P<sub>3</sub>)</strong>, ... <strong>(P<sub>N</sub>, P<sub>1</sub>)</strong> where <strong>N</strong> is the number of vertices.</li> <li>For every line you want to check if it collides with any object iterate over all edges you've denoted and if line you're checking is crossing any edge - line collides with given object.</li> </ol> <p>Checking crossing of the line with edge is a geometry problem. If bounding-points of line we are checking are <strong>P<sub>1</sub>=(x<sub>1</sub>,y<sub>1</sub>)</strong> and <strong>P<sub>2</sub>=(x<sub>2</sub>,y<sub>2</sub>)</strong>, and bounding points of edge are <strong>P<sub>3</sub>=(x<sub>3</sub>,y<sub>3</sub>)</strong> and <strong>P<sub>4</sub>=(x<sub>4</sub>,y<sub>4</sub>)</strong> then you should solve the linear system:</p> <blockquote> <p><strong>(x<sub>2</sub> - x<sub>1</sub>) y + (y<sub>1</sub> - y<sub>2</sub>) x = x<sub>1</sub> y<sub>2</sub> - x<sub>2</sub> y<sub>1</sub></strong> ,<br> <strong>(x<sub>4</sub> - x<sub>3</sub>) y + (y<sub>3</sub> - y<sub>4</sub>) x = x<sub>3</sub> y<sub>4</sub> - x<sub>4</sub> y<sub>3</sub></strong> . </p> </blockquote> <p>After getting a value for <strong>(x, y)</strong> you should check that it is on parts between bounding-points on both lines (line we're checking and the edge). If that is true your lines cross each other.</p> <p><strong>Note:</strong> You can improve running time by not iterating over every object's edges when you are checking for collision, but only over those objects that are in the path of the line. This could be accomplished for example by calculating minimal rectangle that contains every object, and checking if your line passes through the rectangle, dismissing the object from further checking if it doesn't.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload