基于TouchVG和muParser实现了函数图像绘图

用了三天基于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]}");
}

绘图效果:

func

公式来源:

心形图:20*(sqrt(cos(t))*cos(200*t)+sqrt(abs(t))-0.7)*(4-t*t)^0.01,20*t

你可能感兴趣的:(基于TouchVG和muParser实现了函数图像绘图)