c# - GPS lap & Segment timer -
i've been searching while haven't found i'm looking for.
i'm working on app go in race car. give driver ability press button mark start/finish line. have button allow driver set segment times.
keep in mind track can oval i'm working on first. road course or auto cross start , finish line aren't exact same location. 50 feet of each other or car never crosses starts.
i have gps data coming in , convert nmea messages classes , store lat, lon, speed, course etc. in research i've ran across interesting. gps mounted outside roof better signal. generates 10 hits per second. (garmin glo)
http://www.drdobbs.com/windows/gps-programming-net/184405690?pgno=1
it's old talks utm , cartesian coordinate system. using decdeg2utm, convert lat & lon x & coordinates well.
i've been trying use intersect formula found here took intersect , tried convert c# i'll post @ end. however, feeding coordinates of oval track, doesn't seem working. also, i'm not sure it's supposed doing. coordinates returns when somethign -35.xxx & 98.xxxx out in ocean somewhere 1000's of miles track is.
i looking answers following.
- i assume need take location recorded when button pressed start/finish or segment , calculate line perpendicular direction car in able able sort of line intersection calculation. cartesian coordinates seems calculate bearing well. question here how "left , right coordinates". also, keep in mind, oval track may 60 feet wide. mentioned auto cross track may 20 ft wide , part of track may 50 ft. note i'm fine indicating set points, car needs going slow or stopped @ points accurate coordinate. tracks have set while walking track.
- based on this, should trying use decimal lat lon or utilizing cartesian coordinate system based on utm more accurate method i'm trying do?
- either 1 there .net library or c based library source code has methods making these calculations?
- how can accurately handled. (not great math, links code samples tremendously.)
- next, after have lines or whatever needed start/finish , segments, gps sign car racing, need figure out accurate way tell when car has crossed segments. again if i'm lucky i'll 10 hits per second lower. vehicle speeds vary depending on type of track , vehicle. gps hit many feet "left or right" of segment. also, many feet before or after segment.
again, if there gis library out there can feed coordinates , calculated, that's work long it's performant. if not again i'm trying decide if it's best break down coordinates x y or geometry formulas coordinates in decimal format. mods, assume there hard data support answer of either way , isn't responses aren't subjective opinions.
here c# code came script page above. i'm starting feel utm , cartesian coordinate system better accuracy , performance. again i'm open evidence contrary if exists.
thanks
p.s. note geocoordinate .net system.device.location assemble. gpsdata class use convert nmea messages lat, lon, course, numsats, datetime etc.
the degree radian methods extensions as follows.
public static double degreetoradians(this double angle) { return math.pi * angle / 180.0; } public static double radiantodegree(this double angle) { return angle * (180.0 / math.pi); } } public static geocoordinate calculateintersection(gpsdata p1, double brng1, gpsdata p2, double brng2) { // see http://williams.best.vwh.net/avform.htm#intersection // not sure need use cosine double _p1latradians = p1.latitude.degreetoradians(); double _p1lontoradians = p1.longitude.degreetoradians(); double _p2lattoradians = p2.latitude.degreetoradians(); double _p2lontoradians = p2.longitude.degreetoradians(); double _brng1toradians = brng1.degreetoradians(); double _brng2toradians = brng2.degreetoradians(); double _deltalat = _p2lattoradians - _p1latradians; double _deltalon = _p2lontoradians - _p1lontoradians; var _var1 = 2 * math.asin(math.sqrt(math.sin(_deltalat / 2) * math.sin(_deltalat / 2) + math.cos(_p1latradians) * math.cos(_p2lattoradians) * math.sin(_deltalon / 2) * math.sin(_deltalon / 2))); if (_var1 == 0) return null; // initial/final bearings between points var _finalbrng = math.acos((math.sin(_p2lattoradians) - math.sin(_p1latradians) * math.cos(_var1)) / (math.sin(_var1) * math.cos(_p1latradians))); //if (isnan(θa)) θa = 0; // protect against rounding var θb = math.acos((math.sin(_p1latradians) - math.sin(_p2lattoradians) * math.cos(_var1)) / (math.sin(_var1) * math.cos(_p2lattoradians))); var θ12 = math.sin(_p2lontoradians - _p1lontoradians) > 0 ? _finalbrng : 2 * math.pi - _finalbrng; var θ21 = math.sin(_p2lontoradians - _p1lontoradians) > 0 ? 2 * math.pi - θb : θb; var α1 = (_brng1toradians - θ12 + math.pi) % (2 * math.pi) - math.pi; // angle 2-1-3 var α2 = (θ21 - _brng2toradians + math.pi) % (2 * math.pi) - math.pi; // angle 1-2-3 if (math.sin(α1) == 0 && math.sin(α2) == 0) return null; // infinite intersections if (math.sin(α1) * math.sin(α2) < 0) return null; // ambiguous intersection α1 = math.abs(α1); α2 = math.abs(α2); // ... ed williams takes abs of α1/α2, seems break calculation? var α3 = math.acos(-math.cos(α1) * math.cos(α2) + math.sin(α1) * math.sin(α2) * math.cos(_var1)); var δ13 = math.atan2(math.sin(_var1) * math.sin(α1) * math.sin(α2), math.cos(α2) + math.cos(α1) * math.cos(α3)); var _finallatradians = math.asin(math.sin(_p1latradians) * math.cos(δ13) + math.cos(_p1latradians) * math.sin(δ13) * math.cos(_brng1toradians)); var _lonbearing = math.atan2(math.sin(_brng1toradians) * math.sin(δ13) * math.cos(_p1latradians), math.cos(δ13) - math.sin(_p1latradians) * math.sin(_finallatradians)); var _finallon = _p1lontoradians + _lonbearing; var _returnlat = _finallatradians.radiantodegree(); var _lattodegree = _finallon.radiantodegree(); var _returnlon = ( _lattodegree + 540) % 360 - 180; return new geocoordinate(_returnlat, _returnlon); //return new latlon(φ3.todegrees(), (λ3.todegrees() + 540) % 360 - 180); // normalise −180..+180° }
Comments
Post a Comment