A Flash Developer Resource Site

1. Just wanted to run a concept by those who may have more experience in mathematical equations and functions in Flash than I do, before actually getting down and dirty and working out how...

Basically a Flash map of Australia, or any other country/land mass. Then two points - point A and point B. Then a line drawn between point A to point B (such as a route/road.

Okay, now the more complex part - return other mapped values/positions that are within a certain distance from that line along the entire line.

The functionality of this is obvious - for a particular start and end point of a trip, return all the locations that are between those points. Now, the locations will have their own geo-coding, which I will obviously need to convert to an equivalent x y position, but that's the easy part. Returning a list from the dynamic line created between point A and B is the one that I'm asking is it possible?

I hope I've explanined this well enough.

Cheers
Dave

2. Make a movieClip containing a rectangle and two circles at the right and left end of this rectangle. Adjust this movieClip to line A-B.

Check what ever geogrphic point is hitTest positive with this movieClip.

This is my humble idea.

3. I'm not really after something that actually travels from "A" to "B", just the data that's returned within a certain area.

This is actually a quite complex mapping function, that is not even done yet by some of the mapping companies, that I'm trying to find a doable workaround for.

I'm just hoping someone with some Flash mathematics experience will tell me it is possible in some way...

Cheers
Dave

4. return other mapped values/positions that are within a certain distance from that line along the entire line.
I am not sure what data should be included in the list. I dont think it is too complex.

If we travel from A point to B point, a route connecting the A and B. I want a text list. In the list, there includes name of the cities which are located less than 100 miles away from this route. It also shows how far the cities are off the route (the vertical distance between the city and the AB line).

Is that the mapped value you want ?

5. Yes, but I don't know if it will be "not too complex".

First you need to assign some mathematical value to the straight line between A and B.

Then you need an equation that includes locations within a certain distance of that line.

Let's imagine an 800 x 600 pixel Flash movie just for ease of reference - so where would we start?

6. 1) if you actually want to do the maths, it would end up looking something like this:

- calculate an equation for the A-B line (this is easy)
- for all locations (well, you can probably narrow it down a little bit), calculate the equation for the line through that location, perpendicular to the A-B line
- calculate the point of intersection between the perpendicular line and the A-B line
- calculate the distance between the intersection point and the location point
- if distance is less than your target distance, include the point, otherwise discard

This is quite a lot of work but it would work out, I suppose. It should also be possible and perhaps easier to use trigonometry to gain a few shortcuts.

2) A better solution based on ericlin's approach: create just a rectangle whose height is equal to the equivalent of your target distance in your map scale and whose width is equal to distance A-B.

Then align the rectangle so it's center is lying on A-B.

Go through all points and do a hitTest with this rectangle.

(using hitTest(x,y,true) method)

basically the same approach as before but a great deal easier.

of course, none of this addresses much more complex issues, mainly that it is highly unlikely that you can travel from A to B in a straight line

sounds interesting anyway, good luck!

- n.

7. To calculate the vertical distance between the city and the AB line:

Make an empty movieClip. Move that movieClip to A point. Rotation that movieClip to align it with AB:
mc._x=A._x;
mc._y=A._y;
mc._rotation=(180/Math.PI)*Math.atan2(B._y-A._y,B._x-A._x);

For any city in root with position at (cityX,cityY);
point={x:cityX,y:cityY);
mc.globalToLocal(point);

Then point.y will be the vertical vector to the AB line. Math.abs(point.y) is the distance between the city and AB line. Of-course, point.x is the offset of city from A along the AB line.
//-------------------------------
If we dont like globalToLocal function, we can calculate ourself.

We need to calculate out the rotation of the line A-city. The difference of orientation between A-city and AB is the angle of city-A-B;

angle=Math.atan2(cityY-A._y,cityX-A._x)-Math.atan2(B._y-A._y,B._x-A._x);

Then calculate the distance of A-city, that is the hypo of the triangle.

dx=cityX-A._x;
dy=cityY-A._y;
hypo=Math.sqrt(dx*dx+dy*dy);

hypo*Math.sin(angle) will be the vertical distance between the city and the AB line. Offset along the AB line will be hypo*Math.cos(angle);

