I have attached
- the main script "Pixelize_Collimator_Aperture_v4.m"
- the funcions called by the script "CollimatorGrid_v3.m", "curveintersect.m"
- the coordinates of the closed curve that causes the problem "26-Jul-2018_A170258" in text format
- the picture showing the problem on the attached curve "A170258.jpg"
- the function I downloaded from FEX that find curves intersections "curveintersect.m"
To run the code, please do the following:
- run "Pixelize_Collimator_Aperture_v4.m"
- upon promp select the folder containing the curve "26-Jul-2018_A170258.txt"
- upon prompt click on the curve file name "26-Jul-2018_A170257.txt"
- upon prompt enter 1 for the number of nodes (of the Grid) per unit square area. This data can be any positive number (not necessaily integer). If there are too many points per unit square area then it becomes hard to see what is going on.
- the program will stop on line 155 of script "Pixelize_Collimator_Aprture_v4.m"
Given a closed 2D arbitrary curve, the program builds a grid over the curve bounding box. The goal is to approximate the area inclosed by the curve with square pixels whose side is sqrt(#nodes per square area). The goal is to keep the pixels that
- are totally inside the closed area
- intersect the curve on more than one point
- double the resolution only of the pixels that intersect the curve in more than one
- repeat steps 1. and 2. on the new smaller pixels in order to better approximate the area
The logic of my script is wrong as it would keep a pixel (yellow in the attached picture) that is totally outside the closed curve but only has the upper left corner on the curve. This corner coordinates are printed on the picture and coincide with one of the 4 points making up the pixel as printed by the script.
I wrongly toughts that MatLab function "inpolygon" would separate the points inside a curve from the points on the curve. Instead this is returns as "inside" a point which is on the curve.
I use the contributed function "curveintersect" as a double-check. Luckily, as it helped me detect my error.
********* Question *********
In order to find the pixels that intersect the curve on more than one pont may I totally rely on function "curveintersect"?
Actually, I still have to use fynction "inpolygon" to keep the pixels totally inside the closed area. Whereas I will generate 4 smaller pixels from each original pixel that intesect the curve.
Thank you in advance for any help and/or suggestion.