【发布时间】:2022-01-21 12:12:13
【问题描述】:
所以我正在尝试制作一个程序,输出 n 宽和 n 高的菱形的坐标,然后表示使用 gnuplot 程序完成的 figure.out。我已经完成了这段代码,但我想让它更容易。
#include <stdio.h>
#include <stdlib.h>
#define DEF 10
int main()
{
float def_an,def_al,slope,i,j,height,width;
FILE *out = fopen ( "diamond.out", "w" );
if(out==NULL)
{
printf("Wrong output");
return 1;
}
printf("Introduce the height: ");
scanf("%f", &height);
printf("Introduce the width: ");
scanf("%f", &width);
def_al=(height/DEF);
def_an=(width/DEF);
slope=(height/width);
for(j=0;j<= height/2;j+=def_al)
{
for(i=((j-(height/2))/slope);i<=(((height/2)-j)/slope);i+=def_an)
{
printf("%.2f %.2f\n",i,j);
fprintf (out, "%.2f %.2f\n", i,j );
}
}
for(j=(0-def_al);j>= -height/2;j-=def_al)
{
for(i=(((-height/2)-j)/slope);i<=((j-(-height/2))/slope);i+=def_an)
{
printf("%.2f %.2f\n",i,j);
fprintf (out, "%.2f %.2f\n", i,j );
}
}
fclose(out);
return 0;
}
【问题讨论】:
-
gnuplot 知道如何在点之间画线。所以你可以只输出5分;你根本不需要循环。
-
你是认真的吗?我整晚都在制作那个代码,哈哈。好的,但是那我该怎么做呢?我的意思是你能给我举个例子说明 gnuplot 代表 5 分吗?
-
好吧,但是钻石应该填充在里面,而不是不透明的
-
我已经有一段时间没有使用 gnuplot 了。我必须找到并阅读它的文档。你也可以。
-
@Tenko 我建议在 gnuplot 中对
plot with polygons或set object polygon进行一些研究;手册、SO 和 google 中有很多示例...