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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:53:23+00:00 2026-05-26T03:53:23+00:00

I have a problem regarding positioning an image according to the touches location, however

  • 0

I have a problem regarding positioning an image according to the touches location, however limited to a circle.

It works for the most part, but if the angle (from the touches location to the desired location) is less than 0, it positions the image on the wrong side of the circle.

Perhaps it’s some maths that I’ve done wrong.

Anyway, here’s the code:

float newHeight, newWidth, centerPointX, centerPointY;
newHeight = -(invertedY.y - (view.frame.origin.y+view.frame.size.height/2));
newWidth = -(invertedY.x - (view.frame.origin.x+view.frame.size.width/2));

float tangent = newHeight/newWidth; 
float calculatedAngle = atanf(tangent);
float s, c, d, fX, fY;

d = view.frame.size.width/2+30;

    if (calculatedAngle < 0) {
        s = sinf(calculatedAngle) * d;
        c = cosf(calculatedAngle) * d;
    } else {
        s = -sinf(calculatedAngle) * d;
        c = -cosf(calculatedAngle) * d;
    }

    fX = view.center.x + c;
    fY = view.center.y + s;

    [delegate setPoint:CGPointMake(fX, fY)];

    NSLog(@"angle = %.2f", calculatedAngle);

Any help appreciated.

  • 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-26T03:53:24+00:00Added an answer on May 26, 2026 at 3:53 am

    I think the best way to limit location to a circle is calculate vector from center to touch location. Calculate vector length then divide it by that length so it would be normalized. Then multiply normalized vector by radius of circle and finally add this vector to the center to compute new location.

    CGPoint touch, center;
    CGPoint vector = CGPointMake(touch.x-center.x, touch.y-center.y);
    
    float length = sqrtf(vector.x*vector.x + vector.y*vector.y); 
    // Normalize and multiply by radius (r)
    vector.x = r * vector.x / length;
    vector.y = r * vector.y / length;
    
    [delegate setPoint:CGPointMake(center.x + vector.x, center.y + vector.y)];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I actually have two questions regarding the same problem but I think it is
I have just solved another problem regarding the same piece of code but I
I have a problem regarding getting the path of a user control. The scenario
I have a problem regarding StartUp Url in WPF. I have a LoginView.xaml and
I have a problem regarding the datediff MYSQL function, I can use it and
I have a question regarding a problem with L2S, Autogenerated DataContext and the use
I have a problem regarding this query. I want to get the applicant latest
I have a problem regarding flash, actionscript3 and movieclips. I have 2 videos(inserted as
I have a problem regarding to a JavaScript function. I used to have a
I have a problem regarding the memory management when adding objects to a NSMutableArray

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.