Find visual center of contour/polygon


#41

Thank you. But did you measured the probes and the time to find the point with precision of 0.1? I wonder how fast is compiled c++ code.


#42

takes about 0.8 secs to do it 10,000 times @ 0.1 prec on that shape, i removed the debug code though :frowning:


#43

Why do you need so high precision? It doesn’t make sense to be lower than a half of the length to the closest edge… I guess.


#44

Thank you.

Just for testing. There is not a big difference. On this image the yellow point is found with precision=1, the red point is found with precision=0.1. The closest vert to the yellow point is at 1.25 units, the closest vert to the red point is at 1.43 units.
2021-10-15%2011_16_53


#45

Here is my example.
All shapes have different position, rotation, mirror, scale… but the algorithm finds exactly the same relative point. The precision is the half of maximum distance of “the most promising cell”

BTW. It takes ~1-2 msec per shape using MXS version


#46

Do you redefine the precision every time when the cells are sorted, or you set the precision after the first sort(outside of the while loop)?


#47

I set it once after getting all cells…

Try another one.
we do:
h = cellSize/2.0
change it to:
h = cellSize/8.0
for example, and set precision to something very high like FLT_MAX

I have the same result but much faster


#48

The time is 0, the result is the same. :slight_smile:


#49

are you happy now? :wink:


#50

Yep. :slight_smile:

Maybe I am doing something wrong. Again. :slight_smile:
When I set the precision to 100 000 and h = cellSize/2.0 I get the same results - time is 0, the point is at the same position.


#51

It depends on the geometry of the contour. In your case, you have very long and very short segments at the same time. This makes the loop step quite tiny.


#52

And this is also interesting. The lasts shape which I posted above, where the time for the js version was:
precision:0.1 time:56803 heap:80946052L

Now it takes:
precision:100000 time:0 heap:68L

The point is the same.


#53

I think we should forget about precision and only use a smaller step. Try to do more experiments with different geometry


#54

No! I was wrong. For different geometries it doesn’t work. So, we have to find right precision, and use 1/2


#55


Best Distance for very high precision is very close to the precision of 0.1, not only for this shape.


#56

try this:

#(
[192.554,-170.634,0], [208.145,-203.765,0], [255.893,-194.995,0], 
[259.791,-149.683,0], [250.046,-104.371,0], [304.128,-110.705,0], 
[328.002,-99.012,0], [289.999,-65.8808,0], [272.459,-76.5997,0], 
[239.327,-89.7548,0], [218.377,-104.859,0], [233.481,-140.913,0], 
[244.687,-164.787,0], [223.249,-164.787,0], [210.094,-128.733,0], 
[123.855,-160.402,0], [123.368,-203.765,0], [192.554,-170.634,0]
)

i have very different results for different precision:

image


#57


#58

Here is the shape:
Polylabel_03.fbx (91.8 KB)