tag:blogger.com,1999:blog-8152247234598992686.post33880210096363411..comments2024-03-29T18:50:58.394-07:00Comments on Totologic: Accurate point in triangle testLogichttp://www.blogger.com/profile/10024617997824703986noreply@blogger.comBlogger49125tag:blogger.com,1999:blog-8152247234598992686.post-18500486362836604572024-03-29T18:50:58.394-07:002024-03-29T18:50:58.394-07:00I'm using this code for many years now, and I ...I'm using this code for many years now, and I just realized it was not robust enough with geographic data where the points can easily have coordinates as big as 5.000.000. An easy fix consist in moving the coordinates close to 0,0 to get the maximum of arithmetic accuracy.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-90333441136692775252024-01-25T15:31:16.983-08:002024-01-25T15:31:16.983-08:00I'm can't work out how p_p1_squareLength -...I'm can't work out how p_p1_squareLength - dotProduct * dotProduct * p1_p2_squareLength equals the distance between p and p' in distanceSquarePointToSegment. Can someone kindly explain?usernoreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-38462602462038123682023-01-12T16:25:38.479-08:002023-01-12T16:25:38.479-08:00Best example, i had problem with the edges and you...Best example, i had problem with the edges and you made it clear thanks:DAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-62222454354618011462022-10-13T08:12:30.497-07:002022-10-13T08:12:30.497-07:00Hi, do you still remember what kind of hardware yo...Hi, do you still remember what kind of hardware you used? Because with the 32bit floating point calculator (https://suhas1998.github.io/FPCalci-32bit/?#) I could not reconstruct the accuracy problems in example 3.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-33241122818568851872022-04-27T03:35:30.851-07:002022-04-27T03:35:30.851-07:00Ah, that explains it. My Y-axis points upwards, wh...Ah, that explains it. My Y-axis points upwards, which I’ve always thought of as the norm. Your version of my triangle is the reflection of mine in the X-axis, and counterclockwise becomes clockwise. rrgmitchellnoreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-6046560730435021072022-04-26T11:45:00.081-07:002022-04-26T11:45:00.081-07:00Y-axis is pointing down. Your points are clockwise...Y-axis is pointing down. Your points are clockwise.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-85791229439127711192022-04-26T08:27:09.420-07:002022-04-26T08:27:09.420-07:00Hi, I’m not sure what you mean by ordered counterc...Hi, I’m not sure what you mean by ordered counterclockwise. In my example the movement from P1 - > P2 -> P3 -> P1 is a counterclockwise tour round the origin. Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-52958530128190076842022-04-26T06:49:06.346-07:002022-04-26T06:49:06.346-07:00"We assume that p1, p2, p3 are ordered in cou..."We assume that p1, p2, p3 are ordered in counterclockwise"Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8152247234598992686.post-65423982691876469882022-04-26T06:43:12.214-07:002022-04-26T06:43:12.214-07:00There’s a flaw in the dot product method as stated...There’s a flaw in the dot product method as stated. For example, with P1 = (2,-2), P2= (4,3), P3 = (-5,1) and P = the origin (0,0) (which is inside the triangle) the three dot products are -14, -19 and -8. Perhaps the criterion for insideness is either all positive or all negative, as someone previously commented?Rrgmitchellnoreply@blogger.comtag: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.com