四面体的重心坐标 [英] Barycentric coordinates of a tetrahedron

查看:260
本文介绍了四面体的重心坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想寻求有关四面体的重心坐标的帮助:

I would like to ask for help regarding barycentric coordinates of a tetrahedron:

按照我在这里找到的方法:
http://www.cdsimpson.net/2014/10/barycentric-coordinates.html
i实现了C ++函数,用于查找四面体中点的重心坐标:

Following an approach I found here: http://www.cdsimpson.net/2014/10/barycentric-coordinates.html i implemented a C++ function for finding barycentric coordinates of a point in a tetrahedron:

float ScTP(const Vec &a, const Vec &b, const Vec &c)
{
    // computes scalar triple product
    return Dot(a, Cross(b, c));
}

Vec4f bary_tet(Vec3f a, Vec3f b, Vec3f c, Vec3f d, Vec3f p)
{
    float va, vb, vc, vd, v;
    Vec3f vap = p - a;
    Vec3f vbp = p - b;
    Vec3f vcp = p - c;
    Vec3f vdp = p - d;

    Vec3f vab = b - a;
    Vec3f vac = c - a;
    Vec3f vad = d - a;

    Vec3f vbc = c - b;
    Vec3f vbd = d - b;
    // ScTP computes the scalar triple product
    va = ScTP(vbp, vbd, vbc) * 1 / 6;
    vb = ScTP(vap, vac, vad) * 1 / 6;
    vc = ScTP(vap, vad, vab) * 1 / 6;
    vd = ScTP(vap, vab, vac) * 1 / 6;
    v = 1 / ScTP(vab, vac, vad) * 1 / 6;
    return Vec4f(va*v, vb*v, vc*v, vd*v);
}

但是,我的代码似乎计算的重心坐标略有错误-
将我的结果与此处的参考实现进行比较:
http://dennis2society.de/painless -tetrahedral-barycentric-mapping
我的四个重心值分别小于参考实现中
计算的值。

However, my code seems to calculate slightly wrong barycentric coordinates - comparing my results with a reference implementation from here: http://dennis2society.de/painless-tetrahedral-barycentric-mapping my four barycentric values are each smaller the values calculated by the reference implementation.

有人吗?在实现中发现任何错误?非常感谢您的帮助!

Does anyone spot any error in my implementation? Many thanks for help!

推荐答案

盲目猜测:

Vec4f bary_tet(const Vec3f & a, const Vec3f & b, const Vec3f & c, const Vec3f & d, const Vec3f & p)
{
    Vec3f vap = p - a;
    Vec3f vbp = p - b;

    Vec3f vab = b - a;
    Vec3f vac = c - a;
    Vec3f vad = d - a;

    Vec3f vbc = c - b;
    Vec3f vbd = d - b;
    // ScTP computes the scalar triple product
    float va6 = ScTP(vbp, vbd, vbc);
    float vb6 = ScTP(vap, vac, vad);
    float vc6 = ScTP(vap, vad, vab);
    float vd6 = ScTP(vap, vab, vac);
    float v6 = 1 / ScTP(vab, vac, vad);
    return Vec4f(va6*v6, vb6*v6, vc6*v6, vd6*v6);
}

这篇关于四面体的重心坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