Intersection Between Line and Circle | 2D Segment Collision Algorithm | Java, JavaScript, C#, C++





The interactive transcript could not be loaded.


Rating is available when the video has been rented.
This feature is not available right now. Please try again later.
Published on Jun 14, 2016

It's the same line sphere intersection algorithm for, Java, JavaScript, C#, C++ and other programming languages. The implementation for this circle and line intersection is the same. Just follow this tutorial to find out how to actually do it. In this example JavaScript and HTML Canvas are used. This test is also known as sphere line intersection, if you add an extra 3D axis, let's say Z, for example.

This collision detection test is one of the most complex ones (aside from ray vs. triangle test) and will use an extra function for "projecting" a vector (vector projection formula) onto another vector. This function will be added to our game dev library, we have developed so far. This tutorial explains how to do that!

Because collision test of a sphere/circle with a segment line requires basic knowledge of 90 degree trigonometry operations, dot product function will be used. This is good, because it's already part of our segment library. Projecting a perpendicular vector onto another is a very useful algorithm to have in our game development library arsenal.

And finally, toward the end of this tutorial, there is a special case. We need to make sure that the edges of the lines fall within our circle. It's a secondary part of this algorithm, that needs to be solved separately.


When autoplay is enabled, a suggested video will automatically play next.

Up next

to add this to Watch Later

Add to

Loading playlists...