tag:blogger.com,1999:blog-8152247234598992686.post33880210096363411..comments2020-10-02T07:51:12.833-07:00Comments on Totologic: Accurate point in triangle testLogichttp://www.blogger.com/profile/10024617997824703986noreply@blogger.comBlogger40125tag:blogger.com,1999:blog-8152247234598992686.post-22043367256185776512020-10-02T07:51:12.833-07:002020-10-02T07:51:12.833-07:00Much appreciated, thank you.
A small improvement ...Much appreciated, thank you.<br /><br />A small improvement to distanceSquarePointToSegment is as follows. We can take advantage of the fact that p1_p2_squareLength is non-negative, hence we can defer dividing the dot product with it until it is certainly necessary. Code is below.<br /><br /><br />function distanceSquarePointToSegment(x1, y1, x2, y2, x, y:Number):Number<br />{<br /> var p1_p2_squareLength:Number = (x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1);<br /> var dotProduct:Number = ((x - x1)*(x2 - x1) + (y - y1)*(y2 - y1));<br /> if ( dotProduct < 0 )<br /> {<br /> return (x - x1)*(x - x1) + (y - y1)*(y - y1);<br /> }<br /> else if ( dotProduct <= p1_p2_squareLength )<br /> {<br /> var p_p1_squareLength:Number = (x1 - x)*(x1 - x) + (y1 - y)*(y1 - y);<br /> return p_p1_squareLength - dotProduct * dotProduct / p1_p2_squareLength;<br /> }<br /> else<br /> {<br /> return (x - x2)*(x - x2) + (y - y2)*(y - y2);<br /> }<br />}MLhttps://www.blogger.com/profile/14827104873979998364noreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-20276502692677785062020-05-17T15:21:37.800-07:002020-05-17T15:21:37.800-07:00Double wow! Kudos for you. I ported it in C and cr...Double wow! Kudos for you. I ported it in C and created a gist with FULL credit to you.<br />Thank you!<br />https://gist.github.com/dam2k/960ecac776c506a9f3474d4e467969b5dAm2Khttps://www.blogger.com/profile/09469122269866576182noreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-66860662289411260882019-03-29T06:09:36.770-07:002019-03-29T06:09:36.770-07:00It is appreciated! Thanks :)It is appreciated! Thanks :)César Andrés Polindarahttps://www.blogger.com/profile/03126881200059799099noreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-48872822027512556852017-10-20T23:25:29.307-07:002017-10-20T23:25:29.307-07:00This comment has been removed by the author.Mark Szlazakhttps://www.blogger.com/profile/15359238216464029620noreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-1141228591464630142017-10-20T23:05:40.491-07:002017-10-20T23:05:40.491-07:00This comment has been removed by the author.Mark Szlazakhttps://www.blogger.com/profile/15359238216464029620noreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-1688800052230944712017-08-07T23:46:23.794-07:002017-08-07T23:46:23.794-07:00Oops, to be much easy to verify; I updated the coo...Oops, to be much easy to verify; I updated the coordinate of Point P as below:<br />Point P = (MinX, MinY)<br /><br />Thus, P = (834186.3789, 820799.625)<br /><br />As long as P now is intercept point to hit edge AC, it should inside the triangle ABC.<br /><br />but still, with the logic mentioned on the above, it return a false.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-27703579595468248682017-08-07T23:36:03.528-07:002017-08-07T23:36:03.528-07:00Dear Sir/Madam,
Hi, I am new to this topic, I hav...Dear Sir/Madam,<br /><br />Hi, I am new to this topic, I have tried your code but I cant get the expected result, below is some of the information:<br /><br />It is given that, I have the following coordinates:<br />MinX = (834186.3789)<br />MinY = (820799.625)<br />MaxX = (834910.8751)<br />MaxY = (821412.6876)<br /><br />Point A = (MaxX, 0)<br />Point B = (MinX, 0)<br />Point C = (0, MaxY)<br /><br />Point P = (834620, 821059)<br /><br />And form a Triangle ABC <br /><br />You can find that,the range of Px is between Ax and Bx; And Py is less than MaxY, thus, I expect that Point P should be in the Triangle ABC.<br /><br />but with the work it done; The program on the above return FALSE; which is not as expected.<br /><br />Can you please help me to have a look, is there any I misunderstood or misused your code?<br /><br />Many Thanks.<br /> Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-45923899756211647782017-04-03T19:33:32.351-07:002017-04-03T19:33:32.351-07:00Unfortunately it doesn't work on a sphere. If ...Unfortunately it doesn't work on a sphere. If you flatten your local geometry to fit an euclidean 2D space, your triangle will be made from curves, that makes things a bit more complicated.Logichttps://www.blogger.com/profile/10024617997824703986noreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-57374614895514248292017-03-30T02:40:33.750-07:002017-03-30T02:40:33.750-07:00Hi!
Excellent article!
Will this work with lat,lng...Hi!<br />Excellent article!<br />Will this work with lat,lng coordinates (of earth, assuming perfect sphere)?Anonymoushttps://www.blogger.com/profile/12766366566010072079noreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-34815497818819442822017-03-30T02:39:32.431-07:002017-03-30T02:39:32.431-07:00This comment has been removed by the author.Anonymoushttps://www.blogger.com/profile/12766366566010072079noreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-34981296615419827192017-01-15T03:30:43.398-08:002017-01-15T03:30:43.398-08:00Hi.
You must "translate" my AS3 code in...Hi.<br /><br />You must "translate" my AS3 code into IDL code.<br /><br />It is not difficult because my code only use basic features (variable, function, if-else structure) and a few maths being common in all programming languages.<br /><br />At this point I have never worked with IDL so I can't help you more.Logichttps://www.blogger.com/profile/10024617997824703986noreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-26951142527882089802017-01-13T21:14:53.857-08:002017-01-13T21:14:53.857-08:00Hi! Your article is very helpful. I am a beginner ...Hi! Your article is very helpful. I am a beginner and I would like to know how to use these codes using IDL (Interactive Data Language). Thank you and more power. Anonymoushttps://www.blogger.com/profile/02662182394149683960noreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-47844688667774700652016-11-16T03:53:04.053-08:002016-11-16T03:53:04.053-08:00Thanks for you reply!Thanks for you reply!David Frogernoreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-88566685240408258892016-11-05T09:50:20.016-07:002016-11-05T09:50:20.016-07:00Well, for N<7 its not too bad, but the Delaunay...Well, for N<7 its not too bad, but the Delaunay procedure is certainly worth looking into. Can "CM" of the polygon, X=(sum Xi, i=1..N)/N, play a useful role in sorting vertices?Bob Terryhttps://www.blogger.com/profile/07137578798614253121noreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-51412245812533673712016-11-05T05:54:38.801-07:002016-11-05T05:54:38.801-07:00Take care how you build your list of triangles. Co...Take care how you build your list of triangles. Considering ALL possible triangles made from the vertices list is not efficient. On the other hand, trying to optimize your triangles list, you could miss one or several.<br /><br />You should consider to build a Delaunay triangulation from your n-vertices polygon.<br /><br />Or check for algorithms directly dedicated to n-sides polygons.Logichttps://www.blogger.com/profile/10024617997824703986noreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-72922427687502985752016-11-05T05:45:47.585-07:002016-11-05T05:45:47.585-07:00Winding number method is a powerful method for n-s...Winding number method is a powerful method for n-sides polygons. But applied and optimized to 3 sides polygons, it is equivalent to the "check sides" method I exposed ;)Logichttps://www.blogger.com/profile/10024617997824703986noreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-25290487292240862872016-11-04T08:54:36.049-07:002016-11-04T08:54:36.049-07:00Ok, suppose that we have a general convex polygon,...Ok, suppose that we have a general convex polygon, N vertices.<br /><br />We seek to place or reject a test point, P within the polygon.<br /><br />We select as many test triangles as possible, N points 3 at a time, and apply the test on each triangle.<br /><br />The test point is in the polygon if it rests within at least one of the [N,3] of the triangles.<br /><br />Right?Bob Terryhttps://www.blogger.com/profile/07137578798614253121noreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-34896437376936139282016-11-03T16:50:51.379-07:002016-11-03T16:50:51.379-07:00Hello, what about the winding number method [1] fo...Hello, what about the winding number method [1] for the step 2?<br /><br />thanks!<br /><br />[1] http://geomalgorithms.com/a03-_inclusion.htmlDavid Frogerhttps://github.com/dfrogernoreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-48590890937085933512016-06-06T12:51:03.264-07:002016-06-06T12:51:03.264-07:00Thank you very much.Thank you very much.lchtanhttps://www.blogger.com/profile/00405559574145155062noreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-72120007165923767602016-05-30T03:49:06.913-07:002016-05-30T03:49:06.913-07:00Very good article. Thanks a lot it was very useful...Very good article. Thanks a lot it was very usefull to me.Anonymoushttps://www.blogger.com/profile/12945519555943583864noreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-26812800670648337862015-11-24T17:54:38.396-08:002015-11-24T17:54:38.396-08:00Thank you.Thank you.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-39086688179525623122015-11-10T04:17:07.498-08:002015-11-10T04:17:07.498-08:00If you are not sure that your triangle is safe, be...If you are not sure that your triangle is safe, better is to check it before perfoming calculation. Check if any 2 points don't overlap. But problems can still occur with points being too close from each other !<br /><br />That is why in my library (Daedalus Lib) I proceeded differently. I choosed to merge points that are too close each other. For that I checked if the distance is smaller than the epsilon value.Logichttps://www.blogger.com/profile/10024617997824703986noreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-38470013624272812472015-11-09T20:26:14.087-08:002015-11-09T20:26:14.087-08:00so first you have to test if the triangle is in fa...so first you have to test if the triangle is in fact a triangle?drecnoreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-50809424905754423802015-08-27T10:53:20.124-07:002015-08-27T10:53:20.124-07:00A graphical area is a semi-open interval - for con...A graphical area is a semi-open interval - for consistency this is usually done with lower bound inclusive, upper bound exclusive. A point on the boundary of two regions should not be in both; it should be in the region where the point is inclusive and excluded from the region where the point is exclusive. Very few graphics packages handle this issue properly - most have a fencepost error on the boundary. It should be possible to draw two squares from (0,0) to (10,10) and from (10,0) to (20,10) and have them abut exactly, as the pixels should be drawn from 0..9 and 10..19 - in which case a point such as (10,5) would belong to the (10,0) to (20,10) square only.Ghttps://www.blogger.com/profile/04079389970653405030noreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-60557344438161067292015-07-15T14:57:49.456-07:002015-07-15T14:57:49.456-07:00Yes from a computational point of view, they are v...Yes from a computational point of view, they are very close. But the concepts involved in the reasonings are different, that's why I found interesting to expose both.Logichttps://www.blogger.com/profile/10024617997824703986noreply@blogger.com