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 6075899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:32:45+00:00 2026-05-23T10:32:45+00:00

…well, to an incomplete circle. I have a draggable slider that looks like this:

  • 0

…well, to an incomplete circle.

I have a draggable slider that looks like this: Arc Slider

The blue bar has the instance name track and the pink dot has the instance name puck.

I need the puck to be constrained within the blue area at all times, and this is where my maths failings work against me! So far I have the puck moving along the x axis only like this:

private function init():void
{
    zeroPoint = track.x + (track.width/2);
    puck.x = zeroPoint-(puck.width/2);
    puck.buttonMode = true;
    puck.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDown);
}

private function onMouseDown(evt:MouseEvent):void
{
    this.stage.addEventListener(MouseEvent.MOUSE_MOVE,onMouseMove);
    this.stage.addEventListener(MouseEvent.MOUSE_UP,onMouseUp);
}

private function onMouseUp(evt:MouseEvent):void
{
    this.stage.removeEventListener(MouseEvent.MOUSE_MOVE,onMouseMove);
}

private function onMouseMove(evt:MouseEvent):void
{
    puck.x = mouseX-(puck.width/2);
    //need to plot puck.y using trig magic...
}

My thinking is currently that I can use the radius of the incomplete circle (50) and the mouseX relative to the top of the arc to calculate a triangle, and from there I can calculate the required y position. Problem is, I’m reading various trigonometry sites and still have no idea where to begin. Could someone explain what I need to do as if speaking to a child please?

Edit: The fact that the circle is broken shouldn’t be an issue, I can cap the movement to a certain number of degrees in each direction easily, it’s getting the degrees in the first place that I can’t get my head around!

Edit2: I’m trying to follow Bosworth99’s answer, and this is the function I’ve come up with for calculating a radian to put into his function:

private function getRadian():Number
{
    var a:Number = mouseX - zeroPoint;
    var b:Number = 50;
    var c:Number = Math.sqrt((a^2)+(b^2));
    return c;
}
  • 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-23T10:32:46+00:00Added an answer on May 23, 2026 at 10:32 am

    As I see it, the problem you solve is finding the closest point on a circle. Google have a lot of suggestions on this subject.

    You can optimise it by first detecting an angle between mouse position and circle center. Use Math.atan2() for that. If the angle is in a gap range, just choose the closest endpoint: left or right.

    EDIT1 Here is a complete example of this strategy.

    Hope that helps.

    import flash.geom.Point;
    import flash.events.Event;
    import flash.display.Sprite;
    
    var center:Point = new Point(200, 200);
    var radius:uint = 100;
    
    var degreesToRad:Number = Math.PI/180;
    
    // gap angles. degrees are used here just for the sake of simplicity.
    // what we use here are stage angles, not the trigonometric ones.
    var gapFrom:Number = 45; // degrees
    var gapTo:Number = 135; // degrees
    
    // calculate endpoints only once
    
    var endPointFrom:Point = new Point();
    endPointFrom.x = center.x+Math.cos(gapFrom*degreesToRad)*radius;
    endPointFrom.y = center.y+Math.sin(gapFrom*degreesToRad)*radius;
    
    var endPointTo:Point = new Point();
    endPointTo.x = center.x+Math.cos(gapTo*degreesToRad)*radius;
    endPointTo.y = center.y+Math.sin(gapTo*degreesToRad)*radius;
    
    // just some drawing
    graphics.beginFill(0);
    graphics.drawCircle(center.x, center.y, radius);
    graphics.moveTo(center.x, center.y);
    graphics.lineTo(endPointFrom.x, endPointFrom.y);
    graphics.lineTo(endPointTo.x, endPointTo.y);
    graphics.lineTo(center.x, center.y);
    graphics.endFill();
    
    // something to mark the closest point
    var marker:Sprite = new Sprite();
    marker.graphics.lineStyle(20, 0xFF0000);
    marker.graphics.lineTo(0, 1);
    addChild(marker);
    
    var onEnterFrame:Function = function (event:Event) : void
    {
        // circle intersection goes here
        var mx:int = stage.mouseX;
        var my:int = stage.mouseY;
    
        var angle:Number = Math.atan2(center.y-my, center.x-mx);
        // NOTE: in flash rotation is increasing clockwise, 
        // while in trigonometry angles increase counter clockwise
        // so we handle this difference
        angle += Math.PI;
    
        // calculate the stage angle in degrees
        var clientAngle:Number = angle/Math.PI*180
    
        // check if we are in a gap
        if (clientAngle >= gapFrom && clientAngle <= gapTo) {
            // we are in a gap, no sines or cosines needed
            if (clientAngle-gapFrom < (gapTo-gapFrom)/2) {        
                marker.x = endPointFrom.x;
                marker.y = endPointFrom.y;
            } else {
                marker.x = endPointTo.x;
                marker.y = endPointTo.y;
            }
            // we are done here
            return;
        }
    
        // we are not in a gp, calculate closest position on a circle
        marker.x = center.x + Math.cos(angle)*radius;
        marker.y = center.y + Math.sin(angle)*radius;
    }
    addEventListener(Event.ENTER_FRAME, onEnterFrame);
    

    EDIT2 Some links

    Here are some common problems explained and solved in a brilliantly clear and concise manner: http://paulbourke.net/geometry/ This resource helped me a lot days ago.

    Intersection of a line and a circle is a bit of an overkill here, but here it is: http://paulbourke.net/geometry/sphereline/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an element like this: <span class=tool_tip title=The full title>The ful&#8230;</span> This seems
I have this xml <entry id=1008 section=articles> <excerpt><p>&#8230; in Richtung „Aus für Tierversuche. Kosmetik-Fertigprodukte
I have my code like this: for (i in 1:b) { carteraR[[i]]=subset(carteraR[[i]],RUN.FONDO==8026 | RUN.FONDO==8036
so I did $subject = 'sakdlfjsalfdjslfad <a href=something/8230>lol is that true?</a> lalalala'; $subject =
I see that some rss on xml have strange strings. For example, ... is
An Arabic name shall be sent via SOAP. The name is encoded like this:
I would like to run a str_replace or preg_replace which looks for certain words
I have a PDB file. Now it has two parts separated by TER. Before
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a table of data (in this case property rents) and want to

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.