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:39:48 -0500
Wicked. That's working very well. Thank you.
On Thu, Jan 5, 2012 at 2:24 PM, Marco Tabini <email@hidden> wrote:
> On 2012-01-05, at 1:49 PM, 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.
>
>
> I think you can just retrieve the arctangent between the x axis and the
> vector formed by the origin and location of the touch (reversing the y
> coordinate). For example:
>
> - (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
> CGPoint center = self.center;
> CGPoint location = [[touches anyObject] locationInView:self];
>
>
> CGPoint vectorOfInterest = CGPointMake(location.x - center.x, center.y- location.
> y);
>
>
> NSLog(@"Vector: %@, Angle: %.2fº",
> NSStringFromCGPoint(vectorOfInterest),
> atan2(vectorOfInterest.x, vectorOfInterest.y) * 57.29);
> }
>
> The resulting angle will be [0, π) clockwise starting from the top, and
> [-π, 0) from the bottom (or something like that—my trig is horribly rusty).
>
> HTH,
>
>
> —Mt.
>
_______________________________________________
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