我能得到我的細節跨越的中點鏡像ViewSection.CropBox
但它相當複雜。我發現ViewSection.Origin
是項目座標系統中的一個點。另一方面,ViewSection.CropBox
不會在項目座標系中給出它的最小值和最大值,而是會給出CropBox相對於ViewSection.Origin
的位置。使用ViewSection.Origin
和ViewSection.CropBox
,您可以計算項目座標系中ViewSection.CropBox
的最小值和最大值。最後,您需要使用最小值和最大值來查找ViewSection.CropBox
的中點,然後在該點上進行鏡像。
下面是我使用,使我能找到的最小和最大使用單一功能
public enum PointComponent
{
Invalid,
X,
Y,
Z
}
public enum MinOrMax
{
Invalid,
Min,
Max
}
這裏的函數查找最小或最大的X,Y或Z分量一些輔助類裁剪框:
private double GetSectionCropBoxOrigin(ViewSection section,
PointComponent pointComponent, MinOrMax minOrMax)
{
double cropBoxOrigin;
double sectionOrigin, viewDirection, upDirection, rightDirection;
switch (pointComponent)
{
case PointComponent.X:
sectionOrigin = section.Origin.X;
viewDirection = section.ViewDirection.X;
upDirection = section.UpDirection.X;
rightDirection = section.RightDirection.X;
break;
case PointComponent.Y:
sectionOrigin = section.Origin.Y;
viewDirection = section.ViewDirection.Y;
upDirection = section.UpDirection.Y;
rightDirection = section.RightDirection.Y;
break;
case PointComponent.Z:
sectionOrigin = section.Origin.Z;
viewDirection = section.ViewDirection.Z;
upDirection = section.UpDirection.Z;
rightDirection = section.RightDirection.Z;
break;
default:
throw new InvalidOperationException();
}
double cropX, cropY;
switch (minOrMax)
{
case MinOrMax.Min:
cropX = section.CropBox.Min.X;
cropY = section.CropBox.Min.Y;
break;
case MinOrMax.Max:
cropX = section.CropBox.Max.X;
cropY = section.CropBox.Max.Y;
break;
default:
throw new InvalidOperationException();
}
if (Math.Abs(viewDirection) == 1)
cropBoxOrigin = sectionOrigin;
else if (Math.Abs(upDirection) == 1)
cropBoxOrigin = sectionOrigin + (cropY * upDirection);
else if (Math.Abs(rightDirection) == 1)
cropBoxOrigin = sectionOrigin + (cropX * rightDirection);
else
throw new InvalidOperationException();
return cropBoxOrigin;
}
注意,對於PointComponent.Z
我們不使用最小值和最大值之間的中點,而是使用原點。這是因爲我們的細節工作僅存在於2D中,即使我們指定了深度CropBox
並且細節工作與ViewSection.Origin
的深度相同。
下面是我用得到的中點代碼:
private XYZ Get3dMidpoint(XYZ start, XYZ end)
{
double x = (start.X + end.X)/2.0;
double y = (start.Y + end.Y)/2.0;
double z = (start.Z + end.Z)/2.0;
return new XYZ(x, y, z);
}
最後下面的代碼把它一起,並得到了鏡面:
XYZ cropBoxMinInGlobalCoordinates = new XYZ(
GetSectionCropBoxOrigin(section, PointComponent.X, MinOrMax.Min),
GetSectionCropBoxOrigin(section, PointComponent.Y, MinOrMax.Min),
GetSectionCropBoxOrigin(section, PointComponent.Z, MinOrMax.Min)
);
XYZ cropBoxMaxInGlobalCoordinates = new XYZ(
GetSectionCropBoxOrigin(section, PointComponent.X, MinOrMax.Max),
GetSectionCropBoxOrigin(section, PointComponent.Y, MinOrMax.Max),
GetSectionCropBoxOrigin(section, PointComponent.Z, MinOrMax.Max)
);
XYZ cropBoxOriginInGlobalCoordinates =
Get3dMidpoint(cropBoxMinInGlobalCoordinates, cropBoxMaxInGlobalCoordinates);
Plane mirrorPlane =
Plane.CreateByNormalAndOrigin(section.RightDirection, cropBoxOriginInGlobalCoordinates);