ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Snap to closest graph point

Solved!
Go to solution

I have an xy graph with multiple points. The graph is controlled by a mouse down event, when the user clicks on the graph it draws a red circle at the click point. My question is how I would get this to snap to the nearest point?

----------------------------------------------------------------------------------
I have not lost my mind, it's backed up on a disk somewhere
0 Kudos
Message 1 of 16
(5,961 Views)

Hi Paul,

 

I would look for the nearest plot data using Pythagoras formula c²=b²+a²…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 16
(5,959 Views)

What is the datatype of the xy graph? If you use complex numbers (recommended!), convert the click point to a complex point in the data scale, subtract it from the complex array of points, take the absolute value, and use array min&max. The index of the min is the index of the closest point.

 

Can you attach your VI?

0 Kudos
Message 3 of 16
(5,955 Views)

Please see my attached VI

----------------------------------------------------------------------------------
I have not lost my mind, it's backed up on a disk somewhere
0 Kudos
Message 4 of 16
(5,949 Views)

That's just a subVI, there is no xy graph. Also your subVI is missing.

0 Kudos
Message 5 of 16
(5,944 Views)
0 Kudos
Message 6 of 16
(5,941 Views)

Here's what I had in mind.

 

(just showing how to find the closest point. Now simply tranform the value back to pixel coordinates and draw the circle. Not shown.)

 

0 Kudos
Message 7 of 16
(5,935 Views)

Sorry about that please see attached the updated VI

----------------------------------------------------------------------------------
I have not lost my mind, it's backed up on a disk somewhere
0 Kudos
Message 8 of 16
(5,930 Views)

You shold be able to use my code with minimal changes. As I said, simply transform the position of the closest point back to pixels and draw the circle.

0 Kudos
Message 9 of 16
(5,923 Views)

I have tried implementing your method but I am not having much luck?

----------------------------------------------------------------------------------
I have not lost my mind, it's backed up on a disk somewhere
0 Kudos
Message 10 of 16
(5,918 Views)