Параметрическое уравнение для круга с центром в начале координат и радиусе r
имеет вид x = r \times sin(\theta)
y = r \times cos(\theta)
где \theta \in [0,2\pi]
.
Для спирали радиус увеличивается с \ $ \ theta \ $. Предполагая, что \ $ r \ $ опирается на \theta
как r = (a+b\theta)
, это может быть, x = (a+b\theta) sin(\theta)
y = (a+b\theta) cos(\theta)
Чтобы это была 3D фигура с вертикальной осью, вы можете добавить z
в linspace(0, L)
где L
- длина цилиндра.
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import math
import numpy as np
L = 50
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
xpoints=[]
ypoints=[]
a = 0.1
b = 0.1
for theta in np.linspace(0, 2*math.pi, 20):
xpoints.append((a+b*theta)*math.cos(theta))
ypoints.append((a+b*theta)*theta*math.sin(theta))
z = np.linspace(0,L)
theta, z = np.meshgrid(theta, z)
ax.plot_surface(xpoints,ypoints,z)
plt.show()
Так как у вас есть рабочий код, вы можете опубликовать его в обзоре кода Stack Exchange, где я могу объяснить с помощью набранной математики.
Очевидно,
class Int32Util
{
public static bool TryParse(string value, out int result)
{
result = 0;
try
{
result = Int32.Parse(value);
return true;
}
catch(FormatException)
{
return false;
}
catch(OverflowException)
{
return false;
}
}
}
try
{
var i = int.Parse(value);
}
catch(FormatException ex)
{
Console.WriteLine("Invalid format.");
}