如何使用 Brep 对象的其中一个面与 XY、XZ 或 YZ 平面平行对齐?
How to align in parallel a Brep object using one of its face to XY, XZ, or YZ plane?
我尝试了几种可能性,但都做不好。在 SelectionChanged
上,我从选定的脸上创建了一个 plane
。这很好,我可以正确地得到plane
。
var item = e.AddedItems[0];
if (item is Model.SelectedFace)
{
var faceItem = ((Model.SelectedFace)item);
var ent = faceItem.Item;
if (ent is Brep)
{
var sol = (Brep)ent;
if (faceItem.ShellIndex == 0)
{
var mesh = sol.Faces[faceItem.Index].ConvertToMesh();
var plane = new Plane(mesh.Vertices[0], mesh.Vertices[1], mesh.Vertices[2]);
}
}
}
所选面的 plane
和 Plane.XY, Plane.XZ, & Plane.YZ
之间的 xyTheta, xzTheta, and yzTheta
计算正确。出于这个问题的目的,我只显示 xyTheta
如下(我已经尝试将它与 Transformation Matrix
一起使用,但它也没有很好地工作。因此它的目的只是让我检查之间的角度是否两个平面是正确的。
var x0 = plane.Equation.X; var y0 = plane.Equation.Y; var z0 = plane.Equation.Z;
var x1 = Plane.XY.Equation.X; var y1 = Plane.XY.Equation.Y; var z1 = Plane.XY.Equation.Z;
xyTheta = Math.Acos(Math.Abs(x0 * x1 + y0 * y1 + z0 * z1)
/ (Math.Sqrt(x0 * x0 + y0 * y0 + z0 * z0)
* Math.Sqrt(x1 * x1 + y1 * y1 + z1 * z1)));
我的转换 transXY
只能正确执行 Translation
而不能正确执行 Rotation
。例如,在变形后,我的物体在 plane
和 Plane.XY
之间仍然有 10 度的差异,尽管它被移动了。
transXY = new Transformation();
transXY.Rotation(plane, Plane.XY);
// transXZ = new Align3D(plane, Plane.XZ);
foreach (Entity ent in theModel.Entities)
{
ent.TransformBy(transXY);
}
现在能用吗???
ent.TransformBy(转换);这是错误的。
ent.TransformBy(transXY);其他没问题的话就对了
此致
plane.AxisX,Y,Z 似乎适用于变换矩阵。 **您的 BREP 必须转换回原点才能工作,因此通过与之前相反的转换将其移回原点。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using devDept.Eyeshot;
using devDept.Eyeshot.Entities;
using devDept.Geometry;
namespace EyeshotTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
makeSquare();
}
Solid3D square, square2;
Transformation trans2 = new Transformation(1);
int i = 0;
private void timer1_Tick(object sender, EventArgs e)
{
Mesh faceMesh = square2.Faces[i].ConvertToMesh();
var plane = new Plane(faceMesh.Vertices[0], faceMesh.Vertices[1], faceMesh.Vertices[2]);
Point3D origin = plane.Origin;
Vector3D xVec = plane.AxisX;
Vector3D yVec = plane.AxisY;
Vector3D zVec = plane.AxisZ;
trans2.Invert();
square.TransformBy(trans2);
trans2 = new Transformation(origin, xVec, yVec, zVec);
square.TransformBy(trans2);
viewportLayout1.Entities.Regen();
viewportLayout1.Invalidate();
i++;
if(i == 4) { i = 0; }
}
private void makeSquare()
{
square = Solid3D.CreateBox(5, 5, 5, 0.01);
square2 = Solid3D.CreateBox(5, 5, 5, 0.01);
viewportLayout1.Entities.Add(square, Color.Green);
viewportLayout1.Entities.Add(square2, Color.FromArgb(75, Color.Blue));
Transformation trans = new Transformation(new double[,]{
{-0.17,0.67,0.72, 47.33 },
{0.28,-0.67,0.69, 10.24 },
{0.95,0.32,-0.07, 15.98 },
{0,0,0,1 } });
square2.TransformBy(trans);
viewportLayout1.Invalidate();
}
}
}
干杯!
我尝试了几种可能性,但都做不好。在 SelectionChanged
上,我从选定的脸上创建了一个 plane
。这很好,我可以正确地得到plane
。
var item = e.AddedItems[0];
if (item is Model.SelectedFace)
{
var faceItem = ((Model.SelectedFace)item);
var ent = faceItem.Item;
if (ent is Brep)
{
var sol = (Brep)ent;
if (faceItem.ShellIndex == 0)
{
var mesh = sol.Faces[faceItem.Index].ConvertToMesh();
var plane = new Plane(mesh.Vertices[0], mesh.Vertices[1], mesh.Vertices[2]);
}
}
}
所选面的 plane
和 Plane.XY, Plane.XZ, & Plane.YZ
之间的 xyTheta, xzTheta, and yzTheta
计算正确。出于这个问题的目的,我只显示 xyTheta
如下(我已经尝试将它与 Transformation Matrix
一起使用,但它也没有很好地工作。因此它的目的只是让我检查之间的角度是否两个平面是正确的。
var x0 = plane.Equation.X; var y0 = plane.Equation.Y; var z0 = plane.Equation.Z;
var x1 = Plane.XY.Equation.X; var y1 = Plane.XY.Equation.Y; var z1 = Plane.XY.Equation.Z;
xyTheta = Math.Acos(Math.Abs(x0 * x1 + y0 * y1 + z0 * z1)
/ (Math.Sqrt(x0 * x0 + y0 * y0 + z0 * z0)
* Math.Sqrt(x1 * x1 + y1 * y1 + z1 * z1)));
我的转换 transXY
只能正确执行 Translation
而不能正确执行 Rotation
。例如,在变形后,我的物体在 plane
和 Plane.XY
之间仍然有 10 度的差异,尽管它被移动了。
transXY = new Transformation();
transXY.Rotation(plane, Plane.XY);
// transXZ = new Align3D(plane, Plane.XZ);
foreach (Entity ent in theModel.Entities)
{
ent.TransformBy(transXY);
}
现在能用吗???
ent.TransformBy(转换);这是错误的。
ent.TransformBy(transXY);其他没问题的话就对了
此致
plane.AxisX,Y,Z 似乎适用于变换矩阵。 **您的 BREP 必须转换回原点才能工作,因此通过与之前相反的转换将其移回原点。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using devDept.Eyeshot;
using devDept.Eyeshot.Entities;
using devDept.Geometry;
namespace EyeshotTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
makeSquare();
}
Solid3D square, square2;
Transformation trans2 = new Transformation(1);
int i = 0;
private void timer1_Tick(object sender, EventArgs e)
{
Mesh faceMesh = square2.Faces[i].ConvertToMesh();
var plane = new Plane(faceMesh.Vertices[0], faceMesh.Vertices[1], faceMesh.Vertices[2]);
Point3D origin = plane.Origin;
Vector3D xVec = plane.AxisX;
Vector3D yVec = plane.AxisY;
Vector3D zVec = plane.AxisZ;
trans2.Invert();
square.TransformBy(trans2);
trans2 = new Transformation(origin, xVec, yVec, zVec);
square.TransformBy(trans2);
viewportLayout1.Entities.Regen();
viewportLayout1.Invalidate();
i++;
if(i == 4) { i = 0; }
}
private void makeSquare()
{
square = Solid3D.CreateBox(5, 5, 5, 0.01);
square2 = Solid3D.CreateBox(5, 5, 5, 0.01);
viewportLayout1.Entities.Add(square, Color.Green);
viewportLayout1.Entities.Add(square2, Color.FromArgb(75, Color.Blue));
Transformation trans = new Transformation(new double[,]{
{-0.17,0.67,0.72, 47.33 },
{0.28,-0.67,0.69, 10.24 },
{0.95,0.32,-0.07, 15.98 },
{0,0,0,1 } });
square2.TransformBy(trans);
viewportLayout1.Invalidate();
}
}
}
干杯!