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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more