CodePaste Logo
New Snippet New Recent Snippets Recent Snippets My Snippets My Snippets My Favorites Favorites Web Code Search Snippets Search
Sign inor Register
Language: csharp

Calculate Dial Rotation

940 Views   
public enum Quadrants : int { nw = 2, ne = 1, sw = 4, se = 3 } private double GetAngle(Point touchPoint, Size circleSize) { var _X = touchPoint.X - (circleSize.Width / 2d); var _Y = circleSize.Height - touchPoint.Y - (circleSize.Height / 2d); var _Hypot = Math.Sqrt(_X * _X + _Y * _Y); var _Value = Math.Asin(_Y / _Hypot) * 180 / Math.PI; var _Quadrant = (_X >= 0) ? (_Y >= 0) ? Quadrants.ne : Quadrants.se : (_Y >= 0) ? Quadrants.nw : Quadrants.sw; switch (_Quadrant) { case Quadrants.ne: _Value = 090 - _Value; break; case Quadrants.nw: _Value = 270 + _Value; break; case Quadrants.se: _Value = 090 - _Value; break; case Quadrants.sw: _Value = 270 + _Value; break; } return _Value; }
by Jerry Nixon
  November 14, 2012 @ 12:05pm
Tags:
Description:
http://en.wikipedia.org/wiki/Cartesian_coordinate_system
Add a comment


Report Abuse
brought to you by:
West Wind Techologies