Mandelbrot Set & Julia Set -- 美丽分形 (C++, MFC + BCG + CxImage 实现)

    一、分形(Fractal)

    这个概念应该很多人听过,说到这个应该就会提到最著名的Mandelbrot Set与Julia Set,最近便着手写了个能画出两者图形的一个小程序,环境为 VS2013 + BCG + CxImage。

    关于两者的概念,网上很多非常清晰的解释,这里便不再啰嗦,核心公式即

f(z) = z^2 + c

    Mandelbrot Set是在z = 0处,对复平面上每一点c进行迭代计算,若每一个 |f(z)| 小于2,则其属于集合内,当然,我们在计算机计算时只能设定一个迭代次数,超过迭代上限仍然模小于2的认为属于集合。

    Julia Set则是对于设定的一个常数c(其模假定小于2),对复平面内的每一点z进行迭代计算,若满足模小于2则属于集合,两者有差别,具体解释可以维基。

   二、 画图实现

    2.1 复数定义

class CComplex
{
public:
	~CComplex(){};

	CComplex(long double real = 0, long double imag = 0)
		: m_real(real)
		, m_imag(imag)
	{}

	CComplex& operator +=(const CComplex &rhs)
	{
		this->m_real += rhs.m_real;
		this->m_imag += rhs.m_imag;

		return *this;
	}

	CComplex& operator -=(const CComplex &rhs)
	{
		this->m_real -= rhs.m_real;
		this->m_imag -= rhs.m_imag;

		return *this;
	}

	friend CComplex operator +(const CComplex &lhs, const CComplex &rhs);
	friend CComplex operator -(const CComplex &lhs, const CComplex &rhs);
	friend CComplex operator *(const CComplex &lhs, const CComplex &rhs);
	friend bool operator ==(const CComplex &lhs, const CComplex &rhs);
	
	inline friend double modulus_square(const CComplex & c)
	{
		return c.m_real * c.m_real + c.m_imag * c.m_imag;
	}

	inline friend CComplex complex_power(const CComplex &c, unsigned int n)
	{
		CComplex result(1);

		for
  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值