This wiki is out of date, use the continuation of this wiki instead

Cos

From FenixWiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 16:09, 29 May 2007 (edit)
G105b (Talk | contribs)
(Definition)
← Previous diff
Current revision (15:03, 1 March 2008) (edit) (undo)
Sandman (Talk | contribs)
m (Example)
 
(11 intermediate revisions not shown.)
Line 1: Line 1:
[[Category:functions]] [[Category:functions]]
-[[Category:Maths]]+[[Category:math]]
==Definition== ==Definition==
'''FLOAT''' cos ( <'''FLOAT''' angle> ) '''FLOAT''' cos ( <'''FLOAT''' angle> )
-Returns the cosine of a specified [[angle]].+Returns the cosine of the specified angle.
-This [[function]] performs a cosine calculation on a specified [[angle]] and returns the value as a [[floating point]] number between -1 and 1.+This [[function]] performs a cosine calculation on a certain angle and returns a value between -1 and 1.
== Parameters == == Parameters ==
{| {|
-| '''FLOAT''' angle || - Angle, in thousandths of degrees. i.e. 75000 = 75º+| '''FLOAT''' angle || - [[Angle]], in thousandths of degrees. i.e. 75000 = 75º
|} |}
== Returns == == Returns ==
-'''FLOAT''' : The cosine result of the specified angle.+'''FLOAT''' : The cosine result of the specified [[angle]].
== Notes == == Notes ==
-The angle value used in this function should be in thousandths of degrees, as most angles within Fenix are, and will return a floating point value between -1 and 1.+The [[angle]] value used in this function should be in thousandths of degrees, as most angles within [[Fenix]] are.
-To read about all aspects of trigonometry, you can click on Wikipedia's [http://en.wikipedia.org/wiki/Trigonometric_function Trigonometric function] page.+To read about all aspects of trigonometry, you can visit Wikipedia's [http://en.wikipedia.org/wiki/Trigonometric_function Trigonometric function] page.
== Example == == Example ==
<pre> <pre>
-program example_cos;+Const
-global+ screen_width = 320;
 + screen_height = 200;
 + screen_border = 15;
 +End
 + 
 +Global
float value; float value;
-begin+End
 + 
 +Process Main()
 +Begin
 + 
 + // Modes
set_title("Cosine Graph"); set_title("Cosine Graph");
- set_mode(825,480);+ set_mode(screen_width,screen_height);
- + 
- for(x=50;x<=800;x+=50)+ // X axis
- write(0,x,479,6,itoa(x*360/800));+ for(x=1;x<=8;x++)
 + write( 0,
 + screen_border+x*(screen_width-screen_border)/8+3,
 + screen_height-1,
 + 8,
 + itoa(x*360/8 )+"^" );
end end
- + draw_line(1,screen_height-screen_border,screen_width,screen_height-screen_border);
- write(0,1,20,3,"1");+ 
- write(0,1,240,3,"0");+ // Y axis
- write(0,1,460,3,"-1");+ write(0,screen_border-1,20,5,"1");
- + write(0,screen_border-1,screen_height/2,5,"0");
- draw_line(15,1,15,479);+ write(0,screen_border-1,screen_height-20,5,"-1");
- draw_line(1,470,824,470);+ draw_line(screen_border,1,screen_border,screen_height-1);
- + 
 + // Draw tangent
for(angle=0;angle<360;angle++) for(angle=0;angle<360;angle++)
- value=cos(angle*1000)*220;+ value=cos(angle*1000)*(screen_height/2-20);
- put_pixel(angle*800/360,240+value,rgb(255,255,255));+ put_pixel( screen_border+angle*(screen_width-screen_border)/360,
 + screen_height/2-value,
 + rgb(255,255,255) );
 + // screen_height/2-value because the screen's origin (0,0) is topleft instead of downleft.
end end
- repeat+ Repeat
- frame;+ frame;
- until(key(_esc))+ Until(key(_ESC))
-end+ 
 +End
</pre> </pre>
 +Used in example: [[set_title]](), [[set_mode]](), [[write]](), [[draw_line]](), [[cos]](), [[put_pixel]](), [[key]]()
This will result in something like:<br /> This will result in something like:<br />
-http://wwwhome.cs.utwente.nl/~bergfi/fenix/wiki/cos.PNG+{{Image
 + | image = Cos.png
 + | caption = Cosine
 +}}
 + 
 +{{Funcbox
 + | category = Math
 +}}

Current revision


Contents

[edit] Definition

FLOAT cos ( <FLOAT angle> )

Returns the cosine of the specified angle.

This function performs a cosine calculation on a certain angle and returns a value between -1 and 1.

[edit] Parameters

FLOAT angle - Angle, in thousandths of degrees. i.e. 75000 = 75º

[edit] Returns

FLOAT : The cosine result of the specified angle.

[edit] Notes

The angle value used in this function should be in thousandths of degrees, as most angles within Fenix are.

To read about all aspects of trigonometry, you can visit Wikipedia's Trigonometric function page.

[edit] Example

Const
    screen_width  = 320;
    screen_height = 200;
    screen_border = 15;
End

Global
    float value;
End

Process Main()
Begin

    // Modes
    set_title("Cosine Graph");
    set_mode(screen_width,screen_height);

    // X axis
    for(x=1;x<=8;x++)
        write( 0,
               screen_border+x*(screen_width-screen_border)/8+3,
               screen_height-1,
               8,
               itoa(x*360/8 )+"^" );
    end
    draw_line(1,screen_height-screen_border,screen_width,screen_height-screen_border);

    // Y axis
    write(0,screen_border-1,20,5,"1");
    write(0,screen_border-1,screen_height/2,5,"0");
    write(0,screen_border-1,screen_height-20,5,"-1");
    draw_line(screen_border,1,screen_border,screen_height-1);

    // Draw tangent
    for(angle=0;angle<360;angle++)
        value=cos(angle*1000)*(screen_height/2-20);
        put_pixel( screen_border+angle*(screen_width-screen_border)/360,
                   screen_height/2-value,
                   rgb(255,255,255) );
        // screen_height/2-value because the screen's origin (0,0) is topleft instead of downleft.
    end

    Repeat
        frame;
    Until(key(_ESC))

End

Used in example: set_title(), set_mode(), write(), draw_line(), cos(), put_pixel(), key()

This will result in something like:

Image:Cos.png
Cosine


Math Functions
Abs() • Acos() • Asin() • Atan() • Cos() • Fget_angle() • Fget_dist() • Get_distx() • Get_disty() • Pow() • Rand() • Rand_seed() • Sin() • Sqrt() • Tan() •
Personal tools