Поверните эллипс на 3 оси в JavaScript, используя тангаж, рыскание и крен - PullRequest
0 голосов
/ 10 октября 2019

Я нашел полезную функцию для рисования эллипса с любой шириной и высотой. Есть ли способ заставить его выглядеть повернутым в 3D, отправив ему значения высоты тона, рыскания и крена?

function drawEllipse(ctx, x, y, w, h, pitch, yaw, roll, strokeColor) {
    var kappa = .5522848,
        ox = (w / 2) * kappa, // control point offset horizontal
        oy = (h / 2) * kappa, // control point offset vertical
        xe = x + w,           // x-end
        ye = y + h,           // y-end
        xm = x + w / 2,       // x-middle
        ym = y + h / 2;       // y-middle

    ctx.beginPath();
    ctx.strokeStyle = strokeColor
    ctx.moveTo(x, ym);

    // draw 4 quarters of the elipse
    // top left, top right, bottom right, bottom left
    /*
    cp1x
    The x-axis coordinate of the first control point.
    cp1y
    The y-axis coordinate of the first control point.
    cp2x
    The x-axis coordinate of the second control point.
    cp2y
    The y-axis coordinate of the second control point.
    x
    The x-axis coordinate of the end point.
    y
    The y-axis coordinate of the end point.
    */
    ctx.bezierCurveTo(x,       ym - oy, xm - ox, y,       xm, y);  // quarter 1
    ctx.bezierCurveTo(xm + ox, y,       xe,      ym - oy, xe, ym); // quarter 2
    ctx.bezierCurveTo(xe,      ym + oy, xm + ox, ye,      xm, ye); // quarter 3
    ctx.bezierCurveTo(xm - ox, ye,      x,       ym + oy, x,  ym); // quarter 4

    ctx.stroke();
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...