C# 如何使用Brep对象的一个面与XY、XZ或YZ平面平行对齐?
我试过几种可能性,但都做不好。在C# 如何使用Brep对象的一个面与XY、XZ或YZ平面平行对齐?,c#,eyeshot,C#,Eyeshot,我试过几种可能性,但都做不好。在SelectionChanged上,我从选定的面创建一个平面。这很好,我可以正确地得到平面 var item = e.AddedItems[0]; if (item is Model.SelectedFace) { var faceItem = ((Model.SelectedFace)item);
SelectionChanged
上,我从选定的面创建一个平面。这很好,我可以正确地得到平面
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]);
}
}
}
正确计算选定面的平面
和平面.XY、平面.XZ和平面.YZ之间的xyteta、xzTheta和yzTheta
。就这个问题而言,我只展示了下面的xyteta
(我已经尝试将其与变换矩阵一起使用,但效果也不好。因此,它的目的只是让我检查两个平面之间的角度是否正确
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
只能正确地进行平移
,而不能进行旋转
。例如,变换后,我的对象在平面
和平面.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);
}
现在工作还是不工作
TransformBy(转换);这是错误的
TransformBy(transXY);如果其他一切正常,则这是正确的
关于平面。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();
}
}
}
干杯!谢谢你的帮助。这是一个打字错误,但不是转换的问题