C# 曼德布罗特计划是';t输出正确的数据

C# 曼德布罗特计划是';t输出正确的数据,c#,mandelbrot,C#,Mandelbrot,我被分配给我的班级制作一个绘制曼德尔布罗特图形的程序。 我们基本上需要让程序绘制结果的位图。 问题是,我的CalcMBF函数只输出2作为曼德布罗特数。 我完全不知道这是为什么。有人能帮我吗? 这是我的密码: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using Sys

我被分配给我的班级制作一个绘制曼德尔布罗特图形的程序。
我们基本上需要让程序绘制结果的位图。

问题是,我的
CalcMBF
函数只输出
2
作为曼德布罗特数。
我完全不知道这是为什么。有人能帮我吗?

这是我的密码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Mandelbrot_Figure
{
    class PreMainClass
    {
        static void main (String[] args)
        {
            Form1 screen;
            screen = new Form1();
            Application.Run(screen);
        }
    }

    public partial class Form1 : Form
    {
        Label xInputLabel = new Label();
        Label yInputLabel = new Label();
        Label maxInputLabel = new Label();
        Label scaleInputLabel = new Label();
        TextBox xInput = new TextBox();
        TextBox yInput = new TextBox();
        TextBox maxInput = new TextBox();
        TextBox scaleInput = new TextBox();
        Button okButton = new Button();
        double xValue = 0;
        double yValue = 0;
        double maxValue = 0;
        double scaleValue = 0;
        double pixVal = 0;
        double xCalc = 0;
        double yCalc = 0;
        double[,,] mArray = new double[400, 400, 1];

        public Form1()
        {
            InitializeComponent();
            BackColor = Color.FromArgb(255, 255, 255);
            Text = "Mandelbrot Figure";
            Size = new System.Drawing.Size(700, 950);
                //Messing with the xInput Box and Label
            xInput.Location = new Point(50, 50);
            xInput.Size = new Size(210, 50);
            xInput.Text = ("Please input desired X coordinate.");
            Controls.Add(xInput);
            xInputLabel.Location = new Point(46, 20);
            xInputLabel.Size = new Size(100, 40);
            xInputLabel.Text = "Middle X:";
            Controls.Add(xInputLabel);
                //Messing with the yInput Box and Label
            yInput.Location = new Point(320, 50);
            yInput.Size = new Size(210, 50);
            yInput.Text = ("Please input desired Y coordinate.");
            Controls.Add(yInput);
            yInputLabel.Location = new Point(316, 20);
            yInputLabel.Size = new Size(100, 40);
            yInputLabel.Text = "Middle Y:";
            Controls.Add(yInputLabel);
                //Messing with the maxInput Box and Label
            maxInput.Location = new Point(50, 126);
            maxInput.Size = new Size(210, 100);
            maxInput.Text = ("Please input desired max value.");
            Controls.Add(maxInput);
            maxInputLabel.Location = new Point(46, 100);
            maxInputLabel.Size = new Size(50, 40);
            maxInputLabel.Text = "Max:";
            Controls.Add(maxInputLabel);
                //Messing with the scaleInput Box and Label
            scaleInput.Location = new Point(320, 126);
            scaleInput.Size = new Size(210, 100);
            scaleInput.Text = ("Please input desired scale value.");
            Controls.Add(scaleInput);
            scaleInputLabel.Location = new Point(316, 100);
            scaleInputLabel.Size = new Size(80, 40);
            scaleInputLabel.Text = "Scale:";
            Controls.Add(scaleInputLabel);
                //Messing with the okButton
            okButton.Location = new Point(560, 49);
            okButton.Size = new Size(100, 100);
            okButton.Text = ("Start");
            Controls.Add(okButton);
            okButton.Click += CalcMandelbrot;
        }

        //Grabs data and drops it into an array
        public void CalcMandelbrot(object sender, EventArgs e)
        {
            xValue = Convert.ToDouble(xInput.Text);
            yValue = Convert.ToDouble(yInput.Text);
            maxValue = Convert.ToDouble(maxInput.Text);
            scaleValue = Convert.ToDouble(scaleInput.Text);
            pixVal = scaleValue * 0.01;
            for (double yCounter = 0; yCounter < 400; yCounter++)
            {
                yCalc = yValue + (200 * pixVal) + (yCounter * pixVal);
                for (double xCounter = 0; xCounter < 400; xCounter++)
                {
                    xCalc = xValue - (200 * pixVal) + (xCounter * pixVal);
                    mArray[Convert.ToInt32(xCounter), Convert.ToInt32(yCounter), 0] = CalcMBF(xCalc, yCalc, maxValue);
                    Console.WriteLine(xCounter + " " + yCounter + " " + " " + xCalc + " " + yCalc + " " + CalcMBF(xCalc, yCalc, maxValue));
                }
            }
        }

        public double CalcMBF(double aOut, double bOut, double maxValue)
        {
            double aWork = aOut;
            double bWork = bOut;
            double maxWork = maxValue;
            double distanceXY = 0;
            int mandelbrotNum = 0;
            for (int loopCounter = 1; loopCounter < maxWork; loopCounter++)
            {
                if (distanceXY <= 2)
                {
                    distanceXY = Math.Sqrt(Math.Pow((aWork), 2) + Math.Pow((bWork), 2));
                    mandelbrotNum = loopCounter;
                    aWork = (aWork * aWork) - (bWork * bWork) + xCalc;
                    bWork = (2 * aWork * bWork) + yCalc;
                }
                else
                {
                    aWork = 0;
                    bWork = 0;
                    break;
                }
            }
            return mandelbrotNum;
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows.Forms;
名称空间Mandelbrot_图
{
班前班
{
静态void main(字符串[]参数)
{
Form1屏幕;
screen=newform1();
应用程序运行(屏幕);
}
}
公共部分类Form1:Form
{
标签xInputLabel=新标签();
Label yInputLabel=新标签();
标签maxInputLabel=新标签();
Label scaleInputLabel=新标签();
TextBox xInput=new TextBox();
TextBox yInput=新的TextBox();
TextBox maxInput=新建TextBox();
TextBox scaleInput=new TextBox();
按钮OK按钮=新按钮();
双xValue=0;
双Y值=0;
双最大值=0;
双刻度值=0;
双pixVal=0;
双xCalc=0;
双yCalc=0;
双人房[,]mArray=新双人房[400,400,1];
公共表格1()
{
初始化组件();
BackColor=Color.FromArgb(255,255,255);
Text=“Mandelbrot图”;
尺寸=新系统图纸尺寸(700950);
//弄乱箱子和标签
xInput.Location=新点(50,50);
xInput.Size=新尺寸(210,50);
xInput.Text=(“请输入所需的X坐标。”);
控件。添加(xInput);
xInputLabel.Location=新点(46,20);
xInputLabel.Size=新尺寸(100,40);
xInputLabel.Text=“中间X:”;
控件。添加(xInputLabel);
//弄乱输入框和标签
yInput.位置=新点(320,50);
yInput.Size=新尺寸(210,50);
yInput.Text=(“请输入所需的Y坐标。”);
控件。添加(yInput);
位置=新点(316,20);
yInputLabel.Size=新尺寸(100,40);
yInputLabel.Text=“中间Y:”;
控件。添加(yInputLabel);
//弄乱了maxInput框和标签
maxInput.Location=新点(50126);
maxInput.Size=新的大小(210100);
Text=(“请输入所需的最大值。”);
控件。添加(maxInput);
maxInputLabel.Location=新点(46100);
maxInputLabel.Size=新的大小(50,40);
maxInputLabel.Text=“Max:”;
控件。添加(maxInputLabel);
//弄乱scaleInput框和标签
scaleInput.Location=新点(320126);
scaleInput.Size=新的大小(210100);
scaleInput.Text=(“请输入所需的比例值。”);
控件。添加(缩放输入);
scaleInputLabel.Location=新点(316100);
scaleInputLabel.Size=新的大小(80,40);
scaleInputLabel.Text=“缩放:”;
控件。添加(scaleInputLabel);
//弄乱按钮
确定按钮位置=新点(560,49);
OK按钮。大小=新大小(100100);
文本=(“开始”);
控件。添加(确定按钮);
确定按钮。单击+=CalcMandelbrot;
}
//获取数据并将其放入阵列中
public void CalcMandelbrot(对象发送方,事件参数e)
{
xValue=Convert.ToDouble(xInput.Text);
yValue=Convert.ToDouble(yInput.Text);
maxValue=Convert.ToDouble(maxInput.Text);
scaleValue=Convert.ToDouble(scaleInput.Text);
pixVal=scaleValue*0.01;
对于(双yCounter=0;yCounter<400;yCounter++)
{
yCalc=yValue+(200*pixVal)+(yCounter*pixVal);
对于(双xCounter=0;xCounter<400;xCounter++)
{
xCalc=xValue-(200*pixVal)+(xCounter*pixVal);
mArray[Convert.ToInt32(xCounter),Convert.ToInt32(yCounter),0]=CalcMBF(xCalc,yCalc,maxValue);
Console.WriteLine(xCounter+“”+yCounter+“”+xCalc+“”+yCalc+“”+CalcMBF(xCalc,yCalc,maxValue));
}
}
}
公共双计算流量(双aOut、双回合、双最大值)
{
双aWork=aOut;
双倍工作=回合;
double maxWork=最大值;
双距离xy=0;
int-mandelbrotNum=0;
对于(int loopCounter=1;loopCounterif(distanceXY计算起来很漂亮,只是你把实例变量和参数弄得一团糟

CalcMBF
中,它应该是:

var originala = aWork;
aWork = (aWork * aWork) - (bWork * bWork) + aOut;
bWork = (2 * originala * bWork) + bOut;
你有
xCalc
yCalc
,它们不是
CalcMBF
本地的。此外,虚部需要用aWork的初始值计算。有趣的是,它仍然适用于该bug,但它是一个吸引子


mandelbrot集在复平面的-2处有其有趣的区域,公式是z(n+1)=z(n)²+c。您的变量名没有反映这一点,很难理解迭代循环应该如何工作。我建议您分别从z和c的实部和复杂部的明确属性开始。调试类似内容的最佳方法是单步执行代码