以特定周期宽度绘制Cosx [英] Draw Cosx with specific period width
本文介绍了以特定周期宽度绘制Cosx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何绘制宽度为100且高度为50的Cosx周期?
how can i draw a period of Cosx with width =100 and height 50?
我最近的代码很难控制它们:(
my recent code is very hard to control them :(
// this to find y with each x to draw Cos
for (int i = 0, j = 0; i < 50; i += 1, j++)
{
int y = (int)((Math.Cos((double)i * height/10F * Math.PI / cy) + 1.0) * (cx - 1) / widtd/10F);
poi.SetValue(new Point(i, y),j); // poi is an aray of point
}
推荐答案
基于OP的最后评论,我认为宽度是指一个句点,因此计算点幅度为 amp
且周期为 的余弦函数的形式如下:
Based on OP's last comment I assume "width" means a single period. Therefore to calculate the points of a cosine function with amplitude amp
and a period of period
looks like this:
int amp = 50, period = 100;
Point[] poi = new Point[period];
for (int x = 0; x < period; x++)
{
int y = (int)(amp * Math.Cos(x * 2 * Math.PI * (1.0 / period)));
poi[x] = new Point(x, y);
}
N提示这是 1:1计算,即一个点是一个像素。
Note that this is a "1:1" calculation, i.e. one point is one pixel.
这篇关于以特定周期宽度绘制Cosx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文