8. Thanks guys. Hopefully I can give it a go. At this point it's waiting on the client to agree to a project that involves a fair bit of R & D on our part, to deliver functionality that you just can't buy at the moment off the shelf - and so we split the costs of the total development.

I'll let you know how it goes, and the finished example if and when it's complete.

Cheers again.

Dave

9. Having once, long ago, written a program for a phaser (a la Star Trek), I sorta remember using vectors and dot products to do a similar task. The damage to the Klingon was calculated by the nearness of the phaser shot (vector) to the vessel (point) and the distance it was from the Enterprise/player (inverse-square law).

Well, in my wanderings on the internet trying to find an answer to your post, I came across the following post in the Ask Dr. Math forum:

http://mathforum.org/library/drmath/view/51818.html

The topic is strangely similar to your request. At least someone attempted something similar a few years ago. I didn't find a follow-up to see if it was ever accomplished.

Don

10. That seems like a pretty useful link Level - and it works with longitude/latitude too.

tofd - I think this sounds like a very interesting project but I'm not sure it is as exclusive as you imagine. As far as I know there are Route Planners that include exactly this kind of feature (for the UK anyway, perhaps not for Aus).

Anyway, would be interesting to hear how it goes on.

- n.

11. We have route planners here too, but at present they do not provide a route with mapped locations along that route. They provide either:

1. Map for an adress, with locations within a given distance from that point.

2. A route between two points.

It would have seemed logical to combine them to produce the functionality required, but is not done at present. If you can point me to the international developer that has this function for another area please do. I have searched extensively on the 'net and have only found simialr functionality as you will find here: http://www.whereis.com.au , which only has the two functions I described above.

Cheers
Dave

12. examples - you got me now

Around 4 years ago I was evaluating route planning software for a company that I worked with. I remember that some of them offered these 'locations near your route' features, however didn't investigate much further, since these were mostly the home-user products and not suitable for what we were trying to do.

http://www.freetrip.com offers something vaguely similar in that they show you hotels close to your route. It's text based and not as finely tuned as you probably require.

I'm really sorry but can't remember any names of the software I looked at at the time. I did a quick search on Amazon on this one (from microsoft ) seems to have similar functionality:

you can get the software to show as many or as few types of place as you like along a chosen route, and to search any radius round a point you desire.
Not sure of course what that actually looks like in real-life but the 'searching around a point' and 'along a chosen route' seem to fit the bill...

if you ask in the CL, maybe someone has used this software...[/edit]

here is the whole list at amazon:
http://www.amazon.co.uk/exec/obidos/...946967-3433203

sorry I can't be more help,

good luck - n.

13. You could rotate the area so that the route is aligned to either x og y axis then you calculate a bounding box around the line and draw anything that fits into that box without rotation.

14. Originally posted by enemem

Around 4 years ago I was evaluating route planning software for a company that I worked with. I remember that some of them offered these 'locations near your route' features,
Hmmh... don't know how many of these "off the shelf" products let you plot your own locations?? They seem to be for route planning and locating set locations - such as service stations, post offices...etc.

15. Originally posted by TheOriginalFlashDavo
Originally posted by enemem

Around 4 years ago I was evaluating route planning software for a company that I worked with. I remember that some of them offered these 'locations near your route' features,
Hmmh... don't know how many of these "off the shelf" products let you plot your own locations?? They seem to be for route planning and locating set locations - such as service stations, post offices...etc.

You might be right. Two points:

1) We did find a program that let's you import your own locations, place them on separate layers, search them, plan routes with them, etc.

However as far as I remember there wasn't any kind of 'locate places near...' feature. Technology might have advanced since then though.

2) One thing I did come across at the time is that you can purchase map-software engines and map data, which you can then use to build your own software. Depending on what you are trying to accomplish as an end-product, that might be an interesting option.

The main point is that the actual maths involved aren't difficult, if you don't need accurate route planning - measuring straight distances between points of known location isn't rocket-science after all. My main worry would be that Flash isn't really the greatest number cruncher, so a server-side program would be better suited IMHO - and just use Flash to display the results. (needs testing I guess )

if you are looking for people to work on this project, let me know

- n.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap