Re: Angle of touch point from center of view?
Re: Angle of touch point from center of view?
- Subject: Re: Angle of touch point from center of view?
- From: "Eric E. Dolecki" <email@hidden>
- Date: Thu, 05 Jan 2012 14:23:20 -0500
Hmmm...
I have a UITextView in the center of my app. I want to base the origin on
that object.
#define RADIANS_TO_DEGREES(radians) ((radians) * (180.0 / M_PI))
- (CGFloat)angleFromPoints:(CGPoint)first second:(CGPoint)second {
CGFloat height = second.y - first.y;
CGFloat width = first.x - second.x;
CGFloat rads = atan(height/width);
return RADIANS_TO_DEGREES(rads);
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint origin = fullLabel.center;
UITouch *touch = [touches anyObject];
CGPoint pt = [touch locationInView:self.view];
CGFloat angle = [self angleFromPoints:origin second:pt];
NSLog(@"%f", angle);
}
>From the top I get 90... around to the right side I get down to 0... then
around from right to bottom -0 to -90 then around to left side 90 to 0 and
then back to top from left side -0 to -90.
??
On Thu, Jan 5, 2012 at 2:02 PM, David Duncan <email@hidden> wrote:
> On Jan 5, 2012, at 10:49 AM, Eric E. Dolecki wrote:
>
> > I'd like to calculate the angle from a center point of a view to a touch
> > point.
> >
> > 0º behind top of screen, 180º being bottom of screen.
> >
> > Calculating from touchesMoved.
> >
> > Any pointers? Checking Google again.
>
> This is basically just the theta calculation of a convert to polar
> coordinates. man atan2 should give you what you need to know.
> --
> David Duncan
>
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden