【发布时间】:2014-05-29 19:52:57
【问题描述】:
我已经阅读了如何渲染 Julia 分形 here。我对具有 f(z)=z2+C 形式的方程的二次 Julia 集非常彻底,但我不知道如何渲染复杂的 Julia 函数像 f(z) = ez - 0.65 和其他涉及正弦和余弦的复杂函数。我们如何渲染这些类型的函数?另外,指数函数中应该使用什么颜色映射?
例如,我想实现如下图和Wikipedia page 上给出的其他图像。
编辑:
这是我尝试过的:
ComplexNumber.java
package plane.complex;
/**
* code>ComplexNumber</code> is a class which implements complex numbers in Java.
* It includes basic operations that can be performed on complex numbers such as,
* addition, subtraction, multiplication, conjugate, modulus and squaring.
*
* @author Abdul Fatir
* @version 1.0
*
*/
public class ComplexNumber
{
/**
* The real, Re(z), part of the <code>ComplexNumber</code>.
*/
private double real;
/**
* The imaginary, Im(z), part of the <code>ComplexNumber</code>.
*/
private double imaginary;
/**
* Constructs a new <code>ComplexNumber</code> object with both real and imaginary parts 0 (z = 0 + 0i).
*/
public ComplexNumber()
{
real = 0.0;
imaginary = 0.0;
}
/**
* Constructs a new <code>ComplexNumber</code> object.
* @param real the real part, Re(z), of the complex number
* @param imaginary the imaginary part, Im(z), of the complex number
*/
public ComplexNumber(double real, double imaginary)
{
this.real = real;
this.imaginary = imaginary;
}
/**
* Adds another <code>ComplexNumber</code> to the current complex number.
* @param complex_number the complex number to be added to the current complex number
*/
public void add(ComplexNumber complex_number)
{
this.real = this.real + complex_number.real;
this.imaginary = this.imaginary + complex_number.imaginary;
}
/**
* The complex conjugate of the current complex number.
* @return a <code>ComplexNumber</code> object which is the conjugate of the current complex number
*/
public ComplexNumber conjugate()
{
return new ComplexNumber(this.real,-this.imaginary);
}
/**
* The modulus, magnitude or the absolute value of current complex number.
* @return the magnitude or modulus of current complex number
*/
public double mod()
{
return Math.sqrt(Math.pow(this.real,2) + Math.pow(this.imaginary,2));
}
/**
* The square of the current complex number.
* @return a <code>ComplexNumber</code> object which is the square of the current complex number
*/
public ComplexNumber square()
{
double _real = this.real*this.real - this.imaginary*this.imaginary;
double _imaginary = 2*this.real*this.imaginary;
return new ComplexNumber(_real,_imaginary);
}
/**
* Multiplies another <code>ComplexNumber</code> to the current complex number.
* @param complex_number the complex number to be multiplied to the current complex number
*/
public void multiply(ComplexNumber complex_number)
{
double _real = this.real*complex_number.real - this.imaginary*complex_number.imaginary;
double _imaginary = this.real*complex_number.imaginary + this.imaginary*complex_number.real;
this.real = _real;
this.imaginary = _imaginary;
}
/**
* Prints the complex number in x + yi format
*/
@Override
public String toString()
{
return this.real+" + "+this.imaginary+"i";
}
/**
* Calculates the exponential of the <code>ComplexNumber</code>
* @param complex_number The input complex number
* @return a <code>ComplexNumber</code> which is e^(input complex_number)
*/
public static ComplexNumber exp(ComplexNumber complex_number)
{
double a = complex_number.real;
double b = complex_number.imaginary;
a = Math.exp(a)*Math.cos(b);
b = Math.exp(a)*Math.sin(b);
return new ComplexNumber(a,b);
}
}
这是我尝试渲染的方式:
for(int X=0; X<WIDTH; X++)
{
for(int Y=0; Y<HEIGHT; Y++)
{
ComplexNumber oldz = new ComplexNumber();
ComplexNumber newz = new ComplexNumber(2.0*(X-WIDTH/2)/(WIDTH/2), 1.33*(Y-HEIGHT/2)/(HEIGHT/2) );
int i;
for(i=0;i<max_iter; i++)
{
oldz = newz;
newz=ComplexNumber.exp(newz);
newz.add(constant);
if(newz.mod() > 2)
break;
}
float Brightness = i < max_iter ? 1f : 0;
float Hue = i%256 /255.0f;
Color color = Color.getHSBColor(Hue, Saturation, Brightness);
img.setRGB(X,Y, color);
}
}
【问题讨论】:
-
你的陈述中有问题吗?
-
@hooknc 是的,您需要眼睛才能看到帖子中的两个问号,但是当您过分热衷于否决投票时,您将看不到它们。
-
我没有给你投反对票。 Stackoverflow 是一个大型社区,只是导致一个人 cmet,并不意味着他们对你投了反对票。您的问题过于宽泛,这很可能是您投反对票的原因。您的意思是如何使用其中一个 ui 库在 java 中渲染 julia 分形算法?
-
这里似乎没有具体的编程问题。
-
它过于宽泛。听起来您要求我们为您编写一个程序,而没有人会这样做。你需要自己尝试一些事情,当你遇到困难时,回来问一些具体的事情。
标签: java algorithm math colors fractals