我尝试了几种可能的方法,但是我不能做对。在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);
}发布于 2020-11-21 14:21:22
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();
}
}
}干杯!
发布于 2020-11-18 05:09:27
现在行不行?
Ent.TransformBy(转换);这是错误的。
ent.TransformBy(transXY);如果其他方面都没问题,这是正确的。
问候
https://stackoverflow.com/questions/64830742
复制相似问题