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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:43:31+00:00 2026-06-09T01:43:31+00:00

I have tried several different solutions but no luck so far. – (CGPoint)contractLineTemp:(CGPoint)point :(CGPoint)circle

  • 0

I have tried several different solutions but no luck so far.

- (CGPoint)contractLineTemp:(CGPoint)point :(CGPoint)circle :(float)circleRadius { 
CGFloat x,y;
x = point.x - circle.x;
y = point.y - circle.y;

CGFloat theta = atan2(x, y);

CGPoint newPoint;

newPoint.x = circle.x + circleRadius * sin(theta);
newPoint.y = circle.y + circleRadius * cos(theta);

return newPoint;
}


- (CGPoint)contractLineTemp:(CGPoint)startPoint :(CGPoint)endPoint :(float)scaleBy {

float dx = endPoint.x - startPoint.x;
float dy = endPoint.y - startPoint.y;

float scale = scaleBy * Q_rsqrt(dx * dx + dy * dy);
return CGPointMake (endPoint.x - dx * scale, endPoint.y - dy * scale);
}

Both of these solutions kind of work. If I draw the line to the center of the circle you can see that it intersects the circle exactly where it should.

http://www.freeimagehosting.net/le5pi

If I use either of the solutions above and draw to the circumference of the circle depending on the angle it is no longer going towards the center of the circle. In the second image the line should be in the middle of the right edge of the circle and going straight right.

http://www.freeimagehosting.net/53ovs

http://www.freeimagehosting.net/sb3b2

Sorry for the links. I am to new to currently post images.

Thanks for you help.

  • 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-06-09T01:43:33+00:00Added an answer on June 9, 2026 at 1:43 am

    It’s easier to treat this as a vector problem. Your second approach is close, but you don’t correctly scale the vector between the two points. It’s easier to work with a normalized vector in this case, although you have to assume that the distance between the two points on the line is non-zero.

    Given:

    double x0 = CIRC_X0; /* x-coord of center of circle */
    double y0 = CIRC_Y0; /* y-coord of center of circle */
    
    double x1 = LINE_X1; /* x-coord of other point on the line */
    double y1 = LINE_Y1; /* y-coord of other point on the line */
    

    Then the vector between the two points is (vx,vy):

    double vx = x1 - x0;
    double vy = y1 - y0;
    

    It’s easier to work with a unit vector, which we can get by normalizing (vx,vy):

    double vmag = sqrt(vx*vx + vy*vy);
    vx /= vmag;  /* Assumption is vmag > 0 */
    vy /= vmag;
    

    Now, any point along the line can be described as:

    x0 + dist * vx
    y0 + dist * vy
    

    where dist is the distance from the center. The intersection of the circle and the line must be a distance of CIRC_RADIUS from the center, so:

    double x_intersect = x0 + CIRC_RADIUS * vx;
    double y_intersect = y0 + CIRC_RADIUS * vy;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried several things so far, but I haven't had much luck yet.
For the last hour I've tried several different solutions but none have solved my
I have tried several of the solutions I have seen out here, but am
I have tried this several different ways but can't seem to figure out how
Here is what I have. I have tried several things but I can't figure
I have tried several mySQL queries to compare a column of dates stored as
I have tried several ways to login to a website through java. I have
I am stumped by this one. I have tried several angles and some come
I really need advice on how to do the following. I have tried several
I am trying to load a URLRequest in UIWebview. I have tried with several

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.