用了三天基於TouchVG和muParser實現了iOS上的函數圖像繪圖,繪圖代碼(跨平臺)如下:
static bool setExpr(MgShape *sp, const char* expr, float mint, float maxt, float step) {
return ((MgFuncShape*)sp->shape())->setExpr(expr, mint, maxt, step);
}
static void createFuncShapes(MgView *view) {
MgShape *sp = view->createShapeCtx(MgFuncShape::Type());
setExpr(sp, "10*t,10*ln(t*t+1)*sin(t)", -6, 6, 0.1f);
view->shapes()->addShapeDirect(sp);
sp = view->createShapeCtx(MgFuncShape::Type());
setExpr(sp, "10*t,10*exp(t)-t*sin(t)*cos(t)", -6, 6, 0.1f);
view->shapes()->addShapeDirect(sp);
view->setCommand("line", "{'points':[-70,0,70,0,0,-40,0,40]}");
}
繪圖效果:
公式來源:
心形圖:20*(sqrt(cos(t))*cos(200*t)+sqrt(abs(t))-0.7)*(4-t*t)^0.01,20*t