Menu

X-Y coordinate in mglGraphZB to (x,y) in plot

Help
2010-02-06
2012-10-16
  • AnotherUser

    AnotherUser - 2010-02-06

    Hi,

    I'm looking to make an interactive plot using mglGraphZB, where I want to
    convert the co-ordinates of the x-y pixel in the drawn graph to the co-
    ordinates in the plot (which i then use to adjust the axes). Is there a way to
    do this at this time? Currently I am doing this (badly) with my own distance
    computations

     
  • Alexey Balakin

    Alexey Balakin - 2010-02-06

    Yes, you can use CalcXYZ() function. Also you can look on CalcScr() function
    for inverse procedure.

     
  • Alexey Balakin

    Alexey Balakin - 2010-02-07

    Also you can use mglGraphAB::ObjID and array mglGraphAB::OI. First one set
    some unique ID for plot (by ObjID). Second one give this ID for screen point
    (OI is the array with sizes width*height -- the same as returned by GetBits()
    ).

    For example, at plotting stage:

    for(int i=0;i<N;i++)
    {
      gr->ObjID=i+1; // zero is used by default so, lets avoid it
      gr->Plot( a[i] );
    }
    gr->ObjID=0; // in opposite case all later graphics will have last ObjID
    

    Now you can check the which curve is lied under mouse (supposing x,y lie
    inside the picture):

    int id = gr->OI[x+gr->GetWidth()*y];
    if(id) printf("Curve %d",id-1);
    
     

Log in to post a comment.