Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6322439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:19:56+00:00 2026-05-24T16:19:56+00:00

In the context of a game program, I have a moving circle and a

  • 0

In the context of a game program, I have a moving circle and a fixed line segment. The segment can have an arbitrary size and orientation.

  • I know the radius of the circle: r
  • I know the coordinates of the circle before the move: (xC1, yC1)
  • I know the coordinates of the circle after the move: (xC2, yC2)
  • I know the coordinates of the extremities of the line segment: (xL1, yL1) – (xL2, yL2)

moving circle

I am having difficulties trying to compute:

  • A boolean: If any part of the circle hits the line segment while moving from (xC1, yC1) to (xC2, yC2)
  • If the boolean is true, the coordinates (x, y) of the center of the circle when it hits the line segment (I mean when circle is tangent to segment for the first time)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:19:56+00:00Added an answer on May 24, 2026 at 4:19 pm

    Look here:

    Line segment / Circle intersection

    If the value you get under the square root of either the computation of x or y is negative, then the segment does not intersect. Aside from that, you can stop your computation after you have x and y (note: you may get two answers)

    Update I’ve revised my answer to very specifically address your problem. I give credit to Doswa for this solution, as I pretty much followed along and wrote it for C#. The basic strategy is that we are going to locate the closest point of your line segment to the center of the circle. Based on that, we’ll look at the distance of that closest point, and if it is within the radius, locate the point along the direction to the closest point that lies right at the radius of the circle.

    // I'll bet you already have one of these.
    public class Vec : Tuple<double, double>
    {
      public Vec(double item1, double item2) : base(item1, item2) { }
      public double Dot(Vec other) 
        { return Item1*other.Item1 + Item2*other.Item2; }
      public static Vec operator-(Vec first, Vec second) 
        { return new Vec(first.Item1 - second.Item1, first.Item2 - second.Item2);}
      public static Vec operator+(Vec first, Vec second) 
        { return new Vec(first.Item1 + second.Item1, first.Item2 + second.Item2);}
      public static Vec operator*(double first, Vec second) 
        { return new Vec(first * second.Item1, first * second.Item2);}
      public double Length() { return Math.Sqrt(Dot(this)); }
      public Vec Normalize() { return (1 / Length()) * this; }
    }
    
    public bool IntersectCircle(Vec origin, Vec lineStart, 
          Vec lineEnd, Vec circle, double radius, out Vec circleWhenHit)
    {
        circleWhenHit = null;
    
        // find the closest point on the line segment to the center of the circle
        var line = lineEnd - lineStart;
        var lineLength = line.Length();
        var lineNorm = (1/lineLength)*line;
        var segmentToCircle = circle - lineStart;
        var closestPointOnSegment = segmentToCircle.Dot(line) / lineLength;
    
        // Special cases where the closest point happens to be the end points
        Vec closest;
        if (closestPointOnSegment < 0) closest = lineStart;
        else if (closestPointOnSegment > lineLength) closest = lineEnd;
        else closest = lineStart + closestPointOnSegment*lineNorm;
    
        // Find that distance.  If it is less than the radius, then we 
        // are within the circle
        var distanceFromClosest = circle - closest;
        var distanceFromClosestLength = distanceFromClosest.Length();
        if (distanceFromClosestLength > radius) return false;
    
        // So find the distance that places the intersection point right at 
        // the radius.  This is the center of the circle at the time of collision
        // and is different than the result from Doswa
        var offset = (radius - distanceFromClosestLength) *
                     ((1/distanceFromClosestLength)*distanceFromClosest);
        circleWhenHit = circle - offset;
    
        return true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing an OpenGL-ES game of life program for the iPhone and I have
Context I have a web game in JavaScript. I send scores and achievements with
I have written a game playing program for a competition, which relies on some
I have a Quartz 2D game which draws directly onto a context. For this
I don't want to transform the ENTIRE context. I'm making a game with Quartz,
Context: I have a WPF App that uses certain unmanaged DLLs in the D:\WordAutomation\MyApp_Source\Executables\MyApp
Context : programming a c/c++ win32-mfc library How to know whether we are in
I want my program to be able to launch any Windows game, and while
I have written a mail-processing program, which basically slaps a template on incoming mail
Firstly - Z is Up in this problem. Context: Top down 2D Game using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.