[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Assumption help
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /wsr/ - Worksafe Requests

Thread replies: 10
Thread images: 1
File: river.jpg (63 KB, 481x459) Image search: [Google]
river.jpg
63 KB, 481x459
So for homework I got the map (see picture) between column 8 and 9 lies a river, and a bridge located at 8,3 and 8,10. So if I wanted to get from 1,1 to 16,16 for example I need to find the distance to a bridge, and then from the bridge to the other point. Because I need to program this, I want to try and make a general assumption regarding which bridge to choose. Or am I better off calculating the distances to and from each bridge and testing which one has the shortest distance?
>>
>>79145
Are you using Euclidian or Manhattan geometry?

Because with the latter, as long as you're not actually doubling back, which bridge you use makes no difference.
>>
>>79157
We have to use Euclidian.

>>79153
I also though of something similar, but I saw some special cases where it could be invalid. Also I do not understand what you mean with i and j, as there are 4 variables being used, (x1,x2,y1,y2)
>>
Right now I am going to use
if A and B to the left OR A and B to the right
result = distance
else
result = 1 + min(A to bridge1 + bridge1 to B, A to bridge2 + bridge2 to B)
>>
>>79176
Unless I can make a simpler assumption about it. As this is only part of the homework and the specific function will be used millions of times for the follow up questions, I would like to keep unnecesary calculations to a minimum.
>>
>>79173
You've only got two bridges to consider, so just square the offsets from the origin to each bridge, and from each bridge to the destination, and take the lower sum.

Bonus points for checking if you have to cross a bridge at all.

>So if I wanted to get from 1,1 to 16,16
b1 (8,3): x1 = 8-1, x2=16-8. y1=3-1, y2=16-3
b1 (8,3): x1 = 7, x2=8. y1=2, y2=15
b1 (8,3): meansquare = 342

b2 (8,10): x1 = 8-1, x2=16-8. y1=10-1, y2=16-10
b2 (8,10): x1 = 7, x2=8. y1=9, y2=6
b2 (8,10): meansquare = 213

So in this case, you go with b2. Note that you've not had to do any division, just multiplication (or addition).

You can actually ignore the x components entirely, so long as the bridges all have the same x coordinate.
>>
>>79157
He needs a general rule, so it happens that he needs to go back if he choses a wrong bridge.

But in either case the answer is simple: Look at the line where the distance to both bridges is equal. This line divides the area into two parts. For all points in one region one bridge is closer than the other.

In your example, it is the line between the squares with y=6 and y=7. So if y <= 6 you pick the upper bridge, if y >= 7 you pick the lower bridge.

In general the area is subdivided into so called Voronoi cells depending on the distance to given seeds.

https://en.wikipedia.org/wiki/Voronoi_diagram

Note that in the Manhattan metric the cells are delimited by horizontal lines, vertical lines, and lines at 45° angle. In your example the metric doesn't matter since the two bridges define the same cells in both metrics.
>>
Ok so you want to go to 16,16
Use this pretty simple formula (16/2)*83+x (here x=2)
You will find a equilateral triangle
>>
>>79185
Call me Mr. Thick, but if you're at 4,5 and you want to go to 11,10, going to the upper bridge because 5 is less than 6 doesn't seem the optimal route.
>>
>>79213
Yeah, because I only checked the distance from the starting position to the bridge, not the distance from the starting position to the end point, sorry.

I think it's probably easier to go with >>79176 or better >>79181 since the squares calculated can be used in the computation of the distance.
Thread replies: 10
Thread images: 1

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.