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
(4,172 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
(4,170 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
(4,166 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
(4,160 Views)

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

0 Kudos
Message 5 of 16
(4,155 Views)
0 Kudos
Message 6 of 16
(4,152 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
(4,146 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
(4,141 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
(4,134 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
(4,129 Views)