ok just to mention I like making particles
but I dislike needing to use Math.sin, Math.cos for each particle,
Why do I need so much accuracy?
I came up with the idea of making a fast sine and cosine without worrying
that much about accuracy
but worrying about performance.
dont use it for your shooting game this aint THAT accurate,
but it looks GREAT when used with stuff like particles (snow, dust, bricks, etc)
please help with any ideas to improve accuracy without taking away performance;
help improving performance.
it requires angles from an MC
ex.-
Cosine= fcos(alpha_mc.rotation)
Actionscript Code:
var reminder:Number=1;
function fcos(alf:Number):Number {
if (alf < 0) {
alf = -alf;
}
if (alf > 180) {
alf = 180-alf;
}
if (alf>45) {
alf=.7-((alf-45)*.0222)*.7;
} else {
alf=.7+((45-alf)*.0222)*.3;
}
return alf;
}
function fsin(alf:Number):Number {
reminder=1;
if (alf<0) {
reminder=-1;
}
if (alf > 90) {
alf = 180-alf;
} else if (alf < -90) {
alf = 180+alf;
}
if (alf < 0) {
alf = -alf;
}
if (alf>45) {
alf=.7+((alf-45)*.0222)*.3;
} else {
alf=(alf*.0222)*.7;
}
return alf * reminder;
}
(Flash player10)
Speed Tests
average 40 tests
Mat.sin()=1081 fsin()=419
+257% more performance
Mat.cos()=1129.54 fcos()=371.72
+303% more performance
Accuracy tests
System averaged 100000 tests with random angles
fcos() = -6.845% accuracy
fsin() = -9.937% accuracy
EDIT: updated cosine,updated accuracy tests
EDIT2: updated speed tests