Page 1 of 1

CoordToValue ViewSmith Issue

Posted: Tue Apr 25, 2017 4:22 pm
by lokesh
Hi,
I was trying to figure out some points from Smith chart and following is my code:

Code: Select all

      private void LcuBitmapContour_MouseMove(object sender, MouseEventArgs e)
      {
         var vals = lcuBitmapContour.ViewSmith.Axis.CoordToValue(new PointFloat(Cursor.Position.X, Cursor.Position.Y));
         lblBitmap.Text = $"{vals.RealValue}, {vals.ImgValue}";
      }
The code works fine except that the data I get from CoordToValue() might be giving me wrong values and returns different values when I keep my test application at different places or when maximized.

When the window is at around middle left of the screen:
issue 1.png
issue 1.png (21.74 KiB) Viewed 7533 times
When the window is maximized:
issue 2.jpg
issue 2.jpg (127.17 KiB) Viewed 7533 times
The red dot represents the mouse position with a small precision error
My axis reference value is set to 1.
Is there something that I am doing wrong?

Thanks.

Regards,
Lokesh

Re: CoordToValue ViewSmith Issue

Posted: Thu Apr 27, 2017 10:33 am
by ArctionKestutis
Hi Lokesh,

The CoordToValue method return absolute Real/Imaginary value pair (as written in description). From the image it looks like you are using 'Normalized scale'. You need to do conversion. Something like following will work for both scales:

Code: Select all

            PointSmith vals = _chart.ViewSmith.Axis.CoordToValue(new PointFloat(e.X, e.Y), false);
       
            if (_chart.ViewSmith.Axis.ShowAbsoluteValues == false)
            {
                vals.RealValue /= _chart.ViewSmith.Axis.ReferenceValue;
                vals.ImgValue /= _chart.ViewSmith.Axis.ReferenceValue;
            }

All the best,
Kestutis

Re: CoordToValue ViewSmith Issue

Posted: Thu Apr 27, 2017 1:53 pm
by lokesh
Hi Dr.,
Thanks for the reply.
As I mentioned, my reference value is set to 1.

Plus, I noted that (in a different scenario), if I get the reference point using ValueToCoord and add an offset and then plot it using CoordToValue, it plots correctly irrespective of position and size of window which is what is expected.
I am a bit confused here.

Thanks again.

Lokesh

Re: CoordToValue ViewSmith Issue

Posted: Thu Apr 27, 2017 2:45 pm
by ArctionKestutis
I was testing with latest v7.2.6.1 and latest v8.
I used _chart.MouseDoubleClick event in WinForms.
I still see correct values independent of Chart size and location.
If you need help in debugging, please send you app for testing to Arction support email.

All the best.

Re: CoordToValue ViewSmith Issue

Posted: Fri Apr 28, 2017 10:24 am
by ArctionKestutis
The Cursor.Position property gives you absolute screen coordinates (relatively to top-left monitor corner). For usage in LightningChart you need screen coordinates relatively to Chart’s top-left corner.
MouseMove event handler argument MouseEventArgs gives you correct coordinates to be used in LightningChart. Replace line

Code: Select all

      private void LcuBitmapContour_MouseMove(object sender, MouseEventArgs e)
      {
         var vals = lcuBitmapContour.ViewSmith.Axis.CoordToValue(new PointFloat(e.X, e.Y), false);
         lblBitmap.Text = $"{vals.RealValue}, {vals.ImgValue}";
      }
and everything will be just fine.