Search code examples
mathtrigonometrycartesian

Convert Cartesian point to point on rotated plane (pic)


I have a cartesian point that I am being given (blue line), and I need to convert it to a point relative to a rotated plane (green box). The plane is rotated at 28.227º as shown below.

Sadly, my lack of math education has me completely baffled as to how to solve this. I need to be able to take any x,y point and convert it for the rotated plane.

Any help at all on this would be greatly appreciated as I am at a total loss.

Best I can figure out, I will need several different calculations depending on where the input point is.


(source: adam-meyer.com)


Solution

  • I love friends who know math. Thanks KJ! Here is the answer.

    function convertPoint(x,y){
    
        var degree = -28.227;
        var offset = 0; //change if your corner is not 0,0
    
        x2 = x *Math.cos(radians(degree)) + (y - offset) *Math.sin(radians(degree));
        y2 = x *Math.sin(radians(degree)) - (y - offset) *Math.cos(radians(degree));
    
        return {x: x2, y: y2}
    }
    
    function radians(degrees){
        return degrees * (Math.PI / 180);
    }