Published
Edited
Sep 11, 2021
Insert cell
# 常用插值函数
Insert cell
Insert cell
// 算重心坐标
// https://www.scratchapixel.com/lessons/3d-basic-rendering/rasterization-practical-implementation/rasterization-stage
function getBarycentricCoordinates(out, v0, v1, v2, p) {
let area = edgeFunction(v0, v1, v2); // area of the triangle multiplied by 2
let w0 = edgeFunction(v1, v2, p); // signed area of the triangle v1v2p multiplied by 2
let w1 = edgeFunction(v2, v0, p); // signed area of the triangle v2v0p multiplied by 2
let w2 = edgeFunction(v0, v1, p); // signed area of the triangle v0v1p multiplied by 2
// barycentric coordinates are the areas of the sub-triangles divided by the area of the main triangle
w0 /= area;
w1 /= area;
w2 /= area;

return vec3.set(out, w0, w1, w2);
}
Insert cell
glMatrix = require("https://bundle.run/gl-matrix@3.3.0")
Insert cell
vec3 = glMatrix.vec3
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more