Виды проекций

Виды проекций

Параллельная проекция

Проецирующие лучи параллельны друг другу

Ортогональная

Лучи перпендикулярны плоскости проекции

Косоугольная

Лучи наклонены к плоскости проекции

Прямоугольная аксонометрия

Сокращение по осям:

Изометрия три одинаковых масштаба
Диметрия два одинаковых масштаба
Триметрия три разных масштаба

Центральная проекция

Проецирующие лучи проходят через общий центр

Перспективная

Удалённые части объекта выглядят меньше

Точки схода

Число направлений рёбер с конечной точкой схода:

Одноточечная
Двухточечная
Трёхточечная

Виды проекций

Программа показывает один 3D-объект одновременно в ортогональной, косоугольной (параллельные) и центральной проекциях. Можно выбрать куб, домик или ракету и повернуть модель ползунками или мышью

Частные случаи (количество точек схода, аксонометрия) вынесены отдельно ниже

Всё сделано на three js через выбор положения камеры и её тип. Разве что для косоугольной проекции пришлось модифицировать элементы projectionMatrix перспективной камеры, добавив смещение в зависимости от глубины

Библиотека подключается с cgraph.ru

JS-исходник: 
<style>
* {
    box-sizing: border-box;
    margin: 0;
}
body {
    color: #202c32;
    font: 14px system-ui, sans-serif;
}
main {
    max-width: 1440px;
    margin: auto;
    padding: 40px 32px;
}
h1 {
    margin-bottom: 24px;
}
p {
    margin: 8px 0 16px;
    color: #59666a;
    line-height: 1.4;
}
button, select, input {
    font: inherit;
    cursor: pointer;
}
button, select {
    padding: 8px;
}
.controls {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: 24px;
    padding: 16px 0 24px;
}
.controls label {
    font-size: 13px;
}
.slider {
    flex: 1;
    min-width: 120px;
}
.controls input, .controls select {
    display: block;
    width: 100%;
    margin-top: 8px;
}
.controls output {
    float: right;
}
input[type="range"] {
    accent-color: #416d7c;
}
.groups, .parallel-views, .example-grid {
    display: grid;
    gap: 16px;
}
.groups, .parallel-views {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}
.groups {
    gap: 40px;
}
.groups, .examples {
    padding-top: 24px;
    border-top: 1px solid #dfe5e3;
}
.main-views p {
    min-height: 38px;
}
.view {
    height: 240px;
    background: #f2f4f3;
    cursor: grab;
    touch-action: none;
}
canvas {
    display: block;
    width: 100%;
    height: 100%;
}
.examples {
    margin-top: 32px;
}
.example-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}
figure canvas {
    height: 144px;
    background: #f6f7f6;
}
figcaption {
    margin-top: 8px;
    font-weight: 600;
}
figcaption span {
    display: block;
    color: #69797c;
    font-size: 12px;
    font-weight: normal;
}
@media (max-width: 850px) {
    main {
        padding: 24px 20px;
    }
    .groups {
        grid-template-columns: 1fr;
    }
}
@media (max-width: 420px) {
    .parallel-views {
        grid-template-columns: 1fr;
    }
}
</style>
<main>
    <h1>Виды проекций</h1>
    <div class="controls">
        <label>Объект
            <select id="object">
                <option value="cube">Куб</option>
                <option value="house">Домик</option>
                <option value="rocket">Ракета</option>
            </select>
        </label>
        <label class="slider">Поворот <output id="turn-value">0°</output>
            <input id="turn" type="range" min="-180" max="180" step="0.1" value="0">
        </label>
        <label class="slider">Наклон <output id="tilt-value">0°</output>
            <input id="tilt" type="range" min="-90" max="90" step="0.1" value="0">
        </label>
        <button id="animate" type="button" aria-pressed="false">Вращать</button>
        <button id="reset" type="button">Сбросить</button>
    </div>
    <div class="groups">
        <section class="group">
            <h2>Параллельная проекция</h2>
            <p class="group-description">Проецирующие лучи параллельны друг другу</p>
            <div class="main-views parallel-views">
                <article><h3>Ортогональная</h3><p>Лучи перпендикулярны плоскости проекции</p><div class="view" id="view-0"></div></article>
                <article><h3>Косоугольная</h3><p>Лучи наклонены к плоскости проекции</p><div class="view" id="view-1"></div></article>
            </div>
            <div class="examples">
                <h3>Прямоугольная аксонометрия</h3>
                <p>Сокращение по осям:</p>
                <div class="example-grid">
                    <figure><canvas id="example-0"></canvas><figcaption>Изометрия <span>три одинаковых масштаба</span></figcaption></figure>
                    <figure><canvas id="example-1"></canvas><figcaption>Диметрия <span>два одинаковых масштаба</span></figcaption></figure>
                    <figure><canvas id="example-2"></canvas><figcaption>Триметрия <span>три разных масштаба</span></figcaption></figure>
                </div>
            </div>
        </section>
        <section class="group">
            <h2>Центральная проекция</h2>
            <p class="group-description">Проецирующие лучи проходят через общий центр</p>
            <div class="main-views central-view">
                <article><h3>Перспективная</h3><p>Удалённые части объекта выглядят меньше</p><div class="view" id="view-2"></div></article>
            </div>
            <div class="examples">
                <h3>Точки схода</h3>
                <p>Число направлений рёбер с конечной точкой схода:</p>
                <div class="example-grid">
                    <figure><canvas id="example-3"></canvas><figcaption>Одноточечная</figcaption></figure>
                    <figure><canvas id="example-4"></canvas><figcaption>Двухточечная</figcaption></figure>
                    <figure><canvas id="example-5"></canvas><figcaption>Трёхточечная</figcaption></figure>
                </div>
            </div>
        </section>
    </div>
</main>
<script src="<a href="https://cgraph.ru/files/lib/three.min.js"></script>
<script>
const">https://cgraph.ru/files/lib/three.min.js"></script>
<script>
const</a> objectInput = document.getElementById("object");
const turnInput = document.getElementById("turn");
const tiltInput = document.getElementById("tilt");
const turnOut = document.getElementById("turn-value");
const tiltOut = document.getElementById("tilt-value");
const playButton = document.getElementById("animate");
const resetButton = document.getElementById("reset");
 
const scene = new THREE.Scene();
scene.add(new THREE.AmbientLight(0xffffff, 0.8));
const light = new THREE.DirectionalLight(0xffffff, 0.8);
light.position.set(4, 7, 6);
scene.add(light);
const fillLight = new THREE.DirectionalLight(0xe5f2ec, 0.35);
fillLight.position.set(-4, 1, -5);
scene.add(fillLight);
 
const model = new THREE.Group();
scene.add(model);
let rotating = false;
let prevTime = 0;
 
function makeMaterial(color) {
    return new THREE.MeshStandardMaterial({ color: color, roughness: 0.8 });
}
 
function addPart(group, geometry, color, x, y, z) {
    const part = new THREE.Mesh(geometry, makeMaterial(color));
    part.position.set(x, y, z);
    group.add(part);
    return part;
}
 
function makeHouse() {
    const house = new THREE.Group();
    addPart(house, new THREE.BoxGeometry(2, 1.55, 1.7), 0xe3c69c, 0, -0.25, 0);
    const roof = addPart(house, new THREE.ConeGeometry(1.72, 1.1, 4), 0xc86e59, 0, 1.05, 0);
    roof.rotation.y = Math.PI / 4;
    addPart(house, new THREE.BoxGeometry(0.46, 0.85, 0.08), 0x956f5b, 0, -0.59, 0.89);
    for (let x of [-0.62, 0.62]) {
        addPart(house, new THREE.BoxGeometry(0.42, 0.42, 0.08), 0x76adbb, x, -0.05, 0.89);
        addPart(house, new THREE.BoxGeometry(0.42, 0.42, 0.08), 0x76adbb, x, -0.05, -0.89);
    }
    addPart(house, new THREE.BoxGeometry(0.28, 0.6, 0.3), 0xa55c4a, 0.65, 1.45, -0.35);
    return house;
}
 
function makeRocket() {
    const rocket = new THREE.Group();
    addPart(rocket, new THREE.CylinderGeometry(0.55, 0.55, 5, 24), 0xe5e9df, 0, 0, 0);
    addPart(rocket, new THREE.ConeGeometry(0.55, 0.8, 24), 0xd27460, 0, 2.9, 0);
    addPart(rocket, new THREE.SphereGeometry(0.25, 20, 14), 0x70aeba, 0, 1.1, 0.51);
    for (let i = 0; i < 4; i++) {
        const fin = addPart(rocket, new THREE.BoxGeometry(0.55, 0.8, 0.12), 0xd27460, 0, -2.2, 0);
        const angle = i * Math.PI / 2;
        fin.position.x = Math.cos(angle) * 0.62;
        fin.position.z = Math.sin(angle) * 0.62;
        fin.rotation.y = -angle;
    }
    addPart(rocket, new THREE.ConeGeometry(0.3, 0.65, 16), 0xeab35d, 0, -2.8, 0).rotation.z = Math.PI;
    return rocket;
}
 
function makeCube() {
    const colors = [0xd97862, 0xe4b97c, 0x84b69d, 0x568e86, 0x80b5c1, 0xb1a1c4];
    const cube = new THREE.Mesh(new THREE.BoxGeometry(2, 2, 2), colors.map(makeMaterial));
    const group = new THREE.Group();
    group.add(cube);
    return group;
}
 
function chooseObject() {
    while (model.children.length) {
        const old = model.children[0];
        model.remove(old);
        old.traverse(function (part) {
            if (part.geometry) part.geometry.dispose();
            if (part.material) {
                const mats = Array.isArray(part.material) ? part.material : [part.material];
                for (let item of mats) item.dispose();
            }
        });
    }
    const makeObject = { house: makeHouse, rocket: makeRocket, cube: makeCube };
    model.add(makeObject[objectInput.value]());
}
 
const example = makeCube();
example.visible = false;
scene.add(example);
 
function makeView(id) {
    const box = document.getElementById(id);
    const renderer = new THREE.WebGLRenderer({ antialias: true });
    renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
    renderer.setClearColor(0xf2f4f3, 1);
    box.appendChild(renderer.domElement);
    return {
        box, renderer,
        ortho: new THREE.OrthographicCamera(-2, 2, 2, -2, 0.1, 100),
        perspective: new THREE.PerspectiveCamera(40, 1, 0.1, 100),
        camera: null
    };
}
 
const views = [makeView("view-0"), makeView("view-1"), makeView("view-2")];
const config = [
    { type: "ortho", position: [0, 0, 9] },
    { type: "oblique", depth: 0.5, position: [0, 0, 9] },
    { type: "perspective", position: [0, 0, 7.5] }
];
 
const examples = [
    { type: "ortho", position: [6, 6, 6] },
    { type: "ortho", position: [7, 4, 7] },
    { type: "ortho", position: [8, 5, 3] },
    { type: "perspective", position: [0, 0, 7.5] },
    { type: "perspective", position: [6, 0, 8] },
    { type: "perspective", position: [6, 5, 8] }
];
const exampleRender = new THREE.WebGLRenderer({ antialias: true, preserveDrawingBuffer: true });
exampleRender.setPixelRatio(1);
exampleRender.setClearColor(0xf6f7f6, 1);
const exampleView = {
    renderer: exampleRender,
    ortho: new THREE.OrthographicCamera(-2, 2, 2, -2, 0.1, 100),
    perspective: new THREE.PerspectiveCamera(40, 1, 0.1, 100),
    camera: null
};
 
function setCamera(view, config, rocket = false) {
    const width = view.box.clientWidth, height = view.box.clientHeight;
    if (!width || !height) return;
    view.renderer.setSize(width, height, false);
    const aspect = width / height;
    const camera = config.type === "perspective" ? view.perspective : view.ortho;
    view.camera = camera;
    camera.position.set(...config.position);
    camera.up.set(...(config.up || [0, 1, 0]));
    camera.lookAt(0, 0, 0);
 
    if (config.type === "perspective") {
        camera.fov = rocket ? 60 : 40;
        camera.aspect = aspect;
        camera.updateProjectionMatrix();
    } else {
        const size = rocket ? 4.1 : 2.45;
        camera.left = -size * aspect;
        camera.right = size * aspect;
        camera.top = size;
        camera.bottom = -size;
        camera.updateProjectionMatrix();
 
        if (config.type === "oblique") {
            const shift = config.depth / Math.sqrt(2);
            const matrix = camera.projectionMatrix.elements;
            matrix[8] = -shift * matrix[0];
            matrix[9] = -shift * matrix[5];
            // Компенсируем расстояние до камеры: центр модели остаётся в центре экрана
            matrix[12] -= shift * matrix[0] * config.position[2];
            matrix[13] -= shift * matrix[5] * config.position[2];
            camera.projectionMatrixInverse.getInverse(camera.projectionMatrix);
        }
    }
}
 
function updateCameras() {
    const rocket = objectInput.value === "rocket";
    for (let i = 0; i < views.length; i++) setCamera(views[i], config[i], rocket);
    drawExamples();
}
 
function drawPointExample(canvas, base, axes) {
    const ctx = canvas.getContext("2d");
 
    function project(x, y, z) {
        let px = base.x, py = base.y, w = 1;
        for (let i = 0; i < 3; i++) {
            const value = [x, y, z][i];
            const axis = axes[i];
            if (axis.point) {
                const a = axis.part / (1 - axis.part);
                px += value * a * axis.point.x;
                py += value * a * axis.point.y;
                w += value * a;
            } else {
                px += value * axis.dx;
                py += value * axis.dy;
            }
        }
        return { x: px / w, y: py / w };
    }
 
    function line(from, to) {
        ctx.moveTo(from.x, from.y);
        ctx.lineTo(to.x, to.y);
    }
 
    const p = [];
    for (let x = 0; x < 2; x++) {
        for (let y = 0; y < 2; y++) {
            for (let z = 0; z < 2; z++) p[x * 4 + y * 2 + z] = project(x, y, z);
        }
    }
 
    ctx.strokeStyle = "#406d78";
    ctx.lineWidth = 1.5;
    ctx.lineJoin = "round";
    ctx.beginPath();
    for (let x = 0; x < 2; x++) {
        for (let y = 0; y < 2; y++) {
            for (let z = 0; z < 2; z++) {
                const i = x * 4 + y * 2 + z;
                if (x === 0) line(p[i], p[i + 4]);
                if (y === 0) line(p[i], p[i + 2]);
                if (z === 0) line(p[i], p[i + 1]);
            }
        }
    }
    ctx.stroke();
 
    ctx.setLineDash([3, 3]);
    ctx.strokeStyle = "#9aafa9";
    ctx.beginPath();
    for (let i = 0; i < 3; i++) {
        const axis = axes[i];
        if (!axis.point) continue;
        for (let a = 0; a < 2; a++) {
            for (let b = 0; b < 2; b++) {
                const v = i === 0 ? p[4 + a * 2 + b] : i === 1 ? p[a * 4 + 2 + b] : p[a * 4 + b * 2 + 1];
                line(v, axis.point);
            }
        }
    }
    ctx.stroke();
    ctx.setLineDash([]);
 
    ctx.fillStyle = "#406d78";
    ctx.font = "12px system-ui";
    for (let axis of axes) {
        if (!axis.point) continue;
        ctx.beginPath();
        ctx.arc(axis.point.x, axis.point.y, 3, 0, Math.PI * 2);
        ctx.fill();
        ctx.fillText(axis.label, axis.point.x + axis.labelX, axis.point.y + axis.labelY);
    }
}
 
function drawOnePoint(canvas) {
    const w = canvas.width, h = canvas.height;
    drawPointExample(canvas, { x: w * 0.12, y: h * 0.73 }, [
        { dx: w * 0.29, dy: 0 },
        { dx: 0, dy: -h * 0.43 },
        { point: { x: w * 0.84, y: h * 0.24 }, part: 0.48, label: "Тс₁", labelX: -8, labelY: -8 }
    ]);
}
 
function drawTwoPoints(canvas) {
    const w = canvas.width, h = canvas.height;
    drawPointExample(canvas, { x: w * 0.5, y: h * 0.74 }, [
        { point: { x: w * 0.08, y: h * 0.24 }, part: 0.32, label: "Тс₁", labelX: 5, labelY: -7 },
        { dx: 0, dy: -h * 0.42 },
        { point: { x: w * 0.92, y: h * 0.24 }, part: 0.32, label: "Тс₂", labelX: -20, labelY: -7 }
    ]);
}
 
function drawThreePoints(canvas) {
    const w = canvas.width, h = canvas.height;
    drawPointExample(canvas, { x: w * 0.5, y: h * 0.52 }, [
        { point: { x: w * 0.08, y: h * 0.14 }, part: 0.35, label: "Тс₁", labelX: 5, labelY: -7 },
        { point: { x: w * 0.92, y: h * 0.14 }, part: 0.35, label: "Тс₂", labelX: -20, labelY: -7 },
        { point: { x: w * 0.5, y: h * 0.92 }, part: 0.35, label: "Тс₃", labelX: 5, labelY: -7 }
    ]);
}
 
function drawExamples() {
    model.visible = false;
    example.visible = true;
    for (let i = 0; i < examples.length; i++) {
        const canvas = document.getElementById("example-" + i);
        const width = canvas.clientWidth, height = canvas.clientHeight;
        if (!width || !height) continue;
        canvas.width = width;
        canvas.height = height;
        if (i === 3) {
            drawOnePoint(canvas);
            continue;
        }
        if (i === 4) {
            drawTwoPoints(canvas);
            continue;
        }
        if (i === 5) {
            drawThreePoints(canvas);
            continue;
        }
        exampleView.box = canvas;
        setCamera(exampleView, examples[i]);
        exampleRender.render(scene, exampleView.camera);
        canvas.getContext("2d").drawImage(exampleRender.domElement, 0, 0, width, height);
    }
    model.visible = true;
    example.visible = false;
}
 
function updateView() {
    model.rotation.y = Number(turnInput.value) * Math.PI / 180;
    model.rotation.x = Number(tiltInput.value) * Math.PI / 180;
    turnOut.value = Math.round(Number(turnInput.value)) + "°";
    tiltOut.value = Math.round(Number(tiltInput.value)) + "°";
}
 
function setRotating(value) {
    rotating = value;
    playButton.textContent = value ? "Пауза" : "Вращать";
    playButton.setAttribute("aria-pressed", String(value));
}
 
objectInput.addEventListener("change", function () {
    chooseObject();
    updateCameras();
});
for (let input of [turnInput, tiltInput]) {
    input.addEventListener("input", function () {
        setRotating(false);
        updateView();
    });
}
playButton.addEventListener("click", function () { setRotating(!rotating); });
resetButton.addEventListener("click", function () {
    turnInput.value = 0;
    tiltInput.value = 0;
    setRotating(false);
    updateView();
});
window.addEventListener("resize", updateCameras);
 
for (let view of views) {
    let lastX = 0, lastY = 0, dragging = false;
    view.box.addEventListener("pointerdown", function (event) {
        dragging = true;
        lastX = event.clientX;
        lastY = event.clientY;
        view.box.setPointerCapture(event.pointerId);
        setRotating(false);
    });
    view.box.addEventListener("pointermove", function (event) {
        if (!dragging) return;
        turnInput.value = Number(turnInput.value) + (event.clientX - lastX) * 0.6;
        tiltInput.value = Number(tiltInput.value) + (event.clientY - lastY) * 0.6;
        lastX = event.clientX;
        lastY = event.clientY;
        updateView();
    });
    view.box.addEventListener("pointerup", function () { dragging = false; });
    view.box.addEventListener("pointercancel", function () { dragging = false; });
}
 
function animate(time) {
    const dt = prevTime ? Math.min((time - prevTime) / 1000, 0.05) : 0;
    prevTime = time;
    if (rotating) {
        let turn = Number(turnInput.value) + 15 * dt;
        if (turn > 180) turn -= 360;
        turnInput.value = turn;
        updateView();
    }
    for (let view of views) view.renderer.render(scene, view.camera);
    requestAnimationFrame(animate);
}
 
chooseObject();
updateView();
updateCameras();
requestAnimationFrame(animate);
</script>