• 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
LevyDee

Solve path around a given point and radius

6 posts in this topic

The attached image helps to describe my problem.

 

Given a direction vector(V1), location to avoid along with the radius, and a destination point, how could I calculate the blue travel path?

 

I know that given the angle in radians of a circle you can find the vector location at that angle on the circle, but I am not sure how I would implement this equation to solve this.

 

Thank you

0

Share this post


Link to post
Share on other sites

If you are having a point particle:

vector velocity = normalize(destination - start) * speed;

vector t = p - c; //vector from point to circle center
float d = dot(t, t); // squared length of t
if( d < r*r)  // check if circle radius^2 > d
{
  float root = sqrt(d);
  vector overlap = (t / root) * (r - root);
  velocity -= overlap; // offset the point
}

edit:small correction 

Edited by Doublefris
0

Share this post


Link to post
Share on other sites

So, it looks like you'll end up with sort of an inverse dubins car, where instead of an arc, line, arc, you end up with a line, arc, line.

 

 

So, first thing I'd do is a Line vs Circle intersection test, and get the two points of intersection with the circle.  (if you only have 1, then you are in the circle, and no points, you just head down the line.)

 

From there, you just need the start angle (atan2 is your friend) and the angle between that and the end point.  I can dig up the exact code later if you need it.

 

EDIT:  Follow up

angleStart = atan2(ptStart.y - center.y, ptStart.x - center.x); 
deltaAngle = atan2(ptEnd.y - center.y, ptEnd.x - center.x);
if (deltaAngle < 0.0f && (!clockwise))
{
  deltaAngle += 2.0f * PI;
}
else if (deltaAngle > 0.0f && (clockwise))
{
  deltaAngle -= 2.0f * PI;	        
}

endTheta = startTheta + deltaAngle

You might be able to figure out ahead of time whether you'd be going clockwise or not, worse comes to worse, check both angles, take the smaller arc length 

Edited by ferrous
1

Share this post


Link to post
Share on other sites

Here's a fairly decent way to solve this problem. I'm assuming this will be a "line,circle,line" problem, but you can alter this for different cases. I would put the line into parametric form and the circle into implicit form:

\[ C(t) = (x-a)^2 + (y-b)^2 - r^2 = 0; L(x(t),y(t)) = [x_0 + ct, y_0+dt] \]

Here, \( (a,b) \) is the center of the circle, \( r \) is the radius, and \( (x_0,y_0) \) is the start point of the path and your direction vector \( V_1 = (c,d) \). By substituting the parametric line formulas into the implicit circle formula, we can get a polynomial whose roots are the intersection points in the line parameter space:

\[ \begin{aligned} (x_0+ct-a)^2 + (y_0+dt-b)^2 -r^2 &= 0 \\ (c^2+d^2)t^2+2[c(x_0-a)+(y_0-b)]t+[(x_0-a)^2+(y_0-b)^2-r^2] &= 0 \\ At^2+Bt+c &= 0 \\ \end{aligned} \]

The roots can be solved for quickly using the quadratic equation:

\[ t = \frac{-B\pm \sqrt{B^2-4AC}}{2A} \]

If the discriminant \( B^2 - 4AC < 0 \), then you have no intersections. If  \( B^2 - 4AC = 0 \), you've got 1 intersection. If  \( B^2 - 4AC > 0 \), you've got 2 intersections, which is really the only case you have to worry about to avoid the object since the path can stay linear for any other cases. You can then evaluate the parametric line at the roots of the polynomial to get the intersection points in (x,y) form. You can get the angles of the points on the circle using \( \theta = \text{atan2}(y-b, x-a) \). If the problem is as shown in the OP's picture (where the starting path point isn't inside the circle), you also know which point to start from and which point to end with because the point with the lesser parameter value t is the point closest to \( (x_0,y_0) \).

 

Deciding which path around the circle is shorter is the last issue to resolve. We could calculate arc length, but we can figure out which way to go by using the implicit form of the line and figuring out which side of the line the circle's center is. The implicit line formula is given by \( \mathcal{A}x+\mathcal{B}y+\mathcal{C}=0 \). The coefficients for the implicit line are simple to calculate from the parametric form: \( \mathcal{A} = -d, \,\mathcal{B} = c, \,\mathcal{C} = dx_0-cy_0 \). The equation then becomes \( D = d(x_0-a)+c(b-y_0) \). If D < 0, then the circle center is on the right side of the line (looking in the direction of the line). That means the clockwise path around the circle is the shortest path. If D > 0, then the circle center is on the left side of the line, which means the counterclockwise path is the shortest. If D = 0, then the circle center lies on the line and each path is the same length.

 

You can step with constant velocity along the path by using the parametric form of the line and along the circle by figuring out your angle step via \( ds = r d\theta \). As I see it, this is fairly elegant because there's nothing more than additions, multiplications, atan2, and a square root function, making it a fairly fast method.

 

Hope that helps!

Edited by cadjunkie
2

Share this post


Link to post
Share on other sites

The shortest path would have the two straight line portions tangent to the circumference rather than aligned with each other. As a bonus, continuity would be G1 rather than G0.

2

Share this post


Link to post
Share on other sites

The shortest path would have the two straight line portions tangent to the circumference rather than aligned with each other. As a bonus, continuity would be G1 rather than G0.

 

How would one go about calculating that?  Find the two tangent lines to the circle for each endpoint, turn them into rays and intersect them with each other?

Edited by ferrous
0

Share this post


Link to post
Share on other sites

 

The shortest path would have the two straight line portions tangent to the circumference rather than aligned with each other. As a bonus, continuity would be G1 rather than G0.

 

How would one go about calculating that?  Find the two tangent lines to the circle for each endpoint, turn them into rays and intersect them with each other?

 

Almost. You would intersect the two tangents with the circle, to find the tangency points where the arc portion of the path begins and ends.

A concise explanation with formulas: http://mathworld.wolfram.com/CircleTangentLine.html

0

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