http://bcs.wiley.com/he-bcs/Books?actio … indow=true
B
]]>segment2Length = (xDistance)^2 + (yDistance - segment1Length)^2
Bob
]]>how did you analyse and understand this problem? what did you do?
from where did you get this experience ? I thought you are expert in math only not in programming
http://bcs.wiley.com/he-bcs/Books?actio … indow=true
So, I'll answer the easy question first. The distances are in kilometres (Km) and the times in hours h.
Let's say that the road runs South-North and the item is off road to the East. The robot can travel more quickly along the road but must eventually head off road to get to the item.
Is it best (1) to go along the road until we are alongside the item and then cut across with the shortest off-road distance? Or maybe it is better to (2) leave the road at the start and just head diagonally across the rough terrain taking the straight line shortest route? Or (3) go part by road and then cut across diagonally.
If the cross country speed is the same as the road speed then (2) is best. If the road speed is a lot quicker than the rough terrain, then (1) is best. Finding the optimum choice requires that we know the distances and speeds involved.
A speed is measured in kilometres per hour (Km/h) so there is a simple formula connecting distance, speed and time:
speed = distance / time
For example if the robot can travel 14 Km in 2 hours the its speed is 14/2 Km/hour = 7Km/h
If we know the speed and time then we can compute the distance with
distance = speed x time
eg. If speed = 7 and time = 2 the distance = 14
And if we know the distance and speed we can compute the time with
time = distance / speed
eg. if distance = 14 and speed = 7 then time = 14/7 = 2
In the problem segment 1 is the distance along the road. If the road speed is segment1speed then the time is found by dividing the distance by the speed:
time for this = (segment1distance)/(segment1speed)
The cross country part is harder to calculate as it is along a diagonal line.
The easterly amount is just 'x' as we haven't done any travel in an easterly direction yet.
But we have already done segment1distance in a northerly direction so we can subtract this amount from 'y' .
Then use Pythagoras theorem to calculate the diagonal
Note: in your post you left out the square root!
Then dividing that by the speed (rough terrain) gives the time for that part.
Adding them gives the total time.
Once you have a program for calculating this total you can try different values for segment1distance and so find the lowest time.
Bob
]]>enter Distance to item along x-axis
enter Distance to item along y-axis
enter Length of segment
enter Speed along segment 1
enter Speed along segment 2
segment1Time = segment1Length / segment1Speed;
segment2Length = (xDistance)^2 + (yDistance - segment1Length)^2
segment2Time = segment2Length / segment2Speed;
totalTime = segment1Time + segment2Time;
how can that program devide length over speed to get time!!?
can anyone give me an explanation of this program please and what is the meaning of segment 1 or 2 ?
I provided the output of the program and I assumed arbitrary values but I don't know is the speed in km/h or the distance in mile
and I don't know the time is seconds or minutes the program is without units ... see the following photo :-