将三角形和直线从3d映射到2d

时间:2019-04-08 22:24:20

标签: 3d geometry mapping 2d line

我在3d中有一个三角形和一条线,它们位于一个平面上。如何将5个点从3d映射到2d?

我可以将三角形转换为2d,但不能对直线进行相同操作。

Vector2[] ConvertTo2d(Vector3 a, Vector3 b, Vector3 c)
{
    var aN = new Vector2(0, 0);
    var bN = new Vector2(0, 0);
    bN.x = Mathf.Sqrt(Mathf.Pow(b.x - a.x, 2f) + Mathf.Pow(b.y - a.y, 2f) + Mathf.Pow(b.z - a.z, 2f));
    var cN = new Vector2(0, 0);
    cN.x = ((b.x - a.x) * (c.x - a.x) + 
            (b.y - a.y) * (c.y - a.y) + 
            (b.z - a.z) * (c.z - a.z)) / bN.x;
    cN.y = Mathf.Sqrt(Mathf.Pow(c.x - a.x, 2f) + Mathf.Pow(c.y - a.y, 2f) + Mathf.Pow(c.z - a.z, 2f) - Mathf.Pow(cN.x, 2f));

    return new[] {aN, bN, cN};
}

1 个答案:

答案 0 :(得分:1)

将其转换为代码即可使用!

let str =  `<body class="archive category category-basketball category-23872 content-sidebar">`;
let res = str.match(/category-[^\s0-9]+/g)
console.log(res)
var points = new Vector3[]
{
    triangleA,
    triangleB,
    triangleC,
    lineStart,
    lineEnd
};

var pointsIn2D = To2D(points);