-
why is the general method for sine and cosine calculation done using look up tables?
Why has nobody else used the Taylors expansion of sine and cosine to calculate the values of sine and cosine. they can be as acurate as you desire and the process is simple
sin (X) = x - x^3/3! + x^5/5! - x^7/7! + X^9/9!.......
very simple, there is a similar formula for cosine as well
cos (x) = x - x^2/2! + X^4/4! + X^6/6! + x^8/8!....
The formula goes on and on but for adequate results in most cases it is only nesercarry to calculate the first three.
I used this today as i wanted a more acurate calculation of sine than look up tables give.
If this is already used sorry for wasting you time, if not does anyone know why, is there some reason that i have missed?
couple of notes just incase you math is not too fresh in your head:
1) the expression 7! (7 factorial) means 1*2*3*4*5*6*7
2) the angle must be converted into radians before being used in the equation. this is simle to do.
angle in radians = angle in degrees * (pie/180)
thanks for you time
-
Senior Member
i used it several times... and why ppl don't use it? it's (much) more complicate to create it accurate (u forget that you don't have ^, so you need to create loops for each factorial calculation), then just to copy some sine table and use it in your movie... and it's also much processor time consuming (when you bring it to accurate over ^10 (which is at least necessery to get it)...
and there is even better way... that i currently use... you let javascript do the calculations for you... it's faster, smoother, absolute precise and better...
so there are 2 reasons why ppl don't use it...
btw. u shouldn't make that math reminder, those are things that kids in primary school knows (i hope so )...
cheers...
-
hi
how do you get java script to calculate the values of sine and cosine with out using flash 5?
i dont think the lack of ^ makes it that much harder.
r-(r*r*r)/6+(r*r*r*r*r)/120-(r*r*r*r*r*r*r)/5040+(r*r*r*r*r*r*r*r*r)/362880+(r*r*r*r*r*r*r*r*r*r*r)/39916800
thats the equation i used. which i find gives far better results than look ups. But i hear what you are saying about processor intensive. but do lookups not run on a loop till they find the value? is this not processor intensive? and in most cases only have the value of sine for whole number angles.
Sorry about the math reminder, it was not meant to be offensive in any way. im new to these boards, as you see from my number of posts, and as a result i am not quite sure the level of everyones maths here.
i often find its the simple stuff that people forget(the things that were boring at school) so i added the math reminder just in case (i forgot to put the angle in radians first time even though its obvious from the derivation of the expansion so it hought other might need reminding )
thanks
-
Senior Member
he he... i was just kidding about the reminder
neways... want to know how to get sine and cosine calcs from javascript... k... here is the little tutorial :
put this script between <head> and </head> tags in your html:
<script language="JavaScript">
var mName = "sinecos";
function mObject(mName){
if (navigator.appName.indexOf ("Microsoft") !=-1){
return window[mName];
}
else{
return document[mName];
}
}
function sineCalc (inVar,outVar) {
inVar = Math.sin(inVar);
mObject(mName).SetVariable(outVar, inVar);
}
function cosineCalc (inVar,outVar) {
inVar = Math.cos(inVar);
mObject(mName).SetVariable(outVar, inVar);
}
</script>
now you need to make some changes in your .swf callin script:
in <object tag line add: ID="sinecos"
in <embed tag line add: name="sinecos" swliveconnect=true
now... when you want to calculate sin or cos, just use in flash:
Get URL ("JavaScript:sineCalc("&calc&",'finish')")
// sine
Get URL ("JavaScript:cosineCalc("&calc&",'finish')")
// cosine
where:
calc - variable you want to get sine of
finish - variable name you want to return sine/cosine value to
so, if you have in flash 5:
newCalc = Math.sin(variable);
in flash 4 with this code it would be:
Get URL ("JavaScript:cosineCalc("&variable&",'newCalc')")
get it?
you can also add many other functions... like just add this functions to javascript:
function sqrtCalc (inVar,outVar) {
inVar = Math.sqrt(inVar);
mObject(mName).SetVariable(outVar, inVar);
}
for SQRT...
function tanCalc (inVar,outVar) {
inVar = Math.tan(inVar);
mObject(mName).SetVariable(outVar, inVar);
}
for TAN
function logCalc (inVar,outVar) {
inVar = Math.log(inVar);
mObject(mName).SetVariable(outVar, inVar);
}
for logarythm
function absCalc (inVar,outVar) {
inVar = Math.abs(inVar);
mObject(mName).SetVariable(outVar, inVar);
}
for absolute
function asinCalc (inVar,outVar) {
inVar = Math.asin(inVar);
mObject(mName).SetVariable(outVar, inVar);
}
for arcus sine
etc. etc.
and call them on same way, just change function name, so above functions you will call:
Get URL ("JavaScript:sqrtCalc("&inputVariable&",'outputVariable')")
// SQRT
Get URL ("JavaScript:tanCalc("&inputVariable&",'outputVariable')")
// TAN
Get URL ("JavaScript:logCalc("&inputVariable&",'outputVariable')")
// LOG
Get URL ("JavaScript:absCalc("&inputVariable&",'outputVariable')")
// ABS
Get URL ("JavaScript:asinCalc("&inputVariable&",'outputVariable')")
// aSIN
etc.
NOTE: this wont work in IE browsers on MAC platforms, and Netscape 6 on all platforms
hope it helps...
-
Senior Member
he he... i was just kidding about the reminder
neways... want to know how to get sine and cosine calcs from javascript... k... here is the little tutorial :
put this script between <head> and </head> tags in your html:
Code:
<script language="JavaScript">
var mName = "sinecos";
function mObject(mName){
if (navigator.appName.indexOf ("Microsoft") !=-1){
return window[mName];
}
else{
return document[mName];
}
}
function sineCalc (inVar,outVar) {
inVar = Math.sin(inVar);
mObject(mName).SetVariable(outVar, inVar);
}
function cosineCalc (inVar,outVar) {
inVar = Math.cos(inVar);
mObject(mName).SetVariable(outVar, inVar);
}
</script>
now you need to make some changes in your .swf callin script:
in <object tag line add: ID="sinecos"
in <embed tag line add: name="sinecos" swliveconnect=true
now... when you want to calculate sin or cos, just use in flash:
Code:
Get URL ("JavaScript:sineCalc("&calc&",'finish')")
// sine
Get URL ("JavaScript:cosineCalc("&calc&",'finish')")
// cosine
where:
calc - variable you want to get sine of
finish - variable name you want to return sine/cosine value to
so, if you have in flash 5:
Code:
newCalc = Math.sin(variable);
in flash 4 with this code it would be:
Code:
Get URL ("JavaScript:cosineCalc("&variable&",'newCalc')")
get it?
you can also add many other functions... like just add this functions to javascript:
Code:
function sqrtCalc (inVar,outVar) {
inVar = Math.sqrt(inVar);
mObject(mName).SetVariable(outVar, inVar);
}
for SQRT...
Code:
function tanCalc (inVar,outVar) {
inVar = Math.tan(inVar);
mObject(mName).SetVariable(outVar, inVar);
}
for TAN
Code:
function logCalc (inVar,outVar) {
inVar = Math.log(inVar);
mObject(mName).SetVariable(outVar, inVar);
}
for logarythm
Code:
function absCalc (inVar,outVar) {
inVar = Math.abs(inVar);
mObject(mName).SetVariable(outVar, inVar);
}
for absolute
Code:
function asinCalc (inVar,outVar) {
inVar = Math.asin(inVar);
mObject(mName).SetVariable(outVar, inVar);
}
for arcus sine
etc. etc.
and call them on same way, just change function name, so above functions you will call:
Code:
Get URL ("JavaScript:sqrtCalc("&inputVariable&",'outputVariable')")
// SQRT
Get URL ("JavaScript:tanCalc("&inputVariable&",'outputVariable')")
// TAN
Get URL ("JavaScript:logCalc("&inputVariable&",'outputVariable')")
// LOG
Get URL ("JavaScript:absCalc("&inputVariable&",'outputVariable')")
// ABS
Get URL ("JavaScript:asinCalc("&inputVariable&",'outputVariable')")
// aSIN
etc.
NOTE: this wont work in IE browsers on MAC platforms, and Netscape 6 on all platforms
hope it helps...
-
Senior Member
dang... stupid vB forums... posted my post twice...
anyways, hope you'll find it useful..
cheers...
-
thanks thats a nice way round the problem, ill try that as soon as i get the chance.
thanks
-
Senior Member
he he... you see... Flash 4 + JavaScript = Flash 5 ... 99% things that you are able to do in flash 5, you can do in F4 + JS combination... only problem is that plugin wont work on all browsers in this mode...
anyways... cheers
-
hi i tried that last night, and when i put a value in rather than a variable it worked fine, but for some reason it did not work when a variable was used
i mean if i used the variable rad and gave rad a value it reterned the value -1.#IND or somethinkg like that
could you shed some light on this, maybe its just me and the effect of too little sleep, but i could not get it to work, and i cant get to my computer till this evening.
thanks
-
Hey, sxdesign, I'm afraid your my last chance for the moment, if you want to see my problem:
http://board.flashkit.com/board/show...74#post1406474
so I'm trying to transmit a variable coming in a query, and it works for Mac without GetUrl directly rewritting the object & embed in a body js script, but.... nope with window and here comes your solution, so I've tried to adapt it for my stuff, and I'm not so good with the sintax and it don't works, take care of the function feed(), in the place of your sine or coscalc, it takes the direction+?myVar of the first page (index_3) opening the popup (sended5) nesting it
the popup code source:
http://216.12.213.8/~phil/cards/sended5.htm
To see the effect:
http://216.12.213.8/~phil/cards/index_2.htm?9
In sendedCard_2, the swf, were ref is a textfield, so in this case a "9" should appears in it:
GetURL("JavaScript:feed(window.opener.location.toS tring(),'','&id_user&','id_user')");
ref = id_user;
Thanks if you can help,
Phil
-
Sorry, just forget it, this is for Flash 5, so in the function I've now:
function feed (aa, bb, outVar, inVar) {
bb = (bb == "") ? "?" : (bb);
cc = (aa.indexOf(bb))+1;
inVar = aa.slice(cc, aa.length);
mObject(mName)[inVar] = outVar;
}
is that correct?
Phil
-
Well, I had to go to see a client, I'm back, the link of the test for PC/windows is wrong it's index_3:
the popup code source:
http://216.12.213.8/~phil/cards/sended5.htm
To see the effect:
http://216.12.213.8/~phil/cards/index_3.htm?9
Thanks if you could watch the popup code souce and tell me if the swf getUrl is ok:
------------------------------------------------------------------------
In sendedCard_2, the swf, were ref is a textfield, so in this case a "9" should appears in it:
GetURL("JavaScript:feed(window.opener.location.toS tring(),'','&id_user&','id_user')");
ref = id_user;
--------------------------------------------------------------------------
Thanks, Phil
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|