齿轮渐开线方程及绘制
齿轮轮齿轮廓是一个渐开线方程,当一根绳子绕紧一个圆拉直了端部旋转,则绳子端部画出的曲线就是一个螺旋状的渐开线,方程如下,渐开线齿之间啮合传动能保持恒定传动比,传动平稳等特性。
QPointF involute(float r, float s)
{
float x=r*cos(s) + r*s*sin(s);
float y=r*sin(s) - r*s*cos(s);
return QPointF(x,y);
}
下面还是用QPainter将曲线离散为多段线进行可视化。demo是用c4droid编译的apk放到蓝奏上面
我用蓝奏浏览器分享了[curvetest01], 下载链接:https://wwp.lanzoup.com/iTE2A12mp58j 提取码 : 8mok, 你可以不限速下载哦
#include <QApplication>
#include <QLabel>
#include <QWidget>
#include <QPainter>
#include <QTimer>
#include <QMouseEvent>
#include<vector>
#define _USE_MATH_DEFINES
#include <math.h>
float deg2rad(float si)
{
return (si*M_PI)/180.0;
}
QPointF involute(float r, float s)
{
float x=r*cos(s) + r*s*sin(s);
float y=r*sin(s) - r*s*cos(s);
return QPointF(x,y);
}
void createInvoNodes(float cx,float cy,float r, int n, float ds, std::vector<QPointF>& polyline)
{
for(int i=0;i<n;i++)
{
float s=float(i)*ds;
QPointF v=involute(r,s);
QPointF revv=QPointF(cx+v.x(),cy-v.y());
polyline.push_back(revv);
}
}
class GrphWidget : public QWidget
{
//Q_OBJECT
public:
std::vector<QPointF> _invoNodes;
GrphWidget(QWidget *parent = 0):
QWidget(parent)
{
}
~GrphWidget()
{}
void mousePressEvent(QMouseEvent *event)
{
}
void paintEvent(QPaintEvent* event)
{
int w =this->width();
int h = this->height();
float cx=w*0.5;
float cy=h*0.5;
float r=200.0;
if (_invoNodes.empty())
{
createInvoNodes(cx, cy,r,100,deg2rad(2.0), _invoNodes);
}
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
// draw axis
p.setPen(QPen(Qt::black, 2));
p.drawLine( 0,h/2,w, h/2 );
p.drawLine( w/2,0,w/2, h );
// draw circle
p.setPen(QPen(Qt::red, 4));
p.drawEllipse(cx-r,cy-r,2*r,2*r);
// draw involute
p.setPen(QPen(Qt::blue, 4));
p.drawPolyline(_invoNodes.data(), _invoNodes.size());
//p.drawText(30,50,std::to_string(_invoNodes.size()).data());
p.end();
}
};
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
GrphWidget* wgt=new GrphWidget;
wgt->show();
return app.exec();
}