我需要让椭圆绕一个圆来制作一朵花,我已经非常接近解决方案,但我不知道如何解决它,它穿过圆,有什么方法可以制作椭圆更短+绕一圈?
这是代码:
pkg load geometry
clf
figure;
t=0:0.01:2*pi;
x=10*cos(t);
y=3*sin(t)/2;
for i=1:12
hold on;
q=[x;y];
e=pi/12*i;
z=[cos(e) -sin(e);sin(e) cos(e)];
k=z*q;
r=k(1,:);
d=k(2,:);
plot(r,d);
axis square;
pause(1);
endfor
hold on;
drawCircle(0,0,1);
这就是我的样子:
这就是它应该的样子:
您还需要圈出椭圆的中心,它们现在都以原点为中心。这意味着,添加静态偏移。类似的东西
dist = 1; % Distance from the origin, change as necessary
x_Offset = dist * cos(e);
y_Offset = dist * sin(e);
plot(r + x_Offset, d + y_Offset);
我尝试了这个,我发现这里有一些东西可以绘制预期的图表
import matplotlib.pyplot as plt
import numpy as np
def draw_flower():
# Create a circular center
center_theta = np.linspace(0, 2*np.pi, 100)
x_center = 0.4 * np.cos(center_theta) # Adjust the radius as necessary
y_center = 0.4 * np.sin(center_theta) # Adjust the radius as necessary
# Plot the circular center
plt.plot(x_center, y_center, color='blue', label='Center Circle')
# Create a circle
theta = np.linspace(0, 2*np.pi, 100)
x_circle = np.cos(theta)
y_circle = np.sin(theta) / 4
# Plot the outer circle
#plt.plot(x_circle, y_circle, color='black', label='Outer Circle')
# Plot vertically aligned ellipses around the circle
num_petals = 12
for i in range(num_petals):
angle = i * (2 * np.pi / num_petals)
dist = 1.55 # Adjust this distance as necessary
x_offset = dist * np.cos(angle)
y_offset = dist * np.sin(angle)
# Ellipse parameters
a = 0.4
b = 0.8
# Create rotated ellipse
x_ellipse = x_circle * np.cos(angle) - y_circle * np.sin(angle) + x_offset
y_ellipse = x_circle * np.sin(angle) + y_circle * np.cos(angle) + y_offset
# Plot the ellipse
plt.plot(x_ellipse, y_ellipse, label=f'Ellipse {i + 1}')
plt.axis('equal')
plt.title('Flower Plot')
plt.legend()
plt.show()
# Call the function to draw the flower
draw_flower()