Python中的Epitrocoid未给出正确的绘图

Python中的Epitrocoid未给出正确的绘图,python,c#,matplotlib,Python,C#,Matplotlib,我用C编写了以下代码: using System; using System.Drawing; using ZedGraph; namespace _1_12_Epitrocoid { class Epitrocoid { double A = 1.0; double a = 0.4; double λ = 1.4; public double X(double ϕ) {

我用C编写了以下代码:

using System;
using System.Drawing;
using ZedGraph;

namespace _1_12_Epitrocoid
{
    class Epitrocoid
    {
        double A = 1.0;
        double a = 0.4;
        double λ = 1.4;

        public double X(double ϕ)
        {
            return (A + a) * Math.Cos(ϕ) - λ * a * Math.Cos(((A + a) / a) * ϕ);
        }

        public double Y(double ϕ)
        {
            return (A + a) * Math.Sin(ϕ) - λ * a * Math.Sin(((A + a) / a) * ϕ);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Epitrocoid e = new Epitrocoid();

            PointPairList list = new PointPairList();

            for (double ϕ = 0; ϕ < 10; ϕ += 0.01)
            {
                double x = e.X(ϕ);
                double y = e.Y(ϕ);

                list.Add(x, y);
            }

            PlotForm f = new PlotForm("Epitrocoid");
            f.Add(list, "Epitrocoid", Color.Black);
            f.AxisChange();
            f.ShowDialog();

            Console.ReadLine();
        }
    }
}

有人能告诉我这里出了什么问题吗?

在Python中,在phi=1之前,您没有像在C中,在phi=10之前一样构造迭代器

使用正确的phi可以帮助您实现Python。另外,使用numpy可以简化很多事情

进口numpy 从matplotlib导入pyplot A=1.0; a=0.4; λ = 1.4; def Xñ: 返回A+A*numpy.cosñ-λ*A*numpy.cosA+A/A*ñ; def Yñ: 返回A+A*numpy.sinñ-λ*A*numpy.sinA+A/A*ñ; ν=numpy.arange0,10,0.01 x=xа y=yа 图,ax=pyplot.subPlot x.x,y ax.set_aspect'equal'
弧度vs度?oh-1000/1000=1。在C中你得了10分。也可以用numpy来代替数学,这样你就不需要循环了,你只需要用1来代替10,把1001改为110001@Mntfr,我实际上使用了你的解决方案。我不允许使用NumPy。@user366312。这很奇怪,它是matplotlib的一个依赖项。如果没有numpy,您的代码很好,您只需要一直循环到phi=10
import math
import matplotlib.pyplot as plt 

A = 1.0;
a = 0.4;
λ = 1.4;

def X(ϕ):
    return (A + a) * math.cos(ϕ) - λ * a * math.cos(((A + a) / a) * ϕ);

def Y(ϕ):
    return (A + a) * math.sin(ϕ) - λ * a * math.sin(((A + a) / a) * ϕ);


x_list = []
y_list = []


for i in range(0, 1001, 1):
    ϕ = i / 1000.0
    x_list.append(X(ϕ))
    y_list.append(Y(ϕ))

print(len(x_list))
print(len(y_list))

plt.plot(x_list, y_list)