私はJava でKoch フラクタル スノーフレークを実行しており、それを svg ファイルに保存しています。
LineStrip2Dクラスでフラクタルを暗記してやっています(イテラブルを実装したVec2DのArrayListのラッパーです)。
主な機能は次のとおりです。
public static LineStrip2D repeatPatternIntoLineStrip2D(
LineStrip2D pattern,
LineStrip2D polygon,
boolean repeatUp) {
/*
* pattern: must be a pattern between Vec(0,0) and Vec(1,0)
* (normalized beetween 0-1 and in X axis)
* */
float angle, distance;
Vec2D pivot, a, b, direction, b1;
LineStrip2D new_polygon = new LineStrip2D();
new_polygon.add(pattern.vertices.get(0));
a = polygon.vertices.get(0);
int count=0;
for (int i = 1; i < polygon.vertices.size(); i++) {
b = polygon.vertices.get(i);
a = polygon.vertices.get(i-1);
distance = b.distanceTo(a);
direction = b.sub(a).normalize();
angle = PApplet.atan2(direction.y, direction.x);
pivot = a;
for (int j = 1; j < pattern.vertices.size(); j++) {
Vec2D _b1 = pattern.vertices.get(j);
b1 = _b1.copy() ;
if(repeatUp)b1.y *= -1;
b1.scaleSelf(distance);
b1 = b1.rotate(angle);
b1.addSelf(pivot);
new_polygon.add(b1);
count++;
}
a = b;
}
System.out.println(count);
return new_polygon;
}
初期コッホ曲線のパターンがあります:
そして私は電話します:
pattern = GeometryHelper.repeatPatternIntoLineStrip2D(pattern, pattern, false);
今問題:
いくつかの反復 (851968) の後、java.lang.OutOfMemoryError: Java heap spaceが発生しました。このエラーを回避し、巨大な svg ファイルを作成するにはどうすればよいですか? このプロセスはさまざまなステップで実行できると思いますが、スマートな方法で実装する方法がわかりません。