package org.stwing.jrank.bug.gpsemulator.impl;

import org.osgi.framework.BundleContext;
import org.stwing.jrank.bug.gpsemulator.GpsEmulator;

import com.buglabs.bug.module.gps.pub.LatLon;
import com.buglabs.util.StringUtil;

/**
 * 

* Plots a straight path from an initial point along a specific angle and with a * specific velocity. *

*

* Properties (see also {@link GpsEmulator}}: *

*

* * @author Jacob Rank * */ public class StraightLinePath extends GpsEmulator { private static final String KEY_ANGLE = "org.stwing.jrank.bug.gpsemulator.angle"; // Default property values private double angle = 0.0; // degrees public void initialize(BundleContext context) { super.initialize(context); String value; value = context.getProperty(KEY_ANGLE); if (value != null) { angle = Double.parseDouble(value); } } public LatLon getLatitudeLongitude() { LatLon latLon = new LatLon(); // Determine distance double elapsedTime = getNextTime(); double distance = elapsedTime / 1000.0 * velocity; // Determine theta double theta = converter.degreeToRadian(angle); // Convert distance and theta to UTM offsets double utmNorthingDelta = distance * Math.sin(theta); double utmEastingDelta = distance * Math.cos(theta); // Get current position in UTM String[] utmPosition = StringUtil.split(converter.latLon2UTM(initialLatitude, initialLongitude), " "); double utmNorthing = Long.parseLong(utmPosition[2]); double utmEasting = Long.parseLong(utmPosition[3]); // Update UTM position and convert back to lat/lon utmNorthing += utmNorthingDelta; utmEasting += utmEastingDelta; double[] newLatLon = converter.utm2LatLon(utmPosition[0] + " " + utmPosition[1] + " " + utmNorthing + " " + utmEasting); latLon.latitude = newLatLon[0]; latLon.longitude = newLatLon[1]; return latLon; } }