[Solved] Checking if the point is within the area ! lazarus / 39-Graphics ---------------------------------------------------------------------- loaded · 2021-07-17 08:06 Hi All, The code in the https://forum.lazarus.freepascal.org/index.php?topic=42826.0 link that checks whether the point is within the field; Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function PointInPolygon(Point: TPoint; const Polygon: array of TPoint): Boolean;var  rgn: HRGN;begin  rgn := CreatePolygonRgn(Polygon[0], Length(Polygon), WINDING);  Result := PtInRegion(rgn, Point.X, Point.Y);  DeleteObject(rgn);end;It works on windows, but on android, it gives an error on the CreatePolygonRgn line. The code in the https://wiki.freepascal.org/Geometry_in_Pascal link that I can use as an alternative is; Android works but gives wrong result for some situations. Is there an alternative code that I can use instead? Or will I have to roll up my sleeves and write it myself ? I would be glad if you help. ---------------------------------------------------------------------- winni · 2021-07-17 10:06 Hi! Much faster as the example from the link "Geometry in Pascal" is this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function PointInPoly(p : TPointF; const poly :  array of TPointF) : Boolean;var i,k : integer; begin result := false; k := High(poly); For i := 0 to high(poly) do begin  if (     ( ((poly[i].y <= p.y) and (p.y < poly[k].y)) or ((poly[k].y <= p.y)           and (p.y < poly[i].y)) ) and          (p.x < ((poly[k].x - poly[i].x) * (p.y - poly[i].y) /           (poly[k].y - poly[i].y) + poly[i].x) )     ) then result := not result;  k := i end;end;  As you need it for Points with integer coordinates change * TPointF to TPoint * array of TPointF to array of TPoint As the fpc still does not accept arrays for inlining this function cannot be inlined. Winni ---------------------------------------------------------------------- loaded · 2021-07-17 11:52 winnie, thank you very much. The codes worked fine on Android. When you find an expert like you in graphics; There is another issue I would like to ask in line with the phrase "Since,then, the One Who creates knows, surely the One Who knows will speak."; I have geometric problems such as the closest point of the point to the line and the lines that cut the area, and I have very unstable solutions for them. Do you have a clear resource recommendation on the subject? ---------------------------------------------------------------------- marcov · 2021-07-17 13:21 Quote from: winni on July 17, 2021, 12:06:20 pmAs the fpc still does not accept arrays for inlining this function cannot be inlined. (such a complex routine wouldn't improve much, performance wise when inlining anyway) ---------------------------------------------------------------------- Seenkao · 2021-08-02 22:20 Думаю вам нужно посмотреть в сторону игр. Вам нужны математические решения. Многие из них уже давно сделаны. Для вашего решения (как я понимаю) сильно не надо работать с графикой в данный момент времени. Все решения сделаны очень давно, но ими надо уметь пользоваться. Думаю сложно рекомендовать даже что-то. Посмотрите решения в других программах, других модулях. Желательно в игровых или тесно связанных с играми. Google translate: I think you need to look towards games. You need mathematical solutions. Many of them have been made long ago. For your solution (as I understand it), you don't really need to work with graphics at this point in time. All decisions were made a long time ago, but you need to know how to use them. I think it's hard to recommend even something. Look for solutions in other programs, other modules. Preferably in gaming or closely related to them. ---------------------------------------------------------------------- loaded · 2021-08-03 05:22 Thank you Seenkao for the reply. Thanks to winni, his solution works number ten. ---------------------------------------------------------------------- avra · 2021-08-03 08:25 Quote from: Seenkao on August 03, 2021, 12:20:32 amYou need mathematical solutions. Many of them have been made long ago.One of the oldest ways to determine if a point is inside of an irregular polygon, was to draw a line through that point and count intersection points between line and polygon (starting from the point towards outside of the polygon). If number of intersetion points was odd - then point is inside the polygon. If even - point is outside. ---------------------------------------------------------------------- winni · 2021-08-03 09:04 @avra That is exactly what my shown code does. Winni ---------------------------------------------------------------------- avra · 2021-08-03 13:56 Quote from: winni on August 03, 2021, 11:04:49 amThat is exactly what my shown code does. ---------------------------------------------------------------------- loaded · 2021-08-03 14:52 Quote from: winni on August 03, 2021, 11:04:49 amThat is exactly what my shown code does. thanks winni, your code works at work on android.   https://youtu.be/7mdN6wz_lK8