Hello all
I am having a small problem wih a javascript, could anyone help me
please
1. first of all
this code requires a form f01 and textarea t01
<form name ="f01">
<textarea name="t01" rows="80" cols="50">
</textarea></form>
2. the javascript is as follows:

function point(x,y,z){
this.x = x;
this.y = y;
this.z = z;
}
function mkPoints(){
tmp01 = new point(50,50,50);
tmp02 = new point(50,50,50);
tmp03 = new point(50,50,50);
tmp04 = new point(50,50,50);
tmp05 = new point(50,50,50);
tmp06 = new point(50,50,50);
tmp07 = new point( 50,50,50);
tmp08 = new point( 50, 50 ,50 );
}
function rotate(xrot,yrot){
for (i=1;i<=8;i++){
document.all["tmp_zpos0"+i] = (eval("tmp0"+i+".z") * Math.cos(yrot))
 (eval("tmp0"+i+".x") * Math.sin(yrot))
document.all["tmp0"+i+".x"] =
(eval("tmp0"+i+".z")*Math.sin(yrot))+(eval("tmp0"+ i+".x")*Math.cos(yrot));
document.all["tmp0"+i+".z"] =
(eval("tmp0"+i+".y")*Math.sin(xrot))+(eval("docume nt.all.tmp_zpos0"+i)*Math.cos(xrot));
document.all["tmp0"+i+".y"] =
(eval("tmp0"+i+".y")*Math.cos(xrot))(document.all["tmp_zpos0"+i]*Math.sin(xrot));
document.f01.t01.value = document.f01.t01.value +
document.all["tmp0"+i+".y"] + "\n"
}
setTimeout("rotate(0.02,0.01)", 1000);
}
function runAll (){
mkPoints()
rotate(0.02,0.01)
}

