[英]Image cosine wave
I need help with this problem that I am having. 我需要解决这个问题。 What I am trying to do is make an image move in a cosine wave pattern in C# Windows Forms, but whatever I try never works.
我想做的是使图像在C#Windows窗体中以余弦波模式移动,但是我尝试的任何方法都行不通。 This is what I have so far in the timer
这就是我到目前为止的时间
dblX = (Double)picture.Left;
dblY = (Double)picture.Top;
dblY = Math.Cos(dblX);
picture.Top = dblY;
picture.Left +=10;
What this does is make the image flash and go up and down very quickly. 这样做是使图像快速闪烁并上下波动。 Any suggestions?
有什么建议么?
Math.Cos期望弧度,因此您可能需要Math.Cos(dblX * Math.PI / 180)。
Math.Cos expects an argument in radians. Math.Cos期望以弧度为单位的论点。
You are adding 10 radians each time. 每次添加10个弧度。 There are 2 * PI radians in a cycle.
一个周期中有2个* PI弧度。
As your picture moves right you probably want to take the Cosine of 2 * PI * (left / total width)
当您的图片向右移动时,您可能希望采用
2 * PI * (left / total width)
的余弦值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.