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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:55:01+00:00 2026-05-28T07:55:01+00:00

I have a rectangle. Its height (RH) is 400. Its width (RW) is 500.

  • 0

I have a rectangle.
Its height (RH) is 400.
Its width (RW) is 500.

I have circle.
Its height (CH) is 10.
Its width (CW) is 10.
Its starting location (CX1, CY1) is 20, 20.

The circle has moved.
Its new location (CX2, CY2) is 30, 35.

Assuming my circle continues to move in a straight line.
What is the circle’s location when its edge reaches the boundary?

enter image description here

Hopefully you can provide a reusable formula.

Perhaps some C# method with a signature like this?

point GetDest(size itemSize, point itemPos1, point itemPos2, size boundarySize)

I need to calculate what that location WILL be once it arrives – knowing that it is not there yet.

Thank you.

PS: I need this because my application is watching the accelerometer on my Windows Phone. I am calculating the target necessary to animate the motion of the circle inside the rectangle as the user is tilting their device.

  • 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-28T07:55:02+00:00Added an answer on May 28, 2026 at 7:55 am

    The answer is X=270 Y=395

    first define the slope V as dy/dx =(y2-y1)/(x2-x1). In your example: (35-20)/(30-20)=1.5

    the line equation is
    y = V * (x-x1) + y1. You are interested in the horizontal locations x at:
    y= CH/2 OR y= H-CH/2
    so (not code, just math)

    if (y2-y1)<0:
     x=(CH/2 -y1)/V +x1     10 for your example. OR
    if (y2-y1)>0:
     x=(H-CH/2 -y1)/V +x1   270 for your example
    else (that is: y2==y1)
     the upper or lower lines were not hit.
    
    if CH/2 <= x <= W-CH/2 the circle did hit the that upper or lower side: since V>0, we use x=270 and that is within CH/2 and W-CH/2. 
    

    So the answer to your question is y=H-CH/2 = 395 , X=270

    For the side lines it’s similar:

    (if (x2-x1)<0)
     y=(CH/2 -x1)*V +y1   
    (if (x2-x1)>0)
     y=(W-CH/2 -x1)*V +y1 
    else (that is: x2==x1)
     the side lines were not hit.
    
    if CH/2 <= y <= H-CH/2 the circle did hit that side at that y.
    

    be careful with the trivial cases of completely horizontal or vertical movement so that you don’t divide by zero. when calculating V or 1/V. Also deal with the case where the circle did not move at all.

    Since you now asked, here’s metacode which you should easily be able to convert to a real method. It deals with the special cases too. The input is all the variables you listed in your example. I here use just one symbol for the circle size, since it’s a circle not an ellipse.

    method returning a pair of doubles    getzy(x1,y1,W,H,CH){
    
      if (y2!=y1){ // test for hitting upper or lower edges
        Vinverse=(x2-x1)/(y2-y1)
        if ((y2-y1)<0){
           xout=(CH/2 -y1)*Vinverse +x1 
           if (CH/2 <= y <= H-CH/2) {
               yout=CH/2
               return xout,yout
           }
         }
        if ((y2-y1)>0){
           xout=(H-CH/2 -y1)*Vinverse +x1 
           if (CH/2 <= y <= H-CH/2) {
               yout=H-CH/2
               return xout,yout
           }
        }
      }     
      // reaching here means upper or lower lines were not hit.
      if (x2!=x1){ // test for hitting upper or lower edges
        V=(y2-y1)/(x2-x1)
        if ((x2-x1)<0){
           yout=(CH/2 -x1)*V +y1 
           if (CH/2 <= x <= W-CH/2) {
               xout=CH/2
               return xout,yout
           }
         }
        if ((x2-x1)>0){
           yout=(H-CH/2 -x1)*V +y1 
           if (CH/2 <= x <= W-CH/2) {
               xout=H-CH/2
               return xout,yout
           }
        }
      }     
      // if you reach here that means the circle does not move...
       deal with using exceptions or some other way.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a class Rectangle class Rectangle{ private: double width; double height; public:
For example, in a WPF or Silverlight app I have: <Rectangle Height=100 Width=200 Name=rectangle1
I have a rectangle that I've created and set its individual properties like so
I have an abstract base class called Shape from which both Circle and Rectangle
I have a rectangle in my XAML and want to change its Canvas.Left property
I have a transparent rectangle on a picture box,if i click next,the next image
I have the need to determine the bounding rectangle for a polygon at an
I have a point in a rectangle that I need to rotate an arbitrary
I have a collection of non-overlapping rectangles that cover an enclosing rectangle. What is
I have two points (a line segment) and a rectangle. I would like 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.