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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:50:39+00:00 2026-05-25T09:50:39+00:00

Given: point clickWheelCenter point startPoint (first touch) point point (actual touch) I want to

  • 0

Given:

  • point clickWheelCenter
  • point startPoint (first touch)
  • point point (actual touch)

I want to determine the angle between these three point, and I want to know, in which quadrant the last touch was found.
The calculation of the angle is working well, while the quadrant is always 1 or 2, never 3 or 4.

Where am I wrong?

CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2)
{
    CGFloat dx = point2.x - point1.x;
    CGFloat dy = point2.y - point1.y;
    return sqrt(dx*dx + dy*dy );
};

NSInteger GetQuadrant(double angle)
{
    double sinAngle = sin(angle);
    double cosAngle = cos(angle);
    double tanAngle = tan(angle);
    double cotAngle = 1.0/tanAngle;

    NSLog(@"%f %f %f %f", sinAngle, cosAngle, tanAngle, cosAngle);

    if(sinAngle > 0 && cosAngle > 0 && tanAngle > 0 && cotAngle > 0) return 1;
    if(sinAngle > 0 && cosAngle < 0 && tanAngle < 0 && cotAngle < 0) return 2;
    if(sinAngle < 0 && cosAngle < 0 && tanAngle > 0 && cotAngle > 0) return 3;
    if(sinAngle < 0 && cosAngle > 0 && tanAngle < 0 && cotAngle < 0) return 4;
    return 0;
}

double AngleBetweenThreePoints(CGPoint point1,CGPoint point2, CGPoint point3)
{
    CGPoint point_a = point1;
    CGPoint point_b = point2;
    CGPoint point_c = point3;
    CGFloat a, b, c;

    a = DistanceBetweenTwoPoints(point_b, point_c);
    b = DistanceBetweenTwoPoints(point_a, point_c);
    c = DistanceBetweenTwoPoints(point_a, point_b);
    double result = acos((b*b+c*c-a*a)/(2*b*c));

    NSLog(@"%d", GetQuadrant(result));

    return result/M_PI * 180.0;
}


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    startPoint = [[touches anyObject] locationInView:self];
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    CGPoint point = [[touches anyObject] locationInView:self];
    double angle = AngleBetweenThreePoints(self.clickWheelCenter, startPoint, point);
    NSLog(@"%f", angle);    
}
  • 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-25T09:50:40+00:00Added an answer on May 25, 2026 at 9:50 am

    This can all be done much easier.

    With {x1,y1} = first point – center point, and {x2,y2} = third point – center point, the signed angle (-pi,+pi) is given by:

    atan2(x2*y1 - x1*y2,x1*x2 + y1*y2)
    

    Depending on your definition of the sign of the angle you may or may not want to add a minus in front.

    You can easily derive the quadrant from sign and absolute size.

    1. size <= pi/2, sign +
    2. size > pi/2, sign +
    3. size > pi/2, sign –
    4. size <= pi/2, sign –
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need the ability to determine which Shape a given point falls within. There
I'm trying to find rows which are within ____meters from the given point. THis
Given a table where the first column is seconds past a certain reference point
Here is image , I want to know how to get nearest point to
I've got a right triangle and I want to check if a given point
Given a center point, width, height and angle forming an OBB, how can I
Given a point such as (0, 0, 0) and a vector like (x, y,
Given a point (pX, pY) and a circle with a known center (cX,cY) and
For given floating point numbers x and a , I would like to compute
I have a 2D image randomly and sparsely scattered with pixels. given a point

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.