本文整理汇总了C#中XYZ.DotProduct方法的典型用法代码示例。如果您正苦于以下问题:C# XYZ.DotProduct方法的具体用法?C# XYZ.DotProduct怎么用?C# XYZ.DotProduct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XYZ
的用法示例。
在下文中一共展示了XYZ.DotProduct方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExportWallBase
//.........这里部分代码省略.........
Curve baseCurve = GetWallAxisAtBaseHeight(wallElement);
curve = GetWallTrimmedCurve(wallElement, baseCurve);
IFCRange curveBounds;
XYZ oldOrig;
GeometryUtil.GetAxisAndRangeFromCurve(curve, out curveBounds, out localXDir, out oldOrig);
localOrig = oldOrig;
if (baseCurve != null)
{
if (!validRange || (MathUtil.IsAlmostEqual(range.Start, zSpan.Start)))
{
XYZ newOrig = baseCurve.Evaluate(curveBounds.Start, false);
if (!validRange && (zSpan.Start < newOrig[2] - eps))
localOrig = new XYZ(localOrig.X, localOrig.Y, zSpan.Start);
else
localOrig = new XYZ(localOrig.X, localOrig.Y, newOrig[2]);
}
else
{
localOrig = new XYZ(localOrig.X, localOrig.Y, range.Start);
}
}
double dist = localOrig[2] - oldOrig[2];
if (!MathUtil.IsAlmostZero(dist))
{
XYZ moveVec = new XYZ(0, 0, dist);
curve = GeometryUtil.MoveCurve(curve, moveVec);
}
localYDir = localZDir.CrossProduct(localXDir);
// ensure that X and Z axes are orthogonal.
double xzDot = localZDir.DotProduct(localXDir);
if (!MathUtil.IsAlmostZero(xzDot))
localXDir = localYDir.CrossProduct(localZDir);
}
Transform orientationTrf = Transform.Identity;
orientationTrf.BasisX = localXDir;
orientationTrf.BasisY = localYDir;
orientationTrf.BasisZ = localZDir;
orientationTrf.Origin = localOrig;
using (IFCPlacementSetter setter = IFCPlacementSetter.Create(exporterIFC, element, null, orientationTrf, overrideLevelId))
{
IFCAnyHandle localPlacement = setter.GetPlacement();
Plane plane = new Plane(localXDir, localYDir, localOrig); // project curve to XY plane.
XYZ projDir = XYZ.BasisZ;
// two representations: axis, body.
{
if ((centerCurve != null) && (GeometryUtil.CurveIsLineOrArc(centerCurve)))
{
exportingAxis = true;
string identifierOpt = "Axis"; // IFC2x2 convention
string representationTypeOpt = "Curve2D"; // IFC2x2 convention
IFCGeometryInfo info = IFCGeometryInfo.CreateCurveGeometryInfo(exporterIFC, plane, projDir, false);
ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, curve, XYZ.Zero, true);
IList<IFCAnyHandle> axisItems = info.GetCurves();
if (axisItems.Count == 0)
{
示例2: CreateLocalPlacementFromOffset
/// <summary>
/// Creates or updates the IfcLocalPlacement associated with the current origin offset.
/// </summary>
/// <param name="exporterIFC">The exporter.</param>
/// <param name="bbox">The bounding box.</param>
/// <param name="ecData">The extrusion creation data which contains the local placement.</param>
/// <param name="lpOrig">The local placement origin.</param>
/// <param name="unscaledTrfOrig">The unscaled local placement origin.</param>
public void CreateLocalPlacementFromOffset(ExporterIFC exporterIFC, BoundingBoxXYZ bbox, IFCExtrusionCreationData ecData, XYZ lpOrig, XYZ unscaledTrfOrig)
{
if (ecData == null)
return;
IFCAnyHandle localPlacement = ecData.GetLocalPlacement();
if (!IFCAnyHandleUtil.IsNullOrHasNoValue(localPlacement))
{
IFCFile file = exporterIFC.GetFile();
// If the BBox passes through (0,0, 0), or no bbox, do nothing.
if (bbox == null ||
((bbox.Min.X < MathUtil.Eps() && bbox.Max.X > -MathUtil.Eps()) &&
(bbox.Min.Y < MathUtil.Eps() && bbox.Max.Y > -MathUtil.Eps()) &&
(bbox.Min.Z < MathUtil.Eps() && bbox.Max.Z > -MathUtil.Eps())))
{
if (!ecData.ReuseLocalPlacement)
ecData.SetLocalPlacement(ExporterUtil.CopyLocalPlacement(file, localPlacement));
return;
}
if (!MathUtil.IsAlmostZero(unscaledTrfOrig.DotProduct(unscaledTrfOrig)))
{
if (!ecData.ReuseLocalPlacement)
ecData.SetLocalPlacement(ExporterUtil.CreateLocalPlacement(file, localPlacement, lpOrig, null, null));
else
{
IFCAnyHandle relativePlacement = GeometryUtil.GetRelativePlacementFromLocalPlacement(localPlacement);
if (IFCAnyHandleUtil.IsNullOrHasNoValue(relativePlacement))
{
IFCAnyHandle newRelativePlacement = ExporterUtil.CreateAxis(file, lpOrig, null, null);
GeometryUtil.SetRelativePlacement(localPlacement, newRelativePlacement);
}
else
{
IFCAnyHandle newOriginHnd = ExporterUtil.CreateCartesianPoint(file, lpOrig);
IFCAnyHandleUtil.SetAttribute(relativePlacement, "Location", newOriginHnd);
}
}
}
else if (ecData.ForceOffset)
ecData.SetLocalPlacement(ExporterUtil.CreateLocalPlacement(file, localPlacement, null));
else if (!ecData.ReuseLocalPlacement)
ecData.SetLocalPlacement(ExporterUtil.CopyLocalPlacement(file, localPlacement));
}
}
示例3: ProjectPointToPlane
/// <summary>
/// Generates the UV value of a point projected to a plane, given an extrusion direction.
/// </summary>
/// <param name="plane">The plane.</param>
/// <param name="projDir">The projection direction.</param>
/// <param name="point">The point.</param>
/// <returns>The UV value.</returns>
public static UV ProjectPointToPlane(Plane plane, XYZ projDir, XYZ point)
{
XYZ zDir = plane.Normal;
double denom = projDir.DotProduct(zDir);
if (MathUtil.IsAlmostZero(denom))
return null;
XYZ xDir = plane.XVec;
XYZ yDir = plane.YVec;
XYZ orig = plane.Origin;
double distToPlane = ((orig - point).DotProduct(zDir)) / denom;
XYZ pointProj = distToPlane * projDir + point;
XYZ pointProjOffset = pointProj - orig;
UV pointProjUV = new UV(pointProjOffset.DotProduct(xDir), pointProjOffset.DotProduct(yDir));
return pointProjUV;
}
示例4: ExportWallBase
//.........这里部分代码省略.........
Curve centerCurve = GetWallAxis(wallElement);
XYZ localXDir = new XYZ(1, 0, 0);
XYZ localYDir = new XYZ(0, 1, 0);
XYZ localZDir = new XYZ(0, 0, 1);
XYZ localOrig = new XYZ(0, 0, 0);
double eps = MathUtil.Eps();
if (centerCurve != null)
{
Curve baseCurve = GetWallAxisAtBaseHeight(wallElement);
trimmedCurve = GetWallTrimmedCurve(wallElement, baseCurve);
IFCRange curveBounds;
XYZ oldOrig;
GeometryUtil.GetAxisAndRangeFromCurve(trimmedCurve, out curveBounds, out localXDir, out oldOrig);
// Move the curve to the bottom of the geometry or the bottom of the range, which is higher.
if (baseCurve != null)
localOrig = new XYZ(oldOrig.X, oldOrig.Y, validRange ? Math.Max(range.Start, zSpan.Start) : zSpan.Start);
else
localOrig = oldOrig;
double dist = localOrig[2] - oldOrig[2];
if (!MathUtil.IsAlmostZero(dist))
{
XYZ moveVec = new XYZ(0, 0, dist);
trimmedCurve = GeometryUtil.MoveCurve(trimmedCurve, moveVec);
}
localYDir = localZDir.CrossProduct(localXDir);
// ensure that X and Z axes are orthogonal.
double xzDot = localZDir.DotProduct(localXDir);
if (!MathUtil.IsAlmostZero(xzDot))
localXDir = localYDir.CrossProduct(localZDir);
}
else
{
BoundingBoxXYZ boundingBox = element.get_BoundingBox(null);
if (boundingBox != null)
{
XYZ bBoxMin = boundingBox.Min;
XYZ bBoxMax = boundingBox.Max;
if (validRange)
localOrig = new XYZ(bBoxMin.X, bBoxMin.Y, range.Start);
else
localOrig = boundingBox.Min;
XYZ localXDirMax = null;
Transform bTrf = boundingBox.Transform;
XYZ localXDirMax1 = new XYZ(bBoxMax.X, localOrig.Y, localOrig.Z);
localXDirMax1 = bTrf.OfPoint(localXDirMax1);
XYZ localXDirMax2 = new XYZ(localOrig.X, bBoxMax.Y, localOrig.Z);
localXDirMax2 = bTrf.OfPoint(localXDirMax2);
if (localXDirMax1.DistanceTo(localOrig) >= localXDirMax2.DistanceTo(localOrig))
localXDirMax = localXDirMax1;
else
localXDirMax = localXDirMax2;
localXDir = localXDirMax.Subtract(localOrig);
localXDir = localXDir.Normalize();
localYDir = localZDir.CrossProduct(localXDir);
// ensure that X and Z axes are orthogonal.
double xzDot = localZDir.DotProduct(localXDir);
if (!MathUtil.IsAlmostZero(xzDot))
示例5: Evaluate
public override Value Evaluate(FSharpList<Value> args)
{
var symbol = (FamilySymbol)((Value.Container)args[0]).Item;
var curves = ((Value.List) args[1]).Item;
IEnumerable<Tuple<Curve, XYZ>> data;
if (args[2].IsList)
{
var targets = ((Value.List)args[2]).Item;
if (curves.Count() != targets.Count())
throw new Exception("The number of curves and the number of up vectors must be the same.");
//if we get a list of up vectors, then pair each
//curve with a corresponding up vector
data = curves.Zip(targets,
(first, second) =>
new Tuple<Curve, XYZ>((Curve) ((Value.Container) first).Item,
(XYZ) ((Value.Container) second).Item));
}
else
{
//if we get a single up vector, then pair each
//curve with that up vector
data = curves.Select(x=>new Tuple<Curve, XYZ>((Curve)((Value.Container)x).Item,
(XYZ)((Value.Container)args[2]).Item));
}
var instData = new List<FamilyInstanceCreationData>();
int count = 0;
foreach (var pair in data)
{
var curve = pair.Item1;
var target = pair.Item2;
//calculate the desired rotation
//we do this by finding the angle between the z axis
//and vector between the start of the beam and the target point
//both projected onto the start plane of the beam.
XYZ zAxis = new XYZ(0, 0, 1);
XYZ yAxis = new XYZ(0, 1, 0);
//flatten the beam line onto the XZ plane
//using the start's z coordinate
XYZ start = curve.get_EndPoint(0);
XYZ end = curve.get_EndPoint(1);
XYZ newEnd = new XYZ(end.X, end.Y, start.Z); //drop end point to plane
////use the x axis of the curve's transform
////as the normal of the start plane
//XYZ planeNormal = (curve.get_EndPoint(0) - curve.get_EndPoint(1)).Normalize();
//catch the case where the end is directly above
//the start, creating a normal with zero length
//in that case, use the Z axis
XYZ planeNormal = newEnd.IsAlmostEqualTo(start) ? zAxis : (newEnd - start).Normalize();
XYZ target_project = target - target.DotProduct(planeNormal)*planeNormal;
XYZ z_project = zAxis - zAxis.DotProduct(planeNormal)*planeNormal;
//double gamma = target_project.AngleTo(z_project);
double gamma = target.AngleOnPlaneTo(zAxis.IsAlmostEqualTo(planeNormal) ? yAxis : zAxis, planeNormal);
FamilyInstance instance = null;
if (this.Elements.Count > count)
{
if (dynUtils.TryGetElement(this.Elements[count], out instance))
{
if (instance.Symbol != symbol)
instance.Symbol = symbol;
//update the curve
var locCurve = instance.Location as LocationCurve;
locCurve.Curve = curve;
}
else
{
var beamData = new FamilyInstanceCreationData(curve, symbol, dynRevitSettings.DefaultLevel, StructuralType.Beam)
{
RotateAngle = gamma
};
instData.Add(beamData);
}
}
else
{
var beamData = new FamilyInstanceCreationData(curve, symbol, dynRevitSettings.DefaultLevel, StructuralType.Beam)
{
RotateAngle = gamma
};
instData.Add(beamData);
}
count++;
}
//trim the elements collection
//.........这里部分代码省略.........
示例6: VectorsAreParallel2
/// <summary>
/// Returns an integer to indicate if two vectors are parallel, antiparallel or not.
/// </summary>
/// <param name="a">The one vector.</param>
/// <param name="b">The other vector.</param>
/// <returns>1 parallel, -1 antiparallel, 0 not parallel.</returns>
public static int VectorsAreParallel2(XYZ a, XYZ b)
{
if (a == null || b == null)
return 0;
double aa, bb, ab;
double epsSq = Eps() * Eps();
aa = a.DotProduct(a);
bb = b.DotProduct(b);
if (aa < epsSq || bb < epsSq)
return 0;
ab = a.DotProduct(b);
double cosAngleSq = (ab / aa) * (ab / bb);
if (cosAngleSq < 1.0 - AngleEps() * AngleEps())
return 0;
return ab > 0 ? 1 : -1;
}
示例7: VectorsAreOrthogonal
/// <summary>
/// Checks if two vectors are orthogonal or not.
/// </summary>
/// <param name="a">The one vector.</param>
/// <param name="b">The other vector.</param>
/// <returns>True if they are orthogonal, false if not.</returns>
public static bool VectorsAreOrthogonal(XYZ a, XYZ b)
{
if (a == null || b == null)
return false;
if (a.IsAlmostEqualTo(XYZ.Zero) || b.IsAlmostEqualTo(XYZ.Zero))
return true;
double ab = a.DotProduct(b);
double aa = a.DotProduct(a);
double bb = b.DotProduct(b);
return (ab * ab < aa * AngleEps() * bb * AngleEps()) ? true : false;
}
示例8: CreateOpeningForDoorWindow
//.........这里部分代码省略.........
double wantOriginAtY = posHingeSide ? (-unScaledDepth / 2.0) : (unScaledDepth / 2.0);
if (!MathUtil.IsAlmostEqual(wantOriginAtY, clOrig[1]))
{
XYZ moveVec = new XYZ(0, wantOriginAtY - clOrig[1], 0);
tmpCutLoop = GeometryUtil.MoveCurveLoop(tmpCutLoop, moveVec);
}
bool cutDirRelToHostObjY = (cutDir[1] > 0.0); // true = same sense, false = opp. sense
if (posHingeSide != cutDirRelToHostObjY)
{
cutDir = cutDir * -1.0;
cutDirRelToHostObjY = !cutDirRelToHostObjY; // not used beyond this point.
}
}
else if ((cutLoopBBox != null) && (curve is Arc))
{
Arc arc = curve as Arc;
double radius = arc.Radius;
XYZ curveCtr = arc.Center;
// check orientation to cutDir, make sure it points to center of arc.
XYZ origLL = new XYZ(cutLoopBBox.Min.X, cutLoopBBox.Min.Y, curveCtr.Z);
XYZ origUR = new XYZ(cutLoopBBox.Max.X, cutLoopBBox.Max.Y, curveCtr.Z);
XYZ origCtr = (origLL + origUR) / 2.0;
double centerDist = origCtr.DistanceTo(curveCtr);
XYZ approxMoveDir = (origCtr - curveCtr).Normalize();
bool cutDirPointingIn = (cutDir.DotProduct(approxMoveDir) < 0.0);
bool centerInsideArc = (centerDist < radius);
if (centerInsideArc == cutDirPointingIn)
{
XYZ moveVec = cutDir * -unScaledDepth;
origCtr += moveVec;
tmpCutLoop = GeometryUtil.MoveCurveLoop(tmpCutLoop, moveVec);
}
// not for windows that are too big ... forget about it. Very rare case.
double depthFactor = openingWidth / (2.0 * radius);
double eps = MathUtil.Eps();
if (depthFactor < 1.0 - eps)
{
double depthFactorSq = depthFactor * depthFactor * 4;
double extraDepth = radius * (1.0 - Math.Sqrt(1.0 - depthFactorSq));
if (extraDepth > eps)
{
XYZ moveVec = cutDir * -extraDepth;
tmpCutLoop = GeometryUtil.MoveCurveLoop(tmpCutLoop, moveVec);
unScaledDepth += extraDepth;
}
}
// extra fudge on the other side of the window opening.
depthFactor = origUnscaledDepth / (2.0 * radius);
if (depthFactor < 1.0 - eps)
{
double extraDepth = radius * (1.0 - Math.Sqrt(1.0 - depthFactor));
if (extraDepth > eps)
unScaledDepth += extraDepth;
}
}
示例9: GetProfile
/// <summary>
/// Determine the elevation boundary profile
/// polygons of the exterior vertical planar
/// face of the given wall solid.
/// </summary>
/// <param name="polygons">Return polygonal boundary
/// loops of exterior vertical planar face, i.e.
/// profile of wall elevation incl. holes</param>
/// <param name="solid">Input solid</param>
/// <param name="w">Vector pointing along
/// wall centre line</param>
/// <param name="w">Vector pointing towards
/// exterior wall face</param>
/// <returns>False if no exterior vertical
/// planar face was found, else true</returns>
static bool GetProfile(
List<List<XYZ>> polygons,
Solid solid,
XYZ v,
XYZ w)
{
double d, dmax = 0;
PlanarFace outermost = null;
FaceArray faces = solid.Faces;
foreach( Face f in faces )
{
PlanarFace pf = f as PlanarFace;
if( null != pf
&& Util.IsVertical( pf )
&& Util.IsZero( v.DotProduct( pf.Normal ) ) )
{
d = pf.Origin.DotProduct( w );
if( ( null == outermost )
|| ( dmax < d ) )
{
outermost = pf;
dmax = d;
}
}
}
if( null != outermost )
{
XYZ voffset = _offset * w;
XYZ p, q = XYZ.Zero;
bool first;
int i, n;
EdgeArrayArray loops = outermost.EdgeLoops;
foreach( EdgeArray loop in loops )
{
List<XYZ> vertices = new List<XYZ>();
first = true;
foreach( Edge e in loop )
{
IList<XYZ> points = e.Tessellate();
p = points[0];
if( !first )
{
Debug.Assert( p.IsAlmostEqualTo( q ),
"expected subsequent start point"
+ " to equal previous end point" );
}
n = points.Count;
q = points[n - 1];
for( i = 0; i < n - 1; ++i )
{
XYZ a = points[i];
a += voffset;
vertices.Add( a );
}
}
q += voffset;
Debug.Assert( q.IsAlmostEqualTo( vertices[0] ),
"expected last end point to equal"
+ " first start point" );
polygons.Add( vertices );
}
}
return null != outermost;
}
示例10: OffsetArc
/// <summary>
/// Offsets an arc along the offset direction from the point on the arc.
/// </summary>
/// <param name="arc">The arc.</param>
/// <param name="offsetPntOnArc">The point on the arc.</param>
/// <param name="offset">The offset vector.</param>
/// <returns>The offset Arc.</returns>
private static Arc OffsetArc(Arc arc, XYZ offsetPntOnArc, XYZ offset)
{
if (arc == null || offset == null)
throw new ArgumentNullException();
if (offset.IsZeroLength())
return arc;
XYZ axis = arc.Normal.Normalize();
XYZ offsetAlongAxis = axis.Multiply(offset.DotProduct(axis));
XYZ offsetOrthAxis = offset - offsetAlongAxis;
XYZ offsetPntToCenter = (arc.Center - offsetPntOnArc).Normalize();
double signedOffsetLengthTowardCenter = offsetOrthAxis.DotProduct(offsetPntToCenter);
double newRadius = arc.Radius - signedOffsetLengthTowardCenter; // signedOffsetLengthTowardCenter > 0, minus, < 0, add
Arc offsetArc = Arc.Create(arc.Center, newRadius, arc.GetEndParameter(0), arc.GetEndParameter(1), arc.XDirection, arc.YDirection);
offsetArc = GeometryUtil.MoveCurve(offsetArc, offsetAlongAxis) as Arc;
return offsetArc;
}
示例11: CreateExtrudedSolidFromCurveLoop
/// <summary>
/// Creates an extruded solid from a collection of curve loops and a thickness.
/// </summary>
/// <param name="exporterIFC">The ExporterIFC object.</param>
/// <param name="profileName">The name of the extrusion profile.</param>
/// <param name="origCurveLoops">The profile boundary curves.</param>
/// <param name="plane">The plane of the boundary curves.</param>
/// <param name="extrDirVec">The direction of the extrusion.</param>
/// <param name="scaledExtrusionSize">The thickness of the extrusion, perpendicular to the plane.</param>
/// <returns>The IfcExtrudedAreaSolid handle.</returns>
/// <remarks>If the curveLoop plane normal is not the same as the plane direction, only tesellated boundaries are supported.</remarks>
public static IFCAnyHandle CreateExtrudedSolidFromCurveLoop(ExporterIFC exporterIFC, string profileName, IList<CurveLoop> origCurveLoops,
Plane plane, XYZ extrDirVec, double scaledExtrusionSize)
{
IFCAnyHandle extrudedSolidHnd = null;
if (scaledExtrusionSize < MathUtil.Eps())
return extrudedSolidHnd;
IFCFile file = exporterIFC.GetFile();
// we need to figure out the plane of the curve loops and modify the extrusion direction appropriately.
// assumption: first curve loop defines the plane.
int sz = origCurveLoops.Count;
if (sz == 0)
return extrudedSolidHnd;
XYZ planeXDir = plane.XVec;
XYZ planeYDir = plane.YVec;
XYZ planeZDir = plane.Normal;
XYZ planeOrig = plane.Origin;
double slantFactor = Math.Abs(planeZDir.DotProduct(extrDirVec));
if (MathUtil.IsAlmostZero(slantFactor))
return extrudedSolidHnd;
// Reduce the number of line segments in the curveloops from highly tessellated polylines, if applicable.
IList<CurveLoop> curveLoops = CoarsenCurveLoops(origCurveLoops);
// Check that curve loops are valid.
curveLoops = ExporterIFCUtils.ValidateCurveLoops(curveLoops, extrDirVec);
if (curveLoops.Count == 0)
return extrudedSolidHnd;
scaledExtrusionSize /= slantFactor;
IFCAnyHandle sweptArea = CreateSweptArea(exporterIFC, profileName, curveLoops, plane, extrDirVec);
if (IFCAnyHandleUtil.IsNullOrHasNoValue(sweptArea))
return extrudedSolidHnd;
IList<double> relExtrusionDirList = new List<double>();
relExtrusionDirList.Add(extrDirVec.DotProduct(planeXDir));
relExtrusionDirList.Add(extrDirVec.DotProduct(planeYDir));
relExtrusionDirList.Add(extrDirVec.DotProduct(planeZDir));
XYZ scaledXDir = ExporterIFCUtils.TransformAndScaleVector(exporterIFC, planeXDir);
XYZ scaledZDir = ExporterIFCUtils.TransformAndScaleVector(exporterIFC, planeZDir);
XYZ scaledOrig = ExporterIFCUtils.TransformAndScalePoint(exporterIFC, planeOrig);
IFCAnyHandle solidAxis = ExporterUtil.CreateAxis(file, scaledOrig, scaledZDir, scaledXDir);
IFCAnyHandle extrusionDirection = ExporterUtil.CreateDirection(file, relExtrusionDirList);
extrudedSolidHnd = IFCInstanceExporter.CreateExtrudedAreaSolid(file, sweptArea, solidAxis, extrusionDirection, scaledExtrusionSize);
return extrudedSolidHnd;
}
示例12: ExportWallBase
//.........这里部分代码省略.........
Curve baseCurve = GetWallAxisAtBaseHeight(wallElement);
curve = GetWallTrimmedCurve(wallElement, baseCurve);
IFCRange curveBounds;
XYZ oldOrig;
GeometryUtil.GetAxisAndRangeFromCurve(curve, out curveBounds, out localXDir, out oldOrig);
localOrig = oldOrig;
if (baseCurve != null)
{
if (!validRange || (MathUtil.IsAlmostEqual(range.Start, zSpan.Start)))
{
XYZ newOrig = baseCurve.Evaluate(curveBounds.Start, false);
if (!validRange && (zSpan.Start < newOrig[2] - eps))
localOrig = new XYZ(localOrig.X, localOrig.Y, zSpan.Start);
else
localOrig = new XYZ(localOrig.X, localOrig.Y, newOrig[2]);
}
else
{
localOrig = new XYZ(localOrig.X, localOrig.Y, range.Start);
}
}
double dist = localOrig[2] - oldOrig[2];
if (!MathUtil.IsAlmostZero(dist))
{
XYZ moveVec = new XYZ(0, 0, dist);
curve = GeometryUtil.MoveCurve(curve, moveVec);
}
localYDir = localZDir.CrossProduct(localXDir);
// ensure that X and Z axes are orthogonal.
double xzDot = localZDir.DotProduct(localXDir);
if (!MathUtil.IsAlmostZero(xzDot))
localXDir = localYDir.CrossProduct(localZDir);
}
else
{
BoundingBoxXYZ boundingBox = element.get_BoundingBox(null);
if (boundingBox != null)
{
XYZ bBoxMin = boundingBox.Min;
XYZ bBoxMax = boundingBox.Max;
if (validRange)
localOrig = new XYZ(bBoxMin.X, bBoxMin.Y, range.Start);
else
localOrig = boundingBox.Min;
XYZ localXDirMax = null;
Transform bTrf = boundingBox.Transform;
XYZ localXDirMax1 = new XYZ(bBoxMax.X, localOrig.Y, localOrig.Z);
localXDirMax1 = bTrf.OfPoint(localXDirMax1);
XYZ localXDirMax2 = new XYZ(localOrig.X, bBoxMax.Y, localOrig.Z);
localXDirMax2 = bTrf.OfPoint(localXDirMax2);
if (localXDirMax1.DistanceTo(localOrig) >= localXDirMax2.DistanceTo(localOrig))
localXDirMax = localXDirMax1;
else
localXDirMax = localXDirMax2;
localXDir = localXDirMax.Subtract(localOrig);
localXDir = localXDir.Normalize();
localYDir = localZDir.CrossProduct(localXDir);
// ensure that X and Z axes are orthogonal.
double xzDot = localZDir.DotProduct(localXDir);
if (!MathUtil.IsAlmostZero(xzDot))
示例13: foreach
/*
/// <summary>
/// Return the average of a list of values.
/// Prerequisite: the underlying class T must supply
/// operator*(double) and operator+(const T &).
/// </summary>
T Average<T>( List<T> a )
{
T result;
bool first = true;
foreach( T x in a )
{
if( first )
{
result = x;
}
else
{
result += x;
}
}
return result * ( 1.0 / a.Count );
}
XYZ Sum( List<XYZ> a )
{
XYZ sum = XYZ.Zero;
foreach( XYZ x in a )
{
sum += x;
}
return sum;
}
XYZ Average( List<XYZ> a )
{
return Sum( a ) * (1.0 / a.Count);
}
XYZ TriangleCenter( List<XYZ> pts )
{
Debug.Assert( 3 == pts.Count, "expected three points in triangle" );
return Average( pts );
}
*/
/// <summary>
/// Return the plane properties of a given polygon,
/// i.e. the plane normal, area, and its distance
/// from the origin. Cf. also GetSignedPolygonArea.
/// </summary>
internal static bool GetPolygonPlane(
List<XYZ> polygon,
out XYZ normal,
out double dist,
out double area)
{
normal = XYZ.Zero;
dist = area = 0.0;
int n = ( null == polygon ) ? 0 : polygon.Count;
bool rc = ( 2 < n );
if( 3 == n )
{
// the general case returns a wrong result for the triangle
// ((-1 -1 -1) (1 -1 -1) (-1 -1 1)), so implement specific
// code for triangle:
XYZ a = polygon[0];
XYZ b = polygon[1];
XYZ c = polygon[2];
XYZ v = b - a;
normal = v.CrossProduct( c - a );
dist = normal.DotProduct( a );
}
else if( 4 == n )
{
// more efficient code for 4-sided polygons
XYZ a = polygon[0];
XYZ b = polygon[1];
XYZ c = polygon[2];
XYZ d = polygon[3];
normal = new XYZ(
( c.Y - a.Y ) * ( d.Z - b.Z ) + ( c.Z - a.Z ) * ( b.Y - d.Y ),
( c.Z - a.Z ) * ( d.X - b.X ) + ( c.X - a.X ) * ( b.Z - d.Z ),
( c.X - a.X ) * ( d.Y - b.Y ) + ( c.Y - a.Y ) * ( b.X - d.X ) );
dist = 0.25 *
( normal.X * ( a.X + b.X + c.X + d.X )
+ normal.Y * ( a.Y + b.Y + c.Y + d.Y )
+ normal.Z * ( a.Z + b.Z + c.Z + d.Z ) );
}
else if( 4 < n )
{
// general case for n-sided polygons
XYZ a;
//.........这里部分代码省略.........
示例14: GetPolygonPlane
private static bool GetPolygonPlane(List<XYZ> polygon,
out XYZ normal, out double dist, out double area)
{
normal = XYZ.Zero;
dist = area = 0.0;
int n = (null == polygon) ? 0 : polygon.Count;
bool rc = (2 < n);
if (3 == n)
{
XYZ a = polygon[0];
XYZ b = polygon[1];
XYZ c = polygon[2];
XYZ v = b - a;
normal = v.CrossProduct(c - a);
dist = normal.DotProduct(a);
}
else if (4 == n)
{
XYZ a = polygon[0];
XYZ b = polygon[1];
XYZ c = polygon[2];
XYZ d = polygon[3];
normal = new XYZ(
(c.Y - a.Y) * (d.Z - b.Z) + (c.Z - a.Z) * (b.Y - d.Y),
(c.Z - a.Z) * (d.X - b.X) + (c.X - a.X) * (b.Z - d.Z),
(c.X - a.X) * (d.Y - b.Y) + (c.Y - a.Y) * (b.X - d.X));
dist = 0.25 *
(normal.X * (a.X + b.X + c.X + d.X)
+ normal.Y * (a.Y + b.Y + c.Y + d.Y)
+ normal.Z * (a.Z + b.Z + c.Z + d.Z));
}
else if (4 < n)
{
XYZ a;
XYZ b = polygon[n - 2];
XYZ c = polygon[n - 1];
XYZ s = XYZ.Zero;
for (int i = 0; i < n; ++i)
{
a = b;
b = c;
c = polygon[i];
normal = new XYZ(
b.Y * (c.Z - a.Z),
b.Z * (c.X - a.X),
b.X * (c.Y - a.Y));
s += c;
}
dist = s.DotProduct(normal) / n;
}
if (rc)
{
double length = normal.GetLength();
rc = !normal.IsZeroLength();
if (rc)
{
normal /= length;
dist /= length;
area = 0.5 * length;
}
}
return rc;
}
示例15: CreateExtrudedSolidFromCurveLoop
/// <summary>
/// Creates an extruded solid from a collection of curve loops and a thickness.
/// </summary>
/// <param name="exporterIFC">The ExporterIFC object.</param>
/// <param name="profileName">The name of the extrusion profile.</param>
/// <param name="origCurveLoops">The profile boundary curves.</param>
/// <param name="plane">The plane of the boundary curves.</param>
/// <param name="extrDirVec">The direction of the extrusion.</param>
/// <param name="scaledExtrusionSize">The thickness of the extrusion, perpendicular to the plane.</param>
/// <returns>The IfcExtrudedAreaSolid handle.</returns>
/// <remarks>If the curveLoop plane normal is not the same as the plane direction, only tesellated boundaries are supported.</remarks>
public static IFCAnyHandle CreateExtrudedSolidFromCurveLoop(ExporterIFC exporterIFC, string profileName, IList<CurveLoop> origCurveLoops,
Plane plane, XYZ extrDirVec, double scaledExtrusionSize)
{
IFCAnyHandle extrudedSolidHnd = null;
if (scaledExtrusionSize < MathUtil.Eps())
return extrudedSolidHnd;
IFCFile file = exporterIFC.GetFile();
// we need to figure out the plane of the curve loops and modify the extrusion direction appropriately.
// assumption: first curve loop defines the plane.
int sz = origCurveLoops.Count;
if (sz == 0)
return extrudedSolidHnd;
XYZ planeXDir = plane.XVec;
XYZ planeYDir = plane.YVec;
XYZ planeZDir = plane.Normal;
XYZ planeOrig = plane.Origin;
double slantFactor = Math.Abs(planeZDir.DotProduct(extrDirVec));
if (MathUtil.IsAlmostZero(slantFactor))
return extrudedSolidHnd;
// Check that curve loops are valid.
IList<CurveLoop> curveLoops = ExporterIFCUtils.ValidateCurveLoops(origCurveLoops, extrDirVec);
if (curveLoops.Count == 0)
return extrudedSolidHnd;
scaledExtrusionSize /= slantFactor;
IFCAnyHandle sweptArea = null;
if (curveLoops.Count == 1)
{
sweptArea = CreateRectangleProfileDefIfPossible(exporterIFC, profileName, curveLoops[0], plane, extrDirVec);
if (sweptArea == null) sweptArea = CreateCircleProfileDefIfPossible(exporterIFC, profileName, curveLoops[0], plane, extrDirVec);
if (sweptArea == null) sweptArea = CreateIShapeProfileDefIfPossible(exporterIFC, profileName, curveLoops[0], plane, extrDirVec);
}
if (sweptArea == null)
{
IFCAnyHandle profileCurve = null;
HashSet<IFCAnyHandle> innerCurves = new HashSet<IFCAnyHandle>();
// reorient curves if necessary: outer CCW, inners CW.
foreach (CurveLoop curveLoop in curveLoops)
{
bool isCCW = false;
try
{
isCCW = curveLoop.IsCounterclockwise(planeZDir);
}
catch
{
if (profileCurve == null)
return null;
else
continue;
}
if (profileCurve == null)
{
if (!isCCW)
curveLoop.Flip();
profileCurve = ExporterIFCUtils.CreateCurveFromCurveLoop(exporterIFC, curveLoop, plane, extrDirVec);
if (IFCAnyHandleUtil.IsNullOrHasNoValue(profileCurve))
return extrudedSolidHnd;
}
else
{
if (isCCW)
curveLoop.Flip();
IFCAnyHandle innerCurve = ExporterIFCUtils.CreateCurveFromCurveLoop(exporterIFC, curveLoop, plane, extrDirVec);
if (!IFCAnyHandleUtil.IsNullOrHasNoValue(innerCurve))
innerCurves.Add(innerCurve);
}
}
if (innerCurves.Count > 0)
sweptArea = IFCInstanceExporter.CreateArbitraryProfileDefWithVoids(file, IFCProfileType.Area, profileName, profileCurve, innerCurves);
else
sweptArea = IFCInstanceExporter.CreateArbitraryClosedProfileDef(file, IFCProfileType.Area, profileName, profileCurve);
}
IList<double> relExtrusionDirList = new List<double>();
relExtrusionDirList.Add(extrDirVec.DotProduct(planeXDir));
relExtrusionDirList.Add(extrDirVec.DotProduct(planeYDir));
relExtrusionDirList.Add(extrDirVec.DotProduct(planeZDir));
//.........这里部分代码省略.........