【问题标题】:How to draw quarter circle curves in python如何在python中绘制四分之一圆曲线
【发布时间】:2019-09-23 13:27:13
【问题描述】:

我想为我的程序绘制红色的这个 4 花瓣单元:

我需要能够分别绘制每条曲线,以便我可以将它们加粗以使粗体白色图案显示在图片中。

我正在考虑将我的原点坐标放在中心,并围绕点画 8 个四分之一圆。

希望我只有 1 个函数,四分之一圆,并且可以重复那个函数(例如,将其镜像到 y 轴上)以生成所有 8 个函数。

但是,我无法使用 Tkinter 或 matlab 来做到这一点。

使用 Tkinter,我一次只能绘制一条弧线(带有额外的线)。

Tkinter 代码:

import tkinter as tk

root = tk.Tk()
canvas = tk.Canvas(root, width=300, height=200, bg='black')
canvas.pack(fill="both", expand=True)

canvas.create_arc(100, 100, 200, 200, start=0, extent=90, outline="white",style="pieslice")

root.mainloop()

使用 Matlab,我只能通过最小化图形大小来制作“四分之一圆”,因此它只显示我想要的窗口:

import math
import matplotlib.pyplot as plt

plt.figure()
xlist = np.linspace(0, 1.0, 100) # only in quadrant I
ylist = np.linspace(0, 1.0, 100)
X,Y = np.meshgrid(xlist, ylist)
F = X**2 + Y**2 - 1  #  'Circle Equation
plt.contour(X, Y, F, [0], colors = 'k', linestyles = 'solid')
plt.axes().set_aspect('equal')
plt.show()

任何帮助将不胜感激。

【问题讨论】:

    标签: python matlab canvas tkinter graphing


    【解决方案1】:

    我做到了, 使用 style = "arc" 代替 pieslice 并绘制 4 个半圆

    import tkinter as tk
    
    root = tk.Tk()
    canvas = tk.Canvas(root, width=300, height=200, bg='black')
    canvas.pack(fill="both", expand=True)
    
    canvas.create_arc(100, 0, 200, 100, start=0, extent=-180, outline="white", style="arc")
    canvas.create_arc(100, 100, 200, 200, start=0, extent=180, outline="white", style="arc")
    canvas.create_arc(150, 50, 250, 150, start=90, extent=180, outline="white", style="arc")
    canvas.create_arc(50, 50, 150, 150, start=90, extent=-180, outline="white", style="arc")
    
    root.mainloop()
    

    【讨论】:

      【解决方案2】:

      您展示的图案基本是顺时针旋转 90 度的 4 个半圆。 您可以通过为方程 x^2 + y^2 - 1 设置一个限制来绘制一个半圆,使其产生一个半圆。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-20
        • 1970-01-01
        • 2014-09-20
        • 2013-03-31
        • 1970-01-01
        相关资源
        最近更新 更多