首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >bezier曲面中的自动内边

bezier曲面中的自动内边
EN

Stack Overflow用户
提问于 2014-05-02 16:43:24
回答 2查看 558关注 0票数 1

通常,Bezier曲面作为双三次曲面,有16个控制点。然而,在3 3dsMax中,内部边缘可以被隐藏起来以避免编辑和计算自动 (这是它们的默认状态)。这只剩下12个控制点,这使得编辑变得更简单。

XNA的Primitives3D样本项目代码(简化):

代码语言:javascript
复制
void CreatePatchVertices(Vector3[] patch, int tessellation)
{
    Debug.Assert(patch.Length == 16);

    for (int i = 0; i <= tessellation; i++)
    {
        float ti = (float)i / tessellation;

        for (int j = 0; j <= tessellation; j++)
        {
            float tj = (float)j / tessellation;

            // Perform four horizontal bezier interpolations
            // between the control points of this patch.
            Vector3 p1 = Bezier(patch[0], patch[1], patch[2], patch[3], ti);
            Vector3 p2 = Bezier(patch[4], patch[5], patch[6], patch[7], ti);
            Vector3 p3 = Bezier(patch[8], patch[9], patch[10], patch[11], ti);
            Vector3 p4 = Bezier(patch[12], patch[13], patch[14], patch[15], ti);

            // Perform a vertical interpolation between the results of the
            // previous horizontal interpolations, to compute the position.
            Vector3 position = Bezier(p1, p2, p3, p4, tj);

            // Perform another four bezier interpolations between the control
            // points, but this time vertically rather than horizontally.
            Vector3 q1 = Bezier(patch[0], patch[4], patch[8], patch[12], tj);
            Vector3 q2 = Bezier(patch[1], patch[5], patch[9], patch[13], tj);
            Vector3 q3 = Bezier(patch[2], patch[6], patch[10], patch[14], tj);
            Vector3 q4 = Bezier(patch[3], patch[7], patch[11], patch[15], tj);

            // Compute vertical and horizontal tangent vectors.
            Vector3 tangentA = BezierTangent(p1, p2, p3, p4, tj);
            Vector3 tangentB = BezierTangent(q1, q2, q3, q4, ti);

            // Cross the two tangent vectors to compute the normal.
            Vector3 normal = Vector3.Cross(tangentA, tangentB);
            normal.Normalize();

            // Create the vertex.
            AddVertex(position, normal);
        }
    }
}

在此示例中,如何计算矢量5、6、9和10 (patch[5]等)自动的,就像3 3dsMax那样?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-05-05 12:47:38

看起来3ds Max构建了一个平行四边形来获取内部点。

代码语言:javascript
复制
patch[5] = patch[0] + (patch[1] - patch[0]) + (patch[4] - patch[0]);
patch[5] = patch[1] + patch[4] - patch[0];

以及整个功能:

代码语言:javascript
复制
void CreatePatchVertices(Vector3[] s, int tessellation, bool isMirrored)
{
    Debug.Assert(s.Length == 16);

    for (int i = 0; i <= tessellation; i++)
    {
        float ti = (float)i / tessellation;

        for (int j = 0; j <= tessellation; j++)
        {
            float tj = (float)j / tessellation;

            // Compute automatic interior edges.
            s[5] = s[1] + s[4] - s[0];
            s[6] = s[2] + s[7] - s[3];
            s[9] = s[8] + s[13] - s[12];
            s[10] = s[11] + s[14] - s[15];

            // Perform four horizontal bezier interpolations
            // between the control points of this patch.
            Vector3 p1 = Bezier(s[0], s[1], s[2], s[3], ti);
            Vector3 p2 = Bezier(s[4], s[5], s[6], s[7], ti);
            Vector3 p3 = Bezier(s[8], s[9], s[10], s[11], ti);
            Vector3 p4 = Bezier(s[12], s[13], s[14], s[15], ti);

            // Perform a vertical interpolation between the results of the
            // previous horizontal interpolations, to compute the position.
            Vector3 position = Bezier(p1, p2, p3, p4, tj);

            // Perform another four bezier interpolations between the control
            // points, but this time vertically rather than horizontally.
            Vector3 q1 = Bezier(s[0], s[4], s[8], s[12], tj);
            Vector3 q2 = Bezier(s[1], s[5], s[9], s[13], tj);
            Vector3 q3 = Bezier(s[2], s[6], s[10], s[14], tj);
            Vector3 q4 = Bezier(s[3], s[7], s[11], s[15], tj);

            // Compute vertical and horizontal tangent vectors.
            Vector3 tangentA = BezierTangent(p1, p2, p3, p4, tj);
            Vector3 tangentB = BezierTangent(q1, q2, q3, q4, ti);

            // Cross the two tangent vectors to compute the normal.
            Vector3 normal = Vector3.Cross(tangentA, tangentB);
            normal.Normalize();

            // Create the vertex.
            AddVertex(position, normal);
        }
    }
}

