Menu

Can MathGL draw a circle(-segment)?

Help
SImon
2012-03-21
2012-10-16
  • SImon

    SImon - 2012-03-21

    Maybe a stupid question, but:

    can MathGL draw a simple circle-part in a Cartesian plot? Or should I use y =
    sqrt( r - x^2 ).

    Thanks ;)

     
  • Alexey Balakin

    Alexey Balakin - 2012-03-22

    Easily, just use this code

    float phi1=M_PI/4, phi2=M_PI, phi;
    mglData x(30), y(30);
    for(int i=0;i<30;i++)
    { phi=phi1+(phi2-phi1)*i/29.;  x.a[i]=cos(phi);  y.a[i]=sin(phi);  }
    gr->Plot(x,y);
    

    or you can do the same using textual formulas

    gr->Plot("cos(pi/4+(pi-pi/4)*t)", "cos(pi/4+(pi-pi/4)*t)","0");
    
     
  • SImon

    SImon - 2012-03-22

    Of course! :D

    Thank you!

     

Log in to post a comment.