The problem is as follows  I am baffled as to why it appears to retun
Nan or undefined when the values are clearly are there.
Please help,
Thank you
oliverh 4 4610 ma**@oliverhadfield.co.uk (oliver hadfield) writes: 1. first of all
this code requires a form f01 and textarea t01
<form name ="f01"> <textarea name="t01" rows="80" cols="50"> </textarea></form>
2. the javascript is as follows: 
function point(x,y,z){ this.x = x; this.y = y; this.z = z; } function mkPoints(){ tmp01 = new point(50,50,50); tmp02 = new point(50,50,50); tmp03 = new point(50,50,50); tmp04 = new point(50,50,50); tmp05 = new point(50,50,50); tmp06 = new point(50,50,50); tmp07 = new point( 50,50,50); tmp08 = new point( 50, 50 ,50 );
I would make an array of these points instead of eight global variables.
}
function rotate(xrot,yrot){ for (i=1;i<=8;i++){
document.all["tmp_zpos0"+i] = (eval("tmp0"+i+".z") * Math.cos(yrot))  (eval("tmp0"+i+".x") * Math.sin(yrot))
You never need eval for things like this. It is even much faster to do
it without.
To access the global variabel "tmp0"+i, you can just write
window["tmp0"+i]
You use document.all, which is not as widely applicable as
document.getElementById. I think you just wanted to use "eval" anyway.
You assign directly to the result of document.all[...]. That is most
likely not what you want.
You don't mention an HTML element called "tmp_zpos01", so I guess you
meant to write
eval("tmp_zpos0"+i) = ...
where tmp_zpos01 is a variable?
In that case, you only need one variable, not one for each point.
I would write this line as
var tmp_zpos = window["tmp0"+i].z * Math.cos(yrot) 
window["tmp0"+i].x * Math.sin(yrot);
document.all["tmp0"+i+".x"] = (eval("tmp0"+i+".z")*Math.sin(yrot))+(eval("tmp0"+ i+".x")*Math.cos(yrot));
window["tmp0"+i].x = window["tmp0"+i].z*Math.sin(yrot) +
window["tmp0"+i].x*Math.cos(yrot);
document.all["tmp0"+i+".z"] = (eval("tmp0"+i+".y")*Math.sin(xrot))+(eval("docume nt.all.tmp_zpos0"+i)*Math.cos(xrot));
window["tmp0"+i].z = window["tmp0"+i].y*Math.sin(xrot) +
tmp_zpos*Math.cos(xrot);
document.all["tmp0"+i+".y"] = (eval("tmp0"+i+".y")*Math.cos(xrot))(document.all["tmp_zpos0"+i]*Math.sin(xrot));
window["tmp0"+i].y = window["tmp0"+i].y*Math.cos(xrot) +
tmp_zpos*Math.sin(xrot);
document.f01.t01.value = document.f01.t01.value + document.all["tmp0"+i+".y"] + "\n"
Here you use document.all again, where you definitly just meant to use
eval (and you shouldn't use eval either).
document.forms['f01'].elements['t01'].value += window["tmp0"+i].y+"\n";
The problem is as follows  I am baffled as to why it appears to retun Nan or undefined
*What* returns NaN or undefined? There are not return statements in
the code. I guess it is one of the document.all's that return undefined
because you ask for an element that isn't there.
when the values are clearly are there.
Are they. Have you tested that the values are correct (e.g. by inserting
alerts or using a debugger)?
/L

Lasse Reichstein Nielsen  lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
On 12 Oct 2003 16:13:33 0700 ma**@oliverhadfield.co.uk (oliver hadfield) wrote: Hello all
I am having a small problem wih a javascript, could anyone help me please
1. first of all
this code requires a form f01 and textarea t01
<form name ="f01"> <textarea name="t01" rows="80" cols="50"> </textarea></form>
2. the javascript is as follows: 
function point(x,y,z){ this.x = x; this.y = y; this.z = z; } function mkPoints(){ tmp01 = new point(50,50,50); tmp02 = new point(50,50,50); tmp03 = new point(50,50,50); tmp04 = new point(50,50,50); tmp05 = new point(50,50,50); tmp06 = new point(50,50,50); tmp07 = new point( 50,50,50); tmp08 = new point( 50, 50 ,50 ); } function rotate(xrot,yrot){ for (i=1;i<=8;i++){ document.all["tmp_zpos0"+i] = (eval("tmp0"+i+".z") * Math.cos(yrot))  (eval("tmp0"+i+".x") * Math.sin(yrot)) document.all["tmp0"+i+".x"] = (eval("tmp0"+i+".z")*Math.sin(yrot))+(eval("tmp0"+ i+".x")*Math.cos(yr ot)); document.all["tmp0"+i+".z"] = (eval("tmp0"+i+".y")*Math.sin(xrot))+(eval("docume nt.all.tmp_zpos0"+i )*Math.cos(xrot)); document.all["tmp0"+i+".y"] = (eval("tmp0"+i+".y")*Math.cos(xrot))(document.all["tmp_zpos0"+i]*Mat h.sin(xrot)); document.f01.t01.value = document.f01.t01.value + document.all["tmp0"+i+".y"] + "\n" } setTimeout("rotate(0.02,0.01)", 1000); } function runAll (){ mkPoints() rotate(0.02,0.01) } 
The problem is as follows  I am baffled as to why it appears to retun Nan or undefined when the values are clearly are there.
I'm just a newbie in javascript but I see no elements defined to match
your strings in document.all[string] statements.

Life is an offensive, directed against the repetitious mechanism of the
Universe.
Alfred North Whitehead (18611947)
oliver hadfield said: Hello all
I am having a small problem wih a javascript, could anyone help me please
1. first of all
this code requires a form f01 and textarea t01
<form name ="f01"> <textarea name="t01" rows="80" cols="50"> </textarea></form>
2. the javascript is as follows: 
function point(x,y,z){ this.x = x; this.y = y; this.z = z; } function mkPoints(){ tmp01 = new point(50,50,50); tmp02 = new point(50,50,50); tmp03 = new point(50,50,50); tmp04 = new point(50,50,50); tmp05 = new point(50,50,50); tmp06 = new point(50,50,50); tmp07 = new point( 50,50,50); tmp08 = new point( 50, 50 ,50 ); } function rotate(xrot,yrot){ for (i=1;i<=8;i++){ document.all["tmp_zpos0"+i] = (eval("tmp0"+i+".z") * Math.cos(yrot))  (eval("tmp0"+i+".x") * Math.sin(yrot)) document.all["tmp0"+i+".x"] = (eval("tmp0"+i+".z")*Math.sin(yrot))+(eval("tmp0" +i+".x")*Math.cos(yrot)); document.all["tmp0"+i+".z"] = (eval("tmp0"+i+".y")*Math.sin(xrot))+(eval("docum ent.all.tmp_zpos0"+i)*Math.cos(xrot)); document.all["tmp0"+i+".y"] = (eval("tmp0"+i+".y")*Math.cos(xrot))(document.all["tmp_zpos0"+i]*Math.sin(xrot)); document.f01.t01.value = document.f01.t01.value + document.all["tmp0"+i+".y"] + "\n" } setTimeout("rotate(0.02,0.01)", 1000); } function runAll (){ mkPoints() rotate(0.02,0.01) } 
The problem is as follows  I am baffled as to why it appears to retun Nan or undefined when the values are clearly are there
What returns NaN? None of the functions you've shown us return anything.
You're using document.all, which is obsolete, and using eval() where it
is not necessary, which is not a good practice.
Lasse Reichstein Nielsen <lr*@hotpop.com> wrote in message news:<r8**********@hotpop.com>... ma**@oliverhadfield.co.uk (oliver hadfield) writes:
Hey Lasse,
Thank you very much for looking into the problem in such depth. 1. first of all
this code requires a form f01 and textarea t01
<form name ="f01"> <textarea name="t01" rows="80" cols="50"> </textarea></form>
2. the javascript is as follows: 
function point(x,y,z){ this.x = x; this.y = y; this.z = z; } function mkPoints(){ tmp01 = new point(50,50,50); tmp02 = new point(50,50,50); tmp03 = new point(50,50,50); tmp04 = new point(50,50,50); tmp05 = new point(50,50,50); tmp06 = new point(50,50,50); tmp07 = new point( 50,50,50); tmp08 = new point( 50, 50 ,50 );
I would make an array of these points instead of eight global variables.
An array. I will have to look into how to do that. }
function rotate(xrot,yrot){ for (i=1;i<=8;i++){
document.all["tmp_zpos0"+i] = (eval("tmp0"+i+".z") * Math.cos(yrot))  (eval("tmp0"+i+".x") * Math.sin(yrot))
You never need eval for things like this. It is even much faster to do it without.
To access the global variabel "tmp0"+i, you can just write window["tmp0"+i]
You use document.all, which is not as widely applicable as document.getElementById. I think you just wanted to use "eval" anyway. You assign directly to the result of document.all[...]. That is most likely not what you want.
You don't mention an HTML element called "tmp_zpos01", so I guess you meant to write eval("tmp_zpos0"+i) = ... where tmp_zpos01 is a variable? In that case, you only need one variable, not one for each point.
Good advice, I cut out the eval("tmp_zpos0"+i)
so I rewrote the following:
window.tmpZpos = (window["tmp0"+i].z * Math.cos(yrot)) 
(window["tmp0"+i].x * Math.sin(yrot));
window["tmp0"+i+".x"] = (window["tmp0"+i].z * Math.sin(yrot)) +
(window["tmp0"+i].x * Math.cos(yrot));
window["tmp0"+i+".z"] = (window["tmp0"+i].y * Math.sin(xrot)) +
(window.tmpZpos * Math.cos(xrot));
window["tmp0"+i+".y"] = (window["tmp0"+i].y * Math.cos(xrot)) 
(window.tmpZpos * Math.sin(xrot));
works perfectly
I would write this line as
var tmp_zpos = window["tmp0"+i].z * Math.cos(yrot)  window["tmp0"+i].x * Math.sin(yrot);
document.all["tmp0"+i+".x"] = (eval("tmp0"+i+".z")*Math.sin(yrot))+(eval("tmp0"+ i+".x")*Math.cos(yrot));
window["tmp0"+i].x = window["tmp0"+i].z*Math.sin(yrot) + window["tmp0"+i].x*Math.cos(yrot);
document.all["tmp0"+i+".z"] = (eval("tmp0"+i+".y")*Math.sin(xrot))+(eval("docume nt.all.tmp_zpos0"+i)*Math.cos(xrot));
window["tmp0"+i].z = window["tmp0"+i].y*Math.sin(xrot) + tmp_zpos*Math.cos(xrot);
document.all["tmp0"+i+".y"] = (eval("tmp0"+i+".y")*Math.cos(xrot))(document.all["tmp_zpos0"+i]*Math.sin(xrot));
window["tmp0"+i].y = window["tmp0"+i].y*Math.cos(xrot) + tmp_zpos*Math.sin(xrot);
document.f01.t01.value = document.f01.t01.value + document.all["tmp0"+i+".y"] + "\n"
Here you use document.all again, where you definitly just meant to use eval (and you shouldn't use eval either).
document.forms['f01'].elements['t01'].value += window["tmp0"+i].y+"\n";
The problem is as follows  I am baffled as to why it appears to retun Nan or undefined
*What* returns NaN or undefined? There are not return statements in the code. I guess it is one of the document.all's that return undefined because you ask for an element that isn't there.
when the values are clearly are there.
Are they. Have you tested that the values are correct (e.g. by inserting alerts or using a debugger)?
/L
I was using the textarea t01 to return the results.
Thank you again,
oliverh This discussion thread is closed Replies have been disabled for this discussion. Similar topics
2 posts
views
Thread by NotGiven 
last post: by

3 posts
views
Thread by DMAC 
last post: by

4 posts
views
Thread by Hal 
last post: by

49 posts
views
Thread by matty 
last post: by

45 posts
views
Thread by VK 
last post: by

10 posts
views
Thread by Greg 
last post: by

26 posts
views
Thread by Frederick Gotham 
last post: by

33 posts
views
Thread by coolguyaroundyou 
last post: by
           