From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Identifying a circle segment

Solved!
Go to solution

I would like to identify a circle segment by mouse click of an operator according the image below. The operator clicks a segment and the result should be the segment number. Did anybody has a solution or a clue how to do this ?.

 

CircleSegmentsInColour.vi_Front_Panel_on_RSL.lvpro_2016-06-14_15-14-32.png

 

Jörn

0 Kudos
Message 1 of 4
(2,917 Views)

Did you create the picture yourself using known mathematical formulas?

 

I'd use the mouse down event on the picture and determine the pixel coordinates of that event.  Then use them to determine using math what sector you must be in.  If you calculated the angle from mouse position to the center of the circle in the picture, you can calculate which segment you must be in.

Message 2 of 4
(2,910 Views)
Solution
Accepted by topic author joernheit

You can use Property Nodes for the Picture (right-click on Segmentkreis in the Block Diagram, choose Create Property Node).  The Position Property will give you the pixel coordinates of the upper-left corner of the Picture, and the Draw Area Size will give you the width and height of the Picture.  Now if you know the coordinates of the Mouse, you can express this in polar coordinates relative to the center of the Picture.  If the Radius shows that the Mouse is "within the wheel", you can use the angular argument to determine in which segment you are.  Note that your code has Segments and Start Angle as parameters, so your "Where's the Mouse?" sub-VI will need to know these values, as well.

 

Bob "It's only Math" Schor

 

P.S. -- of interest is that you created a Picture with a Bounding Rectangle of 0, 0 and 500, 500.  As expected, the Origin property for the Picture is 0, 0.  Not so expected is that the Draw Area Size is 498, 498, as though the outer-most pixels are not part of the Draw Area.  A minor detail, but it may result in an "off-by-one" error when you try to calculate the center point.

 

Moral of the Story -- write some code and test cases, do some experimentation to be sure you understand how things like Properties work.

Message 3 of 4
(2,881 Views)

Ravens Fan tossed me in the right direction and Bob_schor explicitly formulated the code I implemented and indeed the little offset could play a role. The solution is as follows.

 

CircleSegmentsInColour_MouseIdentSegment.vi_Front__2016-06-14_17-38-49.png

 

Maybe the solution is of some interest for anyone.

 

Thanks a lot to both of you !.

 

Jörn

Message 4 of 4
(2,865 Views)