K
K
kiranananda2020-06-14 11:25:32
JavaScript
kiranananda, 2020-06-14 11:25:32

Get new size after image rotation?

Hi all.
I’ll say right away that I don’t know anything in mathematics, but it’s very necessary to get new sizes after rotating the image in order to resize the Canvas . I write in javascript. I found one example, but it works up to a 90 degree angle, then it fails. Can anyone suggest how this can be done?

function getNewPlanSizes(angle, width, height) {
        let newAngle = angle < 0 ? 360 + angle : angle
        let an = Math.PI * newAngle / 180

        let nwl = width * Math.cos(an)
        let nhl = width * Math.sin(an)
        let nhu = height * Math.cos(an)
        let nwr = height * Math.sin(an)

        return [nwl + nwr, nhu + nhl]
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kiranananda, 2020-06-14
@kiranananda

In general, I decided just like that :). I don't know how clumsy it is, but it works :)

let na = Math.abs(angle)
        if (na > 90) na = 90 - (na - 90)
        let an = Math.PI * na / 180

        let nwl = width * Math.cos(an)
        let nhl = width * Math.sin(an)
        let nhu = height * Math.cos(an)
        let nwr = height * Math.sin(an)

        return [nwl + nwr, nhu + nhl]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question