Re: [Math] sin(), cos() not working? What special magic must I use to summon their powers?
site_archiver@lists.apple.com Delivered-To: cocoa-dev@lists.apple.com Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:cc:message-id:from:to :in-reply-to:content-type:content-transfer-encoding:mime-version :subject:date:references:x-mailer; bh=jnV+cAtnOq1LiqNjTpwYrmf4W2LY/pt+uJY8s8uXQ5w=; b=gevqzHoJnfkuRNRZzvZFCvH/6+Sm03qaW1rDePUz76TtbvoQmjBj69ZKNl3n127HIJ pEcBNuWMvsRrhmeESzDG0/yA6BWVFFN+ik+1Ui2HfuC4vZ2ZxDkOI4VyJdhR+EBk7hlE v4avYX1DU1jXdrnCY63JWRwWVACOxe5tEN/f0= Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=cc:message-id:from:to:in-reply-to:content-type :content-transfer-encoding:mime-version:subject:date:references :x-mailer; b=XJgOWxQxqYs8eQjH7fyUUJXRumu8mCQKNbTdZ0YHLIIURzfTagT2Q/rxGVZPWagNhF yfHT4KZ2q8F3XZSI1wiZZ0uxho4375z3QJqmK6sg8p8kv1sf1fhVrdkE/P0cn/R4pfA3 tiLTCBxSnf2yj9ba+9judoB1Nm/1jJuVcqFis= Thanks for your incredibly swift replies! Thanks for your help, no way I could have figured this out. Mike On 1/10/2008, at 12:47 AM, Manfred Schwind wrote: float retVal; retVal = cornerSize*(1-cos(asin(i/cornerSize))); return (int)retVal; I would write the formula above that way: retVal = cornerSize * (1.0 - cos(asin((float)i / cornerSize))); Regards, Mani -- http://mani.de - friendly software iVolume - listen to music freehand LittleSecrets - the encrypted notepad _______________________________________________ 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/site_archiver%40lists.apple... changing "float retVal" to "double retVal", using "return lround(retVal);" and casting ints as doubles in the formula gave me some real values, which is wonderful! I could have saved myself two hours by asking the list when I first ran into this problem! I've got it spitting out some (jagged but acceptable) corners now, which is wonderful. In case any of you were interested, I'm doing this to create an HTML "object" that can be placed over any background, be given rounded corners and have the background show through. It was being accomplished with Javascript, but I figured it'd be better if this was done one time, when the HTML is generated, instead of at client side. The best argument against democracy is a five-minute conversation with the average voter. -- Sir Winston Churchill I think there is more than one problem here. You may want to get a good book about the C language (Obj-C is just a superset of C). 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. Obviously, I'm no whiz at ObjC, and the fact that this keeps return '0' has got me stumped. Most probably you declared i as an integer value. When dividing with cornerSize, C does not automatically cast this into a floating point value, so the result gets rounded down the next integer value (and maybe always 0 in your case; I don't know). To solve that, e.g. cast i to a float: (float)i / cornerSize. When one of both variables is a float, the other will also be converted to a float and the result is also a float. 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. sin takes the argument in radians, not in degrees. So you have to use e.g. sin(M_PI / 180 * 90) or sin(M_PI / 2) to get the result of "sinus of 90 degrees". This email sent to site_archiver@lists.apple.com
participants (1)
-
Michael Robinson