1
我有一個代碼,這有望使得謝爾賓斯基三角形,我想知道我怎麼能輸出你讀入gnuplot的數據文件嗎?我從來沒有用過gnuplot,我正在努力嘗試。另外,如果這是不可能的,我應該如何修改我的代碼以繪製我的三角形以便我可以看到它?
的代碼說明:
我想,以產生始於點(0,0)
並有一個0.33
概率看起來,下一步將是半路目前點位(0,2)
之間的謝爾賓斯基三角形。下一步將在當前點和(1,sqrt3)
之間的中途有一個0.33
的概率。有一個0.33
概率,下一步將在當前點和(0,0)
之間。
代碼:
import java.util.Random;
public class SierpinskiTriangle {
public static void main(String[] args) {
//int N = Integer.parseInt(args[0]); // number of points
int N = 5000;
double sqrt3 = Math.sqrt(3);
double x = 0.0, y = 0.0; //plots
//need to draw triangle boundary
// triangle rules
for (int i = 0; i < N; i++) {
double r = Math.random();
double x0, y0;
if (r < 1/3) {
x0 = 0.0; y0 = 0.0;
} else if (r < 2/3) {
x0 = 0.0; y0 = 2.0;
} else {
x0 = 1.0; y0 = sqrt3;
}
x = (x0 + x)/2;
y = (y0 + y)/2;
}
}
}
這應該是可行的。您能否提供您的代碼生成的數據作爲鏈接到文件? – Miguel 2015-02-23 16:01:25