在3D空间中拉伸三角形集合 [英] Extruding a triangle collection in 3D space

查看:103
本文介绍了在3D空间中拉伸三角形集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

谢谢您事先的帮助. :)

我一直在研究3D程序已经有一段时间了,它不使用DirectX或任何其他替代方法(作​​为一项技术挑战),在.NET框架中使用GDI +.到目前为止,它完全可以与基本照明一起使用,请浏览导航等内容.

到目前为止,在该程序中,当您手动选择任何3D世界中的三角形时,它将以黄色点亮.现在,我想在单击按钮时将该面/三角形集合挤出给定的整数值. (类似于Blender或3DS Max之类的程序)

我曾尝试使用Google搜索,但结果却被冰淇淋挤出机遮盖了:D:p

我想我要问的是正确方向的指针,或有关其背后数学的一些帮助.我可能缺少一些非常简单的内容.


在程序中
三角形结构只是3个位置向量的集合. (使用法线和幅值等方法的全部方法)

Hello,

Thank you for any help in advance. :)

I have been working on a 3D program for a while now that doesn''t use DirectX or any other alternative (As a technical challenge), Uses GDI+ in .NET framework. So far its fully working with basic lighting, walk around navigation e.t.c.

In the program so far when you make a manual selection of triangles in any 3D world it will illuminate them yellow. I would now like to extrude that face/triangle collection a given integer amount on a button click. (Similar to programs like blender or 3DS Max)

I have tried googling but my results are just clouded with ice-cream extruding machines :D :p

I suppose what i''m asking is pointers in the right direction or some help with the math behind it. I''m probably missing something quite simple.


In the program
Triangle structure is a just a collection of 3 location vectors. (With a whole load of methods for normal and magnitude and such like)

推荐答案

如果您只是问如何计算三角形的凸点,则原理是如下:

-必须对所有三角形(ABC)进行定向.
-计算三角形的法线向量.如果三角形的方向正确,则所有法线都将指向外部.如果它们都指向内部,则只需将所有三角形的ABC顺序更改为ACB.
-归一化此向量(不是必需的,但总是一个好主意) -点 A''(由 A 挤压)将为 A +正常,与 B''相同和 C''

三角形的法线可以使用叉积获得.像这样的东西:

If you are just asking how to compute the extruded points of a triangle then the principle is as follows:

- all your triangles (ABC) must be oriented.
- compute a normal vector for the triangle. If the triangles are properly oriented, all normals will point towards the exterior. If they all point to interior, then just change ABC order into ACB for all your triangles.
- normalize this vector (not necessary but always a good idea)
- point A'' (extruded of A) will be A + normal, and same for B'' and C''

The normal of a triangle can be obtained using cross product. Something like this:

//define a vector (will be used also for points)
struct Vector3
{
    public double X { get; set; }
    public double Y { get; set; }
    public double Z { get; set; }

    //default constructor
    public Vector3() {}
    //constructs a vector from 2 points
    public Vector3(Vector3 A, Vector3 B)
    {
        X = B.X - A.X;
        Y = B.Y - A.Y;
        Z = B.Z - A.Z;
    }

    //normalizes this vector
    public void Normalize()
    {
        float d = Math.Sqrt(X * X + Y * Y + Z * Z);
        if (d == 0)
            return;
        X /= d;
        Y /= d;
        Z /= d;
    }

    // returns the cross product between vectors u and v
    static public Vector3 CrossProduct(Vector3 u, Vector3 v)
    {
        Vector3 w = new Vector3();
        w.X = u.Y * v.Z - u.Z * v.Y;
        w.Y = u.Z * v.X - u.X * v.Z;
        w.Z = u.X * v.Y - u.Y * v.X;
        return w;
    }
}

//defines a face
struct Face
{
    public Vector3 A { get; set; }
    public Vector3 B { get; set; }
    public Vector3 C { get; set; }

    // returns a normalized normal vector
    // use this vector for your extrusion
    public Vector3 GetNormal()
    {
        Vector3 AB = new Vector3(A, B);
        Vector3 AC = new Vector3(A, C);
        Vector3 n = Vector3.CrossProduct(AB, AC);
        n.Normalize();
        return n;
    }
}


这篇关于在3D空间中拉伸三角形集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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