Thursday, December 22, 2016

Flaw in VelocityTracker changes to a diagonal.

Velocity is the direction and speed of an object. Changing the direction because of the maximum velocity was reached must be considered a defect. This also clearly causes a flaw in that a diagonal velocity is faster than the orthogonal one.

The problematic bit of code akin to:
mXVelocity = accumX < 0.0f ? Math.max(accumX, -maxVelocity) : Math.min(accumX, maxVelocity);
mYVelocity = accumY < 0.0f ? Math.max(accumY, -maxVelocity) : Math.min(accumY, maxVelocity);

The flaw here is that if your velocity in the X direction exceeds the maxVelocity it is changed equal maxVelocity and the same for the Y. But, that means that if we are going at 20° angle and at a speed of 200, and our maxVelocity is 20. Our velocity is changed to be 20*sqrt(2) at a 45° angle. The correct answer is to scale the mXVelocity and mYVeloicity by the ratio of the actual velocity and maxVelocity.

mXVelocity = accumX;
mYVelocity = accumY;
double actualVelocitySq = mXVelocity * mXVelocity + mYVelocity * mYVelocity;
double maxSpeedSq = maxVelocity * maxVelocity;
if (actualVelocitySq > maxSpeedSq) {
    double excessFactor = Math.sqrt(maxSpeedSq)/Math.sqrt(actualVelocitySq);
    mXVelocity *= excessFactor;
    mYVelocity *= excessFactor;
}

Sunday, September 18, 2016

Scaryish fact of the day

Each and every moment half of this solar system's life-ending cataclysmic asteroids get closer to Earth.

Saturday, August 27, 2016

Wow the Table Talks are total bullshit.

I checked a few of the Table Talk quotes and found the same thing Richard Carrier found. That they were generally bullshit. But, I didn't know how far the rabbit hole went or how crap they were to start with.
http://www.richardcarrier.info/archives/10978

Tuesday, July 12, 2016

Fastest Pure Code Java Box Blur

----- Behold. Admittedly it'll fill the side two garbage pixels on the right with looped garbage but it doesn't bother to slow down to check when those happen. Stride is typically equal to width.


private static void applyBlur(int[] pixels, int stride) {
    int v0, v1, v2, r, g, b;
    int pos;
    pos = 0;
    try {
        while (true) {
            v0 = pixels[pos];
            v1 = pixels[pos+1];
            v2 = pixels[pos+2];

            r = ((v0 >> 16) & 0xFF) + ((v1 >> 16) & 0xFF) + ((v2 >> 16) & 0xFF);
            g = ((v0 >> 8 ) & 0xFF) + ((v1 >>  8) & 0xFF) + ((v2 >>  8) & 0xFF);
            b = ((v0      ) & 0xFF) + ((v1      ) & 0xFF) + ((v2      ) & 0xFF);
            r/=3;
            g/=3;
            b/=3;
            pixels[pos++] = r << 16 | g << 8 | b;
        }
    }
    catch (ArrayIndexOutOfBoundsException e) { }
    pos = 0;
    try {
    while (true) {
            v0 = pixels[pos];
            v1 = pixels[pos+stride];
            v2 = pixels[pos+stride+stride];

            r = ((v0 >> 16) & 0xFF) + ((v1 >> 16) & 0xFF) + ((v2 >> 16) & 0xFF);
            g = ((v0 >> 8 ) & 0xFF) + ((v1 >>  8) & 0xFF) + ((v2 >>  8) & 0xFF);
            b = ((v0      ) & 0xFF) + ((v1      ) & 0xFF) + ((v2      ) & 0xFF);
            r/=3;
            g/=3;
            b/=3;
            pixels[pos++] = r << 16 | g << 8 | b;
        }
    }
    catch (ArrayIndexOutOfBoundsException e) { }
}

Monday, March 14, 2016

The SVG 2.0 Specification adds a 'b' command to path for bearing.

This is going to make some pretty interesting L-System fractals pretty trivial to generate. F, F:=F-F-F+ then at the end replace all F with h10 all + with b90 and all - with b-90, and you're totally done. Update: This did not make it into the SVG 2.0 final Spec.

Sunday, February 21, 2016

As a GMO myself...

I've started calling myself a GMO in some conversations where it's useful the reason being is that the placental mammal syncytin gene is not ancestral to the line but evolved as a part of a virus and was inserted by a virus. Just like in some GMOs. http://blogs.discovermagazine.com/loom/2012/02/14/mammals-made-by-viruses/#.Vso5mvkrJhE