【发布时间】:2014-06-04 12:23:53
【问题描述】:
我正在编写一个程序来呈现巴恩斯利蕨分形的突变。我的程序完美运行,并准确生成了我希望它生成的输出。我进一步阅读了有关迭代函数系统的信息,并了解到这些分形可以在不使用概率的情况下进行渲染,并在每次迭代中执行所有四个仿射变换。我知道这会增加计算时间,但我想知道我们如何才能消除图片中的概率?
例如,绘制我的蕨类植物的四个函数的概率分别为 2%、84%、7% 和 7%。
对于那些说“我在帖子中找不到问题”的人,这里再次以粗体显示问题。 : 我们如何在每次迭代中使用所有四个函数,而不是根据概率选择四个函数之一?
下面是相关代码:
AffineTransformation.java
public class AffineTransformation
{
private double[][] transformation=new double[2][2];
private double[][] translation=new double[2][1];
public AffineTransformation(double a,double b,double c,double d,double e,double f)
{
transformation[0][0] = a;
transformation[0][1] = b;
transformation[1][0] = c;
transformation[1][1] = d;
translation[0][0] = e;
translation[1][0] = f;
}
public Point transform(Point point)
{
double x = point.getX();
double y = point.getY();
double u = 0.0;
double v = 0.0;
u = transformation[0][0]*x + transformation[0][1]*y;
v = transformation[1][0]*x + transformation[1][1]*y;
u = u + translation[0][0];
v = v + translation[1][0];
return new Point(u,v);
}
}
渲染循环
AffineTransformation f1 = new AffineTransformation(0,0,0,0.25,0,-0.4);
AffineTransformation f2 = new AffineTransformation(0.95,0.005,-0.005,0.93,-0.002,0.5);
AffineTransformation f3 = new AffineTransformation(0.035,-0.2,0.16,0.04,-0.09,0.02);
AffineTransformation f4 = new AffineTransformation(-0.04,0.2,0.16,0.04,0.083,0.12);
Point point = new Point(0.5,0.0);
int N=Width*Height;
for(int i=0;i< N*25;i++)
{
Point newpoint = new Point();
double probability = Math.random();
if(probability < 0.02)
{
newpoint = f1.transform(point);
color=new Color(0x002147);
}
else if(probability < 0.86)
{
newpoint = f2.transform(point);
color=new Color(0x120A8F);
}
else if(probability < 0.93)
{
newpoint = f3.transform(point);
color=new Color(0x002147);
}
else
{
newpoint = f4.transform(point);
color=new Color(0x002147);
}
point = newpoint;
int X=((int)(point.getX()*W/3)+W/2)/2 + W/4-1;
int Y=(int)(point.getY()*H/8) + H/9 -1;
image.setRGB(X,Y, color.getRGB());
}
编辑
我想通过丢弃概率来实现的主要目标。正在测试我自己的转换函数,除非通过反复试验,我显然不会知道概率。那里有什么帮助吗?
详细来说,假设我有四个其他函数,但我不知道要使用什么概率,有没有一种方法可以知道概率,除了通过反复试验。
【问题讨论】:
-
我不完全确定我是否理解正确,但我喜欢你想要的:
point = f4.transform(f3.transform(f2.transform(f1.transform(point)))); //Ad infinitum但这给你留下了选择颜色的问题 -
@Dawnkeeper 你完全理解我。但我已经尝试过你建议的东西。这个东西只在图像上渲染一个像素。在每次迭代中,这一点都保持不变。 :(
-
是的,刚刚自己测试过,这不是解决方案......嗯