You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过7/20π角度的圆锥切片放大Mandelbrot集合?

曼德博集合7/20π角度圆锥切片放大的修正代码

原代码问题分析

  1. 逃逸次数计算逻辑错误:每次迭代覆盖未逃逸点的迭代次数,无法正确区分不同点的逃逸速度。
  2. 复数区域处理错误:直接将复数数组赋值给x/y范围变量,未正确提取实部和虚部作为坐标边界。
  3. 缺少放大控制参数:仅旋转了整个集合范围,没有设置缩放因子和目标放大区域。

修正后的完整代码

import numpy as np
import matplotlib.pyplot as plt

def mandelbrot_set(xmin, xmax, ymin, ymax, width, height, max_iterations):
    X, Y = np.meshgrid(np.linspace(xmin, xmax, width), np.linspace(ymin, ymax, height))
    C = X + 1j * Y
    Z = np.zeros_like(C)
    escape_counts = np.zeros(C.shape, dtype=int)
    mask = np.ones(C.shape, dtype=bool)

    for n in range(max_iterations):
        Z[mask] = Z[mask] ** 2 + C[mask]
        escaped = np.abs(Z) > 2
        escape_counts[escaped & mask] = n
        mask[escaped] = False

    escape_counts[mask] = max_iterations
    return escape_counts

def conical_slice_zoom(angle, zoom_center, zoom_factor, max_iterations, width=800, height=800):
    # 将目标放大中心绕原点旋转指定角度
    rotated_center = zoom_center * np.exp(1j * angle)
    # 原始区域的宽度和高度
    orig_width = 3
    orig_height = 3
    # 计算缩放后的区域范围
    x_range = orig_width / zoom_factor
    y_range = orig_height / zoom_factor
    xmin = rotated_center.real - x_range / 2
    xmax = rotated_center.real + x_range / 2
    ymin = rotated_center.imag - y_range / 2
    ymax = rotated_center.imag + y_range / 2

    return mandelbrot_set(xmin, xmax, ymin, ymax, width, height, max_iterations)

# 配置参数
angle = 7/20 * np.pi
# 选择曼德博集合中可放大的目标中心,此处为经典趣味区域
zoom_center = complex(-0.7, 0.27015)
# 缩放因子,数值越大放大倍数越高
zoom_factor = 100
max_iterations = 512

# 生成曼德博集合数据
M = conical_slice_zoom(angle, zoom_center, zoom_factor, max_iterations)

# 绘制图像
plt.figure(figsize=(10, 10))
plt.imshow(M, cmap='bone')
plt.axis('off')
plt.show()

关键修正说明

  • 逃逸逻辑修复:通过掩码标记未逃逸点,仅更新首次逃逸点的迭代次数,未逃逸点最终设为最大迭代次数,正确反映点的收敛特性。
  • 圆锥切片实现:将指定的放大中心绕原点旋转7/20π角度,以此为基准计算缩放后的坐标范围,实现旋转切片的放大效果。
  • 放大控制:通过zoom_factor调整放大倍数,zoom_center可自由切换要放大的曼德博集合区域。

内容的提问来源于stack exchange,提问作者Ihotu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 01:21:06