在3ds Max和Primitives3D示例中,具有自动内部点的茶壶原语就是这样的:

票数 0
EN

Stack Overflow用户

发布于 2014-05-06 20:05:41

这个答案必须是多余的,但我想提醒您注意另一种构造贝塞尔曲面的方法,称为https://en.wikipedia.org/wiki/Coons_patch。Coons曲面只使用边界曲线,向双三次曲面的转换是非常直接的。

我建议这样做的原因是,它是为了精确地外推汽车设计中典型的边界特征线,并自动计算内部点(对于双三次bezier贴片)或镶嵌。

给出了bu0、bu1、bv0、bv1四条边界曲线;

代码语言:javascript
复制
bu0, bu1  // boundaries in u direction u <- [0, 1]
bv0, bv1  // in v direction  v <- [0, 1]
// bu0, bu1, bv0, bv1 are arrays of bezier coefficients

coons曲面上的内点和点可以通过分别求u和v方向的直纹曲面和u和v的双线性插值来求出。

代码语言:javascript
复制
// In matrix form, so that you can reduce it all together

                      ⎡        ⎤
ruled_u = [ (1-u) u ] ⎜ bv0(v) ⎟
                      ⎜ bv1(v) ⎟
                      ⎣        ⎦ 

// Similarly
                      ⎡        ⎤
ruled_v = [ (1-v) v ] ⎜ bu0(u) ⎟
                      ⎜ bu1(u) ⎟
                      ⎣        ⎦ 

// Assuming cubic bezier curves as boundary, if you select appropriate control point 
// instead of bv0(u) etc, i.e. bv0[1] for u = 1/3 and bv0[2] for u = 2/3, we can convert
// a coons patch into a bicubic patch, instead of evaluating the point on surface directly

                          ⎡               ⎤ ⎡         ⎤
bilinear_uv = [ (1-u) u ] ⎜ bu0(0) bu0(1) ⎟ ⎜ (1 - v) ⎟
                          ⎜ bu1(0) bu1(1) ⎟ ⎜    v    ⎟
                          ⎣               ⎦ ⎣         ⎦

// Then the 'interior' point at u and v is
Coons (u, v) = ruled_u + ruled_v - bilinear_uv

在coons补丁中,内部控制点可以计算为

代码语言:javascript
复制
Coons(1/3, 1/3)
Coons(1/3, 2/3)
Coons(2/3, 1/3)
Coons(2/3, 2/3)

在上述方程中,只选择1/3的bv01而不是bv0(1/3)等。

在Coons贴片中,插值比线性插值边界控制点更自然。在我的经验中也更“正确”。不仅在美学上,而且在参试后也是如此。

最近,我不得不在LCH颜色空间中生成逼近sRGB色域的bezier曲面。它只是一个转换和扭曲的RGB立方体。我所拥有的只是斑块的边界。仅使用线性插值时,内部值是错误的。最后,coons补丁给出的误差最小。

这里是从一个集合coons补丁中生成的双三次曲面的示例。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23433087

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档