ReferenceError: "cos" is not defined. (line#6)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

ReferenceError: "cos" is not defined. (line#6)

Robert and Sigrid
G'day list,

Can anyone help? I get the error message as shown in the subject line  
trying to run this macro:

var pi=3.14159265359;
for (i=0; i<18; i++){
        angle1=pi+(i/18)*pi;
        angle2=(i/18)*pi;
        x1=384+384*cos(angle1);
        x2=384+384*cos(angle2);
        y1=384+384*sin(angle1);
        y2=384+384*sin(angle2);
        makeLine(x1, y1, x2, y2);
        run("Reslice [/]...", "input=32.000 output=32.000 slice=1");
        selectWindow("Stack");
}

but I see example after example where cos(angle) and sin(angle)  
functions are used. What am I doing wrong?

Cheers,
Robert
Reply | Threaded
Open this post in threaded view
|

Re: ReferenceError: "cos" is not defined. (line#6)

Wayne Rasband
On Mar 17, 2009, at 4:32 PM, Robert and Sigrid wrote:

> G'day list,
>
> Can anyone help? I get the error message as shown in the subject line
> trying to run this macro:
>
> var pi=3.14159265359;
> for (i=0; i<18; i++){
> angle1=pi+(i/18)*pi;
> angle2=(i/18)*pi;
> x1=384+384*cos(angle1);
> x2=384+384*cos(angle2);
> y1=384+384*sin(angle1);
> y2=384+384*sin(angle2);
> makeLine(x1, y1, x2, y2);
> run("Reslice [/]...", "input=32.000 output=32.000 slice=1");
> selectWindow("Stack");
> }
>
> but I see example after example where cos(angle) and sin(angle)
> functions are used. What am I doing wrong?

"ReferenceError: "cos" is not defined. (line#6)" is a JavaScript error
but this is not JavaScript code. Does the file have a ".js" extension?
ImageJ macros should have either a ".txt" or ".ijm" extension.

-wayne
Reply | Threaded
Open this post in threaded view
|

Re: ReferenceError: "cos" is not defined. (line#6)

Gluender-2
In reply to this post by Robert and Sigrid
Not sure what happen in your macro...

>G'day list,
>
>Can anyone help? I get the error message as shown in the subject
>line trying to run this macro:
>
>var pi=3.14159265359;
>for (i=0; i<18; i++){
> angle1=pi+(i/18)*pi;
> angle2=(i/18)*pi;
> x1=384+384*cos(angle1);
> x2=384+384*cos(angle2);
> y1=384+384*sin(angle1);
> y2=384+384*sin(angle2);
> makeLine(x1, y1, x2, y2);
> run("Reslice [/]...", "input=32.000 output=32.000 slice=1");
> selectWindow("Stack");
>}
>
>but I see example after example where cos(angle) and sin(angle)
>functions are used. What am I doing wrong?
>
>Cheers,
>Robert


But the following macro runs fine here:

i = 1;
angle1 = PI * ( 1 + i/18);
print ( 10 * ( 1 + cos(angle1) ) );

Please note that PI is already implemented as a constant in ImageJ.

HTH

Herbie
Reply | Threaded
Open this post in threaded view
|

Re: ReferenceError: "cos" is not defined. (line#6)

Robert and Sigrid
In reply to this post by Robert and Sigrid
On Tue, 17 Mar 2009 17:01:47 -0400, Wayne Rasband <[hidden email]> wrote:

>On Mar 17, 2009, at 4:32 PM, Robert and Sigrid wrote:
>
>> G'day list,
>>
>> Can anyone help? I get the error message as shown in the subject line
>> trying to run this macro:
>>
>> var pi=3.14159265359;
>> for (i=0; i<18; i++){
>> angle1=pi+(i/18)*pi;
>> angle2=(i/18)*pi;
>> x1=384+384*cos(angle1);
>> x2=384+384*cos(angle2);
>> y1=384+384*sin(angle1);
>> y2=384+384*sin(angle2);
>> makeLine(x1, y1, x2, y2);
>> run("Reslice [/]...", "input=32.000 output=32.000 slice=1");
>> selectWindow("Stack");
>> }
>>
>> but I see example after example where cos(angle) and sin(angle)
>> functions are used. What am I doing wrong?
>
>"ReferenceError: "cos" is not defined. (line#6)" is a JavaScript error
>but this is not JavaScript code. Does the file have a ".js" extension?
>ImageJ macros should have either a ".txt" or ".ijm" extension.
>
>-wayne

Thanks Wayne, that did the trick! I've just picked up IJ again and was "recording" a macro in IJ, and
creating the macro pressing the "create" button in the "Record" window, but that generates a .js
file indeed. Saving the macro as a .txt file and running it did perform as expected, it sliced the
stack of SLO pictures across the diagonal turning clockwise over 10 degrees per step. Thanks Also
to Herbie for pointing out the fact that PI is an implemented constant; very helpful info.

Cheers,
Robert