devlondoner
devlondoner

Reputation: 127

Convert matrix array

Using jQuery I'm trying to obtain the rotation state of an object but in IE9 I can only return the matrix values. What I need is to change this into a single value as a degree.

Upvotes: 1

Views: 2055

Answers (2)

mojamalu
mojamalu

Reputation: 11


function decodeMatrix(matrix, query) {
    var values = matrix.split('(')[1];
    values = values.split(')')[0];
    values = values.split(',');
    var output = {
        a: values[0],
        b: values[1],
        c: values[2],
        d: values[3],
        x: values[4],
        y: values[5]
    };
    output.scale = Math.sqrt(output.aoutput.a + output.boutput.b);
    output.sin = output.b / output.scale;
    output.angle = Math.round(Math.asin(output.sin) * (180 / Math.PI));
    if (query) {
        return output[query];
    }
    return output;
}

Upvotes: 1

Giona
Giona

Reputation: 21114

Check this article: http://css-tricks.com/get-value-of-css-rotation-through-javascript/

This function will return the rotation angle from matrix values:

function decodeMatrix(matrixValue){
    var values = matrixValue.split('(')[1];
        values = values.split(')')[0];
        values = values.split(',');
    var a = values[0];
    var b = values[1];
    var c = values[2];
    var d = values[3];
    var scale = Math.sqrt(a*a + b*b);
    var sin = b/scale;
    var angle = Math.round(Math.asin(sin) * (180/Math.PI));
    return angle;
}

Upvotes: 1

Related Questions