|
Post by honkytonk on Jun 25, 2022 11:14:48 GMT
In this thread ( justbasiccom.proboards.com/thread/821/help-crazy ), you gave me the closest point calculation. g=1 #w.g, "color white;backcolor darkgray" minDist=1e10 '10000 also works. for x=1 to 800 for y=my-2 to 3 step -1 if map(x,y)=1 then dist = sqr((x-mx)^2+(y-my)^2) 'print mx, my, x, y, dist, minDist if dist < minDist then minDist= dist tagx(g)=x: tagy(g)=y end if ' pointy(y-1)=0 end if next y #w.g, "place 20 40": #w.g, "\ "; str$(x) next x #w.g, "color red;backcolor darkgray" for x=1 to g #w.g, "size 5": #w.g, "set ";tagx(x);" ";tagy(x) next x
I don't understand the reason for this: minDist=1e10 '10000 also works. '.... '.... if dist < minDist then
Could you explain it to me? Thank you for...
|
|
|
Post by tsh73 on Jun 25, 2022 11:36:17 GMT
well, This is standard way of searching MIN out of something:
minDist= "big enough number" for i=... dist="some calculation" if dist < minDist then minDist=dist 'also you can store "i" on which it is happened in some variable end if next Now, "big enough number" should be big enough so first calculated "dist" will trigger condition. Since (usually?) there less then 2000 pixels on screen, 10000 is big enough. But if I want to save some time and use not distance sqr(x^2+y^2) but distance squared x^2+y^2 then suddenly 10000 is not enough. I thought about it and put 1e10, that means 1*10^10 or 10000000000 But printing exactly 10 zeros is awkward (just now I had to split it two groups to cout, and it happened I missed one zero) While printing 1e10 is just 4 characters, easily recognised and defnitely big enough.
That's all. (oh. And since I am part time teacher, I used to explain this and put 1e10 as big enough number. So why not 1e100? Well, that extra character to type. Why not 1e99? Now, this stems from really old time then floating point numbers were restricted to 1e38)
|
|
|
Post by honkytonk on Jun 25, 2022 11:51:59 GMT
So we cannot calculate the nearest point without going through this condition? Why ?
|
|
|
Post by tsh73 on Jun 25, 2022 20:05:12 GMT
Getting that WHY makes me nervous (not really). Why do you asking?
This is condition
if dist < minDist then and it is standart working way to search for minimum.
Now can we
I have no idea. (actually I have a couple, but I pretty sure it would have same condition inside, may be hidden from our sight) And since I have working way I'd rather not bother, really. EDIT Is something in this solution does not suit you? Too slow may be?
|
|
|
Post by honkytonk on Jun 26, 2022 8:37:19 GMT
This condition is very troubling; And I would like to know his reason for being there. Doing without it is not the point, even if one could list all the hypothenuses at the last plotted point, then sort the values and the indices (associated indices), at the same time to extract the minimum.
I understand that this is "the standart working way". But I don't understand why.
|
|
|
Post by Rod on Jun 26, 2022 11:24:39 GMT
It is really very simple. We are comparing two numbers to see which is lower. At the very start of the comparison we only have the first point. The number we compare it against MUST be bigger than it. So we use a very big number, as big as we can imagine, safe in the knowledge that it will be bigger than our first point and so the first point will become the lowest point. Until the next comparison where it gets compared with the next real point and may or may not stay as the lowest point.
|
|
|
Post by honkytonk on Jun 26, 2022 11:35:14 GMT
Ah ok, now I understand. Thanks a lot.
|
|
|
Post by tsh73 on Jun 26, 2022 12:11:08 GMT
Thanks Rod ;))
|
|