1. 阿基米德螺线
阿基米德螺线的极坐标方程为:
r=a+bθ
其中:
- r 是螺旋线上点到原点的距离(径向距离),
- θ 是点的角度,
- a 是起始半径(当 θ=0 时的半径),
- b 是螺旋线的扩展系数或密度系数。
2. 代码
#include <QtWidgets>
class ArchimedeanSpiralWidget : public QWidget
{
public:
ArchimedeanSpiralWidget(QWidget *parent = nullptr) : QWidget(parent) {}
protected:
void paintEvent(QPaintEvent *event) override
{
Q_UNUSED(event);
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
int centerX = width() / 2;
int centerY = height() / 2;
int numPoints = 10000;
qreal a = 1; // 起始半径
qreal b = 2; // 扩展系数
painter.translate(centerX, centerY); // 将坐标系原点移到窗口中心