• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0

Sweep test for circle vs line segment

2 posts in this topic

Hello! I recently have read through Swept Ellipsoids article and findout there the both (math and code) for swept sphere and static plane tests. But the problem is that this is infinite plane or something, and when I implement in in 2d with tries to make in work with segmented line, it works just awful. So I'm up here to ask you about the math and code for perform Swept circle vs Static segment and Swept circle vs Swept segment tests... The second one just have translation vector... like if describe it as segment with two point in space as A,B and normal and then translate it through some displacement like nA = A+D nB = B+D... no any angular rotations and so on... The example why I need that : Fast growable surface which goes up, and fast flying player who trying to hit this surface by fastly falling, and going from the top... So the point is to find out boolean results and also calculate (exactly contact point with normal and separation). How calculate this stuff using parameter t -&rt [0,1] I know only for Static Segment vs Swept Circle, because has write Sweep Circle vs Sweep Circle test, but what suppose to be in Swept Segment vs Swept Circle, well I can't figure it out, my math level doesn't let me imagine exactly cases for that. So I beg you guys to help me somehow to dealing with sjb.

Share this post

Link to post
Share on other sites
Just a few comments to get you started...

First of all, intersection tests involving two moving objects can generally be expressed such that one of them is stationary (by subtracting the velocity of one object from the velocity of the other). As such, all you really need is a swept circle vs. static line segment test.

In turn, this problem can be expressed as a capsule raytracing test. The ray originates at the circle center, and its direction vector is equal to the circle's velocity vector. The capsule's medial segment is equal to the line segment, and has a radius equal to the circle's.

The ray vs. capsule test can be implemented in various different ways, but a relatively straightforward (if not maximally efficient) approach would be to intersect the ray with the oriented box and pair of circles that make up the capsule, and then take the least of the parametric values returned (if any) as the parametric hit point.

Once you have the hit point in parametric form (i.e. the time of collision), you can move the circle and the segment to the point where they are just touching. At this point you can compute both the contact point and normal (if needed) by computing the point on the line segment closest to the circle center.

I wasn't clear from your post whether you already have the swept circle vs. static line segment test written or not; if you do, you're almost done, but if not, you may need to implement the ray vs. capsule test described above.

(Note that most of these tests can be expressed in more than one way; for example, the swept circle vs. segment test can be approached in terms of a circle vs. hyperplane test and two circle vs. point tests. However you express it though, the computations you end up performing will be more or less equivalent.)

Share this post

Link to post
Share on other sites
I think youre talking about not so efficiant way.
So what we got here is Plane vs Circle vs Circler's Line equation test.
So there we go, I read this article and even try to implement something,

take a look, here is the article and theory:

I'm not too smart in mathematics, and don't understand what exactly plane constant suppose to be, I mean if we talking about finite plane.

And here what I try:

inline static float PointDistToLineSeg( Vector P, Vector vSrc, Vector vEnd )
Vector v = vEnd - vSrc;
Vector w = P - vSrc;

float c1 = w.Dot(v);
if ( c1 <= 0 )
return w.Length();

float c2 = v.Dot(v);
if ( c2 <= c1 )
return (P - vEnd).Length();

float frac = 0.0f;
if ( fabsf( c2 ) < 1.0e-6f ){ frac = 0.0f; }
else { frac = c1 / c2; }
return (P - (vSrc + v * frac)).Length();

// swept circle vs swept line
bool SegmentCircleIntersect( const circle_t &circ, const lineseg_t &line, circ_int_t &int_info )
// substitute for moving line
Vector transition = circ.transition - line.transition; // souldn't use that!!!! not works!

// If the center of the sphere moves like: center = position + t * translation for t -> [0, 1]
// then the sphere intersects the plane if: -R <= distance plane to center <= R

float dist_norm = Dot(line.normal, transition); // something from plane equation
float dist_to_c = PointDistToLineSeg(circ.position, line.src, line.end); // NOTE: !SIGNED! distance to line seg? how?

if ( fabsf(dist_norm) < 1.0e-6f )
// The sphere is moving nearly parallel to the plane, check if the distance
// is smaller than the radius
if ( fabsf(dist_to_c) > circ.radius )
return false;
// Intersection on the entire range
int_info.entire_range = true;
int_info.fraction1 = 0.0f;
int_info.fraction2 = 1.0f;
// Determine interval of intersection
int_info.fraction1 = ( circ.radius - dist_to_c) / dist_norm;
int_info.fraction2 = (-circ.radius - dist_to_c) / dist_norm;
// Order the results
if (int_info.fraction1 > int_info.fraction2)
swap(int_info.fraction1, int_info.fraction2);
// Early out if no hit possible
if (int_info.fraction1 > 1.0f || int_info.fraction2 < 0.0f)
return false;
// Clamp it to the range [0, 1], the range of the swept circle
if (int_info.fraction1 < 0.0f) int_info.fraction1 = 0.0f;
if (int_info.fraction2 > 1.0f) int_info.fraction2 = 1.0f;
// contact points
Vector point1 = circ.position + transition * int_info.fraction1; // determine where exactly circle should stop
Vector point2 = circ.position + transition * int_info.fraction2; // determine where exactly circle should exit

int_info.numpts = 1; // determine whether or not second point should be used
int_info.points[0].position = point1;
// int_info.points[1] = point2;
int_info.points[0].separation = dist_to_c - circ.radius;
int_info.points[0].normal = line.normal;

return true;

So I don't take good results with this why, maybe you see some errors in implementation?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0