Leave these fields empty (spam trap):
You can leave this blank to post anonymously, or you can create a Tripcode by using the format Name#Password
[i]Italic Text[/i]
[b]Bold Text[/b]
[spoiler]Spoiler Text[/spoiler]
>Highlight/Quote Text
[pre]Preformatted & Monospace Text[/pre]
[super]Superset Text[/super]
[sub]Subset Text[/sub]
1. Numbered lists become ordered lists
* Bulleted lists become unordered lists


I ask you because I like you

- Wed, 29 Jun 2016 15:39:21 EST sIgWxmPi No.35786
File: 1467229161198.png -(9121B / 8.91KB, 746x542) Thumbnail displayed, click image for full size. I ask you because I like you
tl;dr: how to find the point closest to the intersection in pic. The black dots are cartesian points from a list (or two). The circle can be a function, or also a list of points. I'm using python...

Amateur needing some programming for a thesis here.

I have a list of cartesian points (currently two lists, one for x, one for y, but I can do it differently ofc). These points describe a short path of a veichile, arond 10 meters, so it's a uncomplicated curve. I also have a list of points forming a circle derived from points from the aforementioned list(s) (derived means the circle center is not actually one of the points), and a constant radius.
I could also just use a function for the circle I guess.

I want to find the point closest to the intersection. Pic related
Oliver Wucklelug - Wed, 29 Jun 2016 15:43:53 EST sIgWxmPi No.35787 Reply
1467229433198.jpg -(1570606B / 1.50MB, 3100x3100) Thumbnail displayed, click image for full size.
The blue line is just how I get the circle center, nvm that.
Cyril Pickforth - Wed, 29 Jun 2016 16:43:36 EST m0aA/cv2 No.35788 Reply
for each point, measure its distance from the center of the circle and subtract the radius from that distance, then throw away the sign. the point with the smallest answer is closest to the circumference of the circle.
Clara Clayham - Thu, 30 Jun 2016 02:37:06 EST sIgWxmPi No.35791 Reply
1467268626586.jpg -(383778B / 374.78KB, 918x1632) Thumbnail displayed, click image for full size.
Thanks, that's much easier. I need this to happen for every 10cm of veichile travel though. Will there be a processing speed issue you think? (veichile will rarely exeed 20km/h)
Barnaby Pimmlefuck - Thu, 30 Jun 2016 09:41:10 EST V5hbNNkO No.35792 Reply
I can calculate 200,000 float distances in about 0.3 seconds on my desktop CPU. That's fast enough for about 30 minutes if you never discard points and don't do any optimizations.
Sidney Wablingnock - Thu, 30 Jun 2016 10:37:04 EST WLOo3E7i No.35793 Reply
At 20km/h, with calculation happening every 10cm, this means you will have to do these calculation about 55 times per second.

If you compare that to a video game which will updates its entire state and then draw an image to the screen 60 times per second, you should probably be OK.
Barnaby Pimmlefuck - Thu, 30 Jun 2016 16:25:43 EST V5hbNNkO No.35796 Reply
I redid my math expecting to be off by one order of magnitude, but ended up off by two and I can't figure out how. That seems really slow even when accounting for python tax. If you want to do this in real time for any length of time, my suggestion would be to figure out how to limit the number of points you're looking at.
Fucking Cloddlefuck - Wed, 06 Jul 2016 13:56:38 EST sIgWxmPi No.35819 Reply
oh the list of points is limited to 100 entries, 1 point added, one point deleted. I'm more worried if the math (a bit more math than has been mentioned, finding some angles etc.) can be done before another 10cm have been driven and everything starts again.
Ernest Greenwill - Wed, 06 Jul 2016 14:13:02 EST PQ13pkX3 No.35820 Reply
Unless you're trying to do this on a microcontroller without enough memory for a lookup table, this is trivial.
Shit Worthinghood - Thu, 07 Jul 2016 15:18:32 EST sIgWxmPi No.35823 Reply
1467919112741.png -(58141B / 56.78KB, 1157x389) Thumbnail displayed, click image for full size.
Yeah, the prototype will probably just use a laptop or similar.
Felt kinda stupid asking that question.


Would this work?:
import math
p2 = (center of the famous red circle)
for point in lista:
math.hypot(p2[0] - %r[0],p2[1] - %r[1])

"lista" is the list of all the 100 most recent cartesian points.
Nathaniel Derringway - Thu, 07 Jul 2016 20:01:08 EST ggSMefJk No.35824 Reply
I don't know wtf %r is supposed to be, but you have the right idea. If this is all you're looking to do, here's one way a civilized person might write this:

def get_min_distance(center, radius, point_list):
solution = (float("inf"), None)

for point in point_list:
distance = math.hypot(center[0] - point[0], center[1] - point[1]) - radius
if distance < solution[0]:
solution = (distance, point)

return solution
William Boblinghick - Mon, 18 Jul 2016 12:36:06 EST sIgWxmPi No.35866 Reply
1468859766408.jpg -(2130467B / 2.03MB, 2204x3920) Thumbnail displayed, click image for full size.
This just picks the point closest to the center and gives me the distance from the center + the radius
I want the closest point to the circle edge.

I've mucked about with it but am at a loss, so, if anyone, please.

Among other things I've tried this:
def get_min_distance(center, radius, point_list):
solution = (float("inf"), None)

for point in point_list:
distance = math.hypot(center[0] - point[0], center[1] - point[1])
if distance < solution[0] - radius:
solution = (distance, point)

return solution

Wich yields a point kind of in the middle of the circle edge and the center.
I'm not really sure exactly what
if distance < solution[0]:
does, to be honest.
Fanny Greencocke - Mon, 18 Jul 2016 14:34:12 EST WLOo3E7i No.35868 Reply
It looks like >>35824 is pretty close, it just needs the absolute value of the distance
distance = abs(math.hypot(center[0] - point[0], center[1] - point[1]) - radius)

For the line distance < solution[0], solution is a list where the 0th element is the distance from the radius and and 1st element is the point itself

So all it is doing is comparing the distance of the current point with the point that is closest to the radius

Report Post
Please be descriptive with report notes,
this helps staff resolve issues quicker.