Collision line with object?

I’m looking for a system to detect the intersection of a line with an object. 

The best idea I could come up with was to imagine the line as a series of points and checking each point to see if it was inside of the shape. I think this would work as long as the points were spaced close enough. I figure the points would need to be closer than the width and height of the objects. 

Hi @soggybag,

Have you considered raycasting? This would be the best approach, based on your description.

Best regards,

Brent

Also, from the comments of the non-physics collision tutorial:

http://www.coronalabs.com/blog/2013/07/23/tutorial-non-physics-collision-detection/#comment-34786

Thanks for the replies. I wasn’t thinking of physics so raycasting didn’t occur to me. 

I saw this line intersection code earlier. If I understand correctly it finds the point where two lines cross. First thoughts, were that this would not work as I want to know where a line intersects a shape. On second thoughts, I suppose if I had a line intersecting a rectangle I could check each side of the rectangle for an intersection… 

Hi @soggybag,

Have you considered raycasting? This would be the best approach, based on your description.

Best regards,

Brent

Also, from the comments of the non-physics collision tutorial:

http://www.coronalabs.com/blog/2013/07/23/tutorial-non-physics-collision-detection/#comment-34786

Thanks for the replies. I wasn’t thinking of physics so raycasting didn’t occur to me. 

I saw this line intersection code earlier. If I understand correctly it finds the point where two lines cross. First thoughts, were that this would not work as I want to know where a line intersects a shape. On second thoughts, I suppose if I had a line intersecting a rectangle I could check each side of the rectangle for an intersection…