Mathematical formula: y=Asin(ωx φ) k
Sample: http://www.zhaojz.com.cn/demo/draw7.html
JS function declaration:
//Draw a sine curve
//dot origin
//amplitude Amplitude -- A
//initialPhase initial phase -- φ
//setover offset -- k
//palstance angular velocity -- ω
//len number of cycles
function drawSinusoid(dot, amplitude,initialPhase,palstance,setover, len, opts){
var color = opts&&opts.color?opts.color:"DarkRed"; //Color of curve
var max = len*2*Math.PI/w; //The maximum value of x
//var x = -2*Math.PI/w/3;
var x = 0; //Initial value of x
var pre = [dot[0] x, dot[1] (amplitude*Math.sin(palstance*x initialPhase) setover)]; //Initial value of y
for(;x < max;x =5){ //Draw a line every five units
var cur = [dot[0] x, dot[1] (amplitude*Math.sin(palstance*x initialPhase) setover)];
drawLine(pre, cur, {color: color}); // Draw line
pre = cur;
}
var d = Math.PI/(2*w);
for(var x =0;x < max;x =d){//Plot point
var cur = [dot[0] x, dot[1] (amplitude*Math.sin(palstance*x initialPhase) setover)];
drawPoint({
pw:3,ph:3,color:'DarkRed',point: cur
});
}
var pend = [dot[0] max, dot[1] (amplitude*Math.sin(palstance*max initialPhase) setover)];
drawPoint({
pw:3,ph:3,color:'DarkRed',point: pend
});
drawLine(pre, pend);
}