A geometric geofence

JohnWrowles

New member
Joined
Sep 26, 2007
Messages
2
Note that this is a real world problem rather than one from a textbook.

I need to be alerted when a vehicle crosses a line. The line is defined by start and end points in terms of spatial coordinates (x,y) e.g. start of line x=2662150 (east), y=6494900 (north) end of line x=2662158 (east), y=6494895 (north)- these are actually New Zealand map grid coordinates - but the principle is the same in any coordinate system.
We always know that the coordinates are positive.
The vehicle carries a GPS and so always knows its own x,y position. The challenge is to construct an algorithm that continuously monitors the position and triggers an alert when the vehicle crosses the line (or an extension of the line) within a reasonable distance.

My thinking so far is to set one of the points to the origin and then set the y axis so that it follows the line. If I can translate the x,y of the moving vehicle into this (new) coordinate system then the trigger would simply fire when the x coordinate changes from positive to negative (or vice versa) - i.e. crosses the (new) y axis in either direction. I think that this requires a translation to polar coordinates so that the angle of axis rotation can be calculated, but despite much sketching and figuring I can't figure it out

Any help would be much appreciated.
 
By inversing between these two sets of coordinates, I found the distance between them is only 9.43 feet. The actual line has an azimuth of 122 degrees.
Or S58E from the first line to the second.
Of course, the opposite direction, just add 180. 302 degree azimuth or bearing of N58W.

Perhaps you could write an algorithm to keep the truck on that heading. If it waivers too much from that azimuth, it is signaled somehow.

As you said, you could set one end at (0,0) and the other at (9.43, 0).

If someone enters into too much of a positive or negative y coordinate, then the alarm sounds.
 
2D cross product

Thanks Galactus for your advice.

The specific data was just an example set for the general problem of having a trigger created when the line was crossed. In practise there are over 3,200 lines.

I have decided to use a "2D cross product" as per http://www.geocities.com/SiliconValley/2151/math2d.html.

P1 and P3 will be the first and last points of my geofence.
P2 is the moving point.

When the cross product changes sign either from +ve to -ve or vice versa I will know the moving point (P2) has crossed the line P1 to P3
 
Top