Question: Please can somebody take a look at my .htaccess code to help identify what's wrong.

I am trying to amend all example.php, example.html and example.htm URL's to index.php?filename=example.html

```
Options +FollowSymLinks

<IfModule mod_rewrite.c>

   RewriteEngine On

   RewriteRule ^(index\.php) - [L]

   RewriteRule ^([^/\.]+).(php|html|htm)$ index.php?filename=$1.html&%{QUERY_STRING} [L]

</IfModule>

```

When I enter a URL like example.html I'm taken to the default 404 and not index.php

Answer: 
This stuff is high school physics, and if you don't know the difference between acceleration and velocity, you'll need to review it before you have any hope here.

I can tell you this much: the linear acceleration readings from a cell phone or tablet aren't remotely precise or accurate enough to do what you want without constant correction (via gps or other methods). There is an entire field of study trying to solve this problem. I've attended conferences on it.

That said, you also need to take into account that the orientation of your device will also change, unless this is some sort of special application, e.g. the device is trapped onto a sled which can only move in one direction.

Let's assume that case, and assume that the device is strapped to your sled with the right side of the device (+X axis) aligned in the direction of travel. Let's also assume that the initial position of the sled is known (call it X0) when the program starts, and that the initial velocity is zero.

Your code looks approximately like this:

```
double x0;    // previous position, meters
double x;     // current position
double v0;    // previous velocity, meters/second
double v;     // current velocity
long t0;      // previous time, nanoseconds
long t;       // current time

public void onStart() {
    x0 = getInitialPosition();
    x = x0;
    v0 = 0;
    v = v;
    t0 = System.getCurrentTime() * 1000000;
    // Enable sensors; left as an exercise for the reader
}

public void onSensorChanged(SensorEvent event) {
    // Assume linear acceleration is the only active sensor
    double accel = event.values[0];   // X axis is our axis of acceleration
    t = event.timestamp;
    double dt = (t - t0) * .000001;
    v = v0 + accel * dt;
    x = x0 + v * dt;
    t0 = t;
    v0 = v;
    x0 = x;
}

```

This is by no means a complete solution. Doing this right involves differential equations which I'm not equipped to explain here (translation: I've forgotten everything I learned in college). However, if your acceleration value is accurate enough, and your time slice is short enough, this is viable.

If you need to solve this in more than one direction, it's only slightly more complicated provided that the device never changes orientation. If it does, then you also need to capture the rotation sensor and learn about quaternions and rotation matrices.

And even if you do everything right, errors will still accumulate, so now you want some sort of correction factor based on GPS, known geometry of the environment (e.g. if you're indoors and the software has a map of the building, it can make corrections when you turn a corner), and other environmental clues such as WiFi hotspots in known locations.

You might want to read up on Kalman filters at this point.

Executive summary: this is a HARD problem in the general case, and if you solve it, there's probably fame and fortune waiting for you.
Well, the correct form, known from school, is
finalXPosition = (linearAcceleration\*timePassed^2)/2+ initialVelocity\*timePassed+initialXPosition

finalVelocity = initialVelocity\*timePassed

chaining these chunks you'll get your theoretical values.

In practice, best results are achieved by regular calibration of initialXPosition and initialVelocity through GPS.

simple example to receive calibrated horizontal acceleration in onSensorChanged:

```
class Integrator {
    private float position = 0f;
    private float velocity = 0f;

    public void setGpsPosition (float gpsPosition) {
        position = gpsPosition;
    }
    public void setGpsVelocity (float gpsVelocity) {
        velocity = gpsVelocity;
    }
    public void onAccelerationChangeHandler(float acceleration, float timePassed) {
        position += acceleration*timePassed*timePassed/2f + velocity*timePassed;
        velocity += acceleration*timePassed;
    }
    public float getCurrentPosition() {
        return position;
    }
}

```

usage for x-acceleration:

```
long lastTime = 0;
public void onSensorChanged(SensorEvent evt) { 
    if (evt.sensor.getType() == Sensor.TYPE_LINEAR_ACCELERATION) {
        long newTime = System.currentTimeMillis();
        OnAccelerationChangeHandler(evt.values[0], (newTime-lastTime)/1000);
        lastTime = newTime;
    }

```

Please, note that outside a minute scale the error makes this all meaningless w/o gps correction. Understand, that if you are walking at constant speed the sensor won't give you **anything** at all.