Table of Contents
Isometric Projection
TL;DR
This blog post about isometric projection math and code.
From 2D
SR45⁰
Rotate and scale vertical direction with .
Preview
Math
Code
main.ts
const ANGLE = Math.PI / 4;
const SCALE = Math.tan(Math.PI / 6);
function sr45(x: number, y: number): [number, number] {
return [
x * Math.cos(ANGLE) - y * Math.sin(ANGLE),
(x * Math.sin(ANGLE) + y * Math.cos(ANGLE)) * SCALE,
];
}
SSR30⁰
Scale vertical direction with , Skew horizontal direction , Rotate .
Preview
Math
Code
main.ts
const ANGLE = Math.PI / 6;
const SCALE = Math.cos(ANGLE);
function scale(x: number, y: number): [number, number] {
return [x, y * SCALE];
}
function skew(x: number, y: number, angle: number): [number, number] {
return [x + y * Math.tan(angle), y];
}
function rotate(x: number, y: number, angle: number): [number, number] {
return [
x * Math.cos(angle) - y * Math.sin(angle),
x * Math.sin(angle) + y * Math.cos(angle),
];
}
From 3D
Projection
You can directly project 3D point to 2D point and swap the up axis easily.
Preview
Math
Code
main.ts
const ANGLE = Math.PI / 6;
function upY(x: number, y: number, z: number): [number, number] {
return [(x - z) * Math.cos(ANGLE), (x + z) * Math.sin(ANGLE) + y];
}
function upZ(x: number, y: number, z: number): [number, number] {
return [(x - y) * Math.cos(ANGLE), (x + y) * Math.sin(ANGLE) + z];
}