On Oct 24, 2007, at 8:02 PM, Sophia Poirier wrote:
PtToAngle() is deprecated in Mac OS X 10.4. What should we use as a
replacement? None of the documentations or headers I've found have
pointed towards a replacement.
What an odd function...I had never had occasion to use PtToAngle. At
its core, the equivalent is an "inverse tangent of (y / x)"
computation, but there are a few interesting details to consider.
PtToAngle adjusts for the aspect ratio of the rectangle you pass. If
you were using an empty rectangle (or any rectangle that is square and
is centered at (0,0)) then you can skip this part. Otherwise, compute
dy = point.y - rectCenterY and dx = point.x - rectCenterX. Compute
dy / dx and then multiply by rectWidth / rectHeight to normalize the
slope.
The arc-tangent (atan) of that value is your answer...but in radians
(counter-clockwise from right-equals-zero), and in the range -pi/2 to
pi/2. If dx was negative, add or subtract pi to point the angle in
the opposite direction.
If you need a result compatible with PtToAngle, convert to degrees,
and subtract from 90, and round off to an integer. At some point,
normalize the value into your preferred range by adding or subtracting
360 degrees or 2pi radians.
I've glossed over some details, such as being careful about the dx = 0
case. You may wish to check for that, or it may be sufficient to let
the floating-point result be Inf or -Inf, which atan can handle
properly.
Note that I haven't tested the above, only composed it here in email
(but with reference to the PtToAngle implementation in the QuickDraw
source).
Cheers,
--Dave (a.k.a. email@hidden)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden