Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^4: Make sin wave with GD

by Anonymous Monk
on Jul 01, 2015 at 17:40 UTC ( [id://1132866]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Make sin wave with GD
in thread Make sin wave with GD

Yes. The wave start in upper left. But I want it to start in middle left. And go up. Not down. Any more help? Thank you again.

Replies are listed 'Best First'.
Re^5: Make sin wave with GD
by sn1987a (Deacon) on Jul 01, 2015 at 18:14 UTC
    $y2 = 200 - 200*sin($x2));

    The first 200 will shift the center line of the sine so that it is along the center of the plot. The minus sign flips the sine upside down since y is increasing down, not up. Finally, the scale factor is changed to 200 so there is room for both the upper and lower halves of the sine.

    That can be written without repeating the 200 as:

    $y2 = 200 * (1-sin($x2));

      OK that works! Does is there a generic way to do this for any values though?

        I'm not sure I understand what you are asking, but I will take a shot. If f(x) is a function whose range goes from $f_min to $f_max over the domain of interest, and the graph is of size $graph_size, then plot

        my $span = $f_max - $f_min; $y = (-f($x)-$f_min)*$graph_size/$span;

        In the case of your sine, you would have $f_min = -1; $f_max = 1; $graph_size = 400. This simplifies the the expression in my previous response.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1132866]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-28 15:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found