c++11 - 如何绘制正弦波?
问题描述
我是 C++ 编程的新手,我想绘制一个正弦/余弦/方波,但我找不到任何资源来帮助我。
我的目标是产生任何波,然后对该波进行傅立叶变换并产生合成波。
解决方案
这段代码应该适合你。只需确保在具有graphics.h
. 在许多新的 IDEgraphics.h
中,默认情况下不会出现,您必须先添加它。
#include <iostream>
#include <conio.h>
#include <graphics.h>
#include <math.h>
using namespace std;
int main(){
initwindow(800,600);
int x,y;
line(0,500,getmaxx(),500); //to draw co-ordinate axes
line(500,0,500,getmaxy());
float pi = 3.14;
for(int i = -360; i < 360 ; i++){
x = (int)500+i;
y = (int)500 - sin(i*pi/100)*25;
putpixel(x,y,WHITE); //to plot points on the graph
}
getch(); //to see the resultant graph
closegraph();
return 0;
}
推荐阅读
- hive - 整个配置单元文件 (hive -f) 在一个错误查询上执行失败
- asp.net-core - Startup.cs 没有得到更新的 appsettings.json 值 asp.net core
- jquery - 根据屏幕尺寸更改 jquery
- r - 如何从 rmarkdown 创建 pdf,其中可以选择和复制图像
- oracle - 如何在已经有 Oracle 数据库的机器上安装 WebLogic
- docker - Cassandra alpine 图像发布计划?
- java - Docker 错误:无法找到或加载主类 Main.Main
- javascript - 更新用户信息
- java - 使用 Java Streams 从嵌套列表创建 TreeMap
- python - 类型错误:缺少多个 .py 文件所需的位置参数