On 30 Sep 2008, at 9:29 pm, Michael Robinson wrote:

Variables i, cornerSize are passed to the function from a for loop. i being the counter for the loop, cornerSize being the size of corner desired by the user.

        float retVal;

        retVal = cornerSize*(1-cos(asin(i/cornerSize)));

        return (int)retVal;

Obviously, I'm no whiz at ObjC, and the fact that this keeps return '0' has got me stumped.

At first I thought it was some stupid mistake I made translating the formula, but I tested a few things and now I'm not so sure.

sin(90); returns 0 as well. When I use Apple's Calculator and ask it to tell me the result of sin(90), it gives me 1.

What what whaaaaat?


I can't comment on the correctness of the formulas, and I'm not very familiar with Javascript.

But I suspect your problem is that in C and Obj-C (and pretty much every language AFAIK), the argument you pass to cos, sin, etc. is in radians, not degrees.

So you can't pass sin(90) and get 1, because 90 radians is ~0.89, truncate that to an int and you have 0.

You need to convert everything to radians before using these functions. These macros may be handy:

#define DEGREES_TO_RADIANS( d )                 ((d) * 0.0174532925199432958)
#define RADIANS_TO_DEGREES( r )                 ((r) * 57.29577951308232)

hth,

Graham


(FWIW, radians are nice, lovely, easy to use units based on some solid maths. Degrees on the other hand are a legacy of the ancient Egyptians believing that a year was 360 days and inventing an arbitrary system around it. You only think you're comfortable in degrees because schools drum it into you from an early age. But radians are much, much nicer when you come to compute physics and geometry problems. Just my 2ยข worth!).

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to