Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Lines Primitive collision with Quads  (Read 2714 times)

0 Members and 4 Guests are viewing this topic.

Csharpest

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Lines Primitive collision with Quads
« on: March 10, 2016, 07:50:22 pm »
Hi all,

I'm hoping you guys can help me. I've created my own vertexArray classes via the tutorials available on the site to build a class which displays a two dimensional graph using Lines.

My issue is now I have another vertexArray of Quads, which is the sections of the graph. (like the squares on graph paper). I'm struggling to do collision detection on these two objects.

Is there a way that I can test if a line has passed through a quad shape?
e.g. I have a line at point 0,0 to 100,100. The quads are in sizes of 10,10. Which of these quads have the line passed through?

Many thanks for any and all help, it would be really helpful.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Lines Primitive collision with Quads
« Reply #1 on: March 10, 2016, 07:57:50 pm »
Maybe this article or this article will be of some help.

Found them by googling "collision line with rectangle" :P
« Last Edit: March 10, 2016, 07:59:22 pm by Hapax »
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Csharpest

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Lines Primitive collision with Quads
« Reply #2 on: March 10, 2016, 08:52:24 pm »
Ah thank you, I was thinking of how I'd done collison in SFML before by using bounding boxes and such.

Didn't want to implement something like this if it was already in the SFML libraries.

Hopefully will get this to work, but if anyone has other ideas I'd love to hear them too

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Lines Primitive collision with Quads
« Reply #3 on: March 11, 2016, 05:18:35 pm »
You could also test all four points of the quad. If they are all on the same side of the line, the line does not pass through it. This would assume the line is infinite, though.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Lines Primitive collision with Quads
« Reply #4 on: March 11, 2016, 05:38:34 pm »
You could also test all four points of the quad. If they are all on the same side of the line, the line does not pass through it. This would assume the line is infinite, though.
If they are all on the same side of the line extrapolated to infinity and none of the endpoints of the actual (non infinite) line are within the polygon described by the quad, then the line does not intersect the quad.
Right?

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Lines Primitive collision with Quads
« Reply #5 on: March 11, 2016, 05:47:03 pm »
If the points of the quad are on the same side of the line, it doesn't intersect the quad.

However, the endpoints of the line could easily be outside of the quad if the line passes through it.

For a finite line, the points of the quad would also need to be tested against the end points. If all of the points of the quad are all outside of the range of the finite line, they doesn't intersect.
One way to do this is to test if the points of the quad are on the same side of the line's normal at each endpoint.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything