本文整理汇总了C#中XYZ.DistanceTo方法的典型用法代码示例。如果您正苦于以下问题:C# XYZ.DistanceTo方法的具体用法?C# XYZ.DistanceTo怎么用?C# XYZ.DistanceTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XYZ
的用法示例。
在下文中一共展示了XYZ.DistanceTo方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateModelLine
/// <summary>
/// Create a model line between the two given points.
/// Internally, it creates an arbitrary sketch
/// plane given the model line end points.
/// </summary>
public static ModelLine CreateModelLine(
Document doc,
XYZ p,
XYZ q)
{
if( p.DistanceTo( q ) < Util.MinLineLength ) return null;
// Create sketch plane; for non-vertical lines,
// use Z-axis to span the plane, otherwise Y-axis:
XYZ v = q - p;
double dxy = Math.Abs( v.X ) + Math.Abs( v.Y );
XYZ w = ( dxy > Util.TolPointOnPlane )
? XYZ.BasisZ
: XYZ.BasisY;
XYZ norm = v.CrossProduct( w ).Normalize();
//Autodesk.Revit.Creation.Application creApp
// = doc.Application.Create;
//Plane plane = creApp.NewPlane( norm, p ); // 2014
//Plane plane = new Plane( norm, p ); // 2015, 2016
Plane plane = Plane.CreateByNormalAndOrigin( norm, p ); // 2017
//SketchPlane sketchPlane = creDoc.NewSketchPlane( plane ); // 2013
SketchPlane sketchPlane = SketchPlane.Create( doc, plane ); // 2014
//Line line = creApp.NewLine( p, q, true ); // 2013
Line line = Line.CreateBound( p, q ); // 2014
// The following line is only valid in a project
// document. In a family, it will throw an exception
// saying "Document.Create can only be used with
// project documents. Use Document.FamilyCreate
// in the Family Editor."
//Autodesk.Revit.Creation.Document creDoc
// = doc.Create;
//return creDoc.NewModelCurve(
// //creApp.NewLine( p, q, true ), // 2013
// Line.CreateBound( p, q ), // 2014
// sketchPlane ) as ModelLine;
ModelCurve curve = doc.IsFamilyDocument
? doc.FamilyCreate.NewModelCurve( line, sketchPlane )
: doc.Create.NewModelCurve( line, sketchPlane );
return curve as ModelLine;
}
示例2: CreateModelLine
/// <summary>
/// Miroslav Schonauer's model line creation method.
/// A utility function to create an arbitrary sketch
/// plane given the model line end points.
/// </summary>
/// <param name="app">Revit application</param>
/// <param name="p">Model line start point</param>
/// <param name="q">Model line end point</param>
/// <returns></returns>
public static ModelLine CreateModelLine(
Document doc,
XYZ p,
XYZ q)
{
if( p.DistanceTo( q ) < Util.MinLineLength ) return null;
// Create sketch plane; for non-vertical lines,
// use Z-axis to span the plane, otherwise Y-axis:
XYZ v = q - p;
double dxy = Math.Abs( v.X ) + Math.Abs( v.Y );
XYZ w = ( dxy > Util.TolPointOnPlane )
? XYZ.BasisZ
: XYZ.BasisY;
XYZ norm = v.CrossProduct( w ).Normalize();
Autodesk.Revit.Creation.Application creApp
= doc.Application.Create;
Plane plane = creApp.NewPlane( norm, p );
Autodesk.Revit.Creation.Document creDoc
= doc.Create;
//SketchPlane sketchPlane = creDoc.NewSketchPlane( plane ); // 2013
SketchPlane sketchPlane = SketchPlane.Create( doc, plane ); // 2014
return creDoc.NewModelCurve(
//creApp.NewLine( p, q, true ), // 2013
Line.CreateBound( p, q ), // 2014
sketchPlane ) as ModelLine;
}
示例3: LineSegmentIsTooShort
/// <summary>
/// Returns true if the line segment from pt1 to pt2 is less than the short curve tolerance.
/// </summary>
/// <param name="pt1">The first point of the line segment.</param>
/// <param name="pt2">The final point of the line segment.</param>
/// <returns>True if it is too short, false otherwise.</returns>
public static bool LineSegmentIsTooShort(XYZ pt1, XYZ pt2)
{
double dist = pt1.DistanceTo(pt2);
return (dist < IFCImportFile.TheFile.Document.Application.ShortCurveTolerance + MathUtil.Eps());
}
示例4: FindFace
private Face FindFace(XYZ location, XYZ vector, Document doc)
{
Face face = null;
FilteredElementCollector elementCollector = new FilteredElementCollector(doc);
elementCollector.WhereElementIsNotElementType();
Options opt = new Options { ComputeReferences = true };
foreach (Element e in elementCollector)
{
try
{
GeometryElement ge = e.get_Geometry(opt);
foreach (GeometryObject go in ge)
{
try
{
XYZ endPt = location + vector;
Line l = Line.CreateBound(location - vector, endPt);
Curve c = l as Curve;
double dist = 1000000;
GeometryInstance geoInst = go as GeometryInstance;
if (geoInst != null)
{
// Family instance
GeometryElement instGeometry = geoInst.GetInstanceGeometry();
foreach (GeometryObject o in instGeometry)
{
Solid s = o as Solid;
if (s != null)
foreach (Face f in s.Faces)
{
IntersectionResultArray results;
SetComparisonResult result = f.Intersect(c, out results);
if (results != null)
{
foreach (IntersectionResult res in results)
{
XYZ intersect = res.XYZPoint;
double tempDist = location.DistanceTo(intersect);
if (tempDist < dist)
{
dist = tempDist;
face = f;
if (dist < 0.05)
{
return f;
}
}
}
}
}
}
}
else
{
// Assume something like a wall.
Solid solid = go as Solid;
if (solid != null)
foreach (Face f in solid.Faces)
{
IntersectionResultArray results;
SetComparisonResult result = f.Intersect(c, out results);
if (results != null)
{
foreach (IntersectionResult res in results)
{
XYZ intersect = res.XYZPoint;
double tempDist = location.DistanceTo(intersect);
if (tempDist < dist)
{
dist = tempDist;
face = f;
if (dist < 0.05)
{
return f;
}
}
}
}
}
}
}
catch (Exception ex)
{
//errors++;
Debug.WriteLine(ex.Message);
}
}
}
catch (Exception ex)
{
//errors++;
Debug.WriteLine(ex.Message);
}
}
if (face == null)
{
TaskDialog.Show("error", "no face found");
//.........这里部分代码省略.........
示例5: ExportWallBase
//.........这里部分代码省略.........
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))
localXDir = localYDir.CrossProduct(localZDir);
}
}
IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle();
Transform orientationTrf = Transform.Identity;
orientationTrf.BasisX = localXDir;
orientationTrf.BasisY = localYDir;
orientationTrf.BasisZ = localZDir;
orientationTrf.Origin = localOrig;
double scaledFootprintArea = 0;
double scaledLength = 0;
using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, element, null, orientationTrf, overrideLevelId))
{
IFCAnyHandle localPlacement = setter.LocalPlacement;
// The local coordinate system of the wall as defined by IFC for IfcWallStandardCase.
Plane wallLCS = new Plane(localXDir, localYDir, localOrig); // project curve to XY plane.
XYZ projDir = XYZ.BasisZ;
示例6: ExportWallBase
//.........这里部分代码省略.........
}
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))
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 (!exportParts && (centerCurve != null) && (GeometryUtil.CurveIsLineOrArc(centerCurve)))
{
exportingAxis = true;
示例7: Evaluate
public override Value Evaluate(FSharpList<Value> args)
{
var curves = ((Value.List)args[0]).Item.Select(
x => ((Curve)((Value.Container)x).Item)).ToList();
List<Curve> curvesWithFlip = new List<Curve>();
bool bStart = true;
XYZ prevEnd = new XYZ();
double tolMax = 0.0001;
double tolMin = 0.00001;
foreach (Curve c in curves)
{
if (!bStart)
{
XYZ thisEnd = c.Evaluate(1.0, true);
XYZ thisStart = c.Evaluate(0.0, true);
double thisDist = thisStart.DistanceTo(prevEnd);
if (thisDist > tolMax && thisEnd.DistanceTo(prevEnd) < tolMin && (c is Line))
{
prevEnd = thisStart;
Curve flippedCurve = /* Line.CreateBound */ dynRevitSettings.Revit.Application.Create.NewLineBound(thisEnd, thisStart);
curvesWithFlip.Add(flippedCurve);
continue;
}
}
else
{
bStart = false;
prevEnd = c.Evaluate(1.0, true);
if (curves.Count > 1)
{
XYZ nextStart = curves[1].Evaluate(0.0, true);
double thisDist = prevEnd.DistanceTo(nextStart);
if (thisDist > tolMax)
{
XYZ nextEnd = curves[1].Evaluate(1.0, true);
if (nextEnd.DistanceTo(prevEnd) > tolMax)
{
XYZ thisStart = c.Evaluate(0.0, true);
if (thisStart.DistanceTo(nextEnd) < tolMin || thisStart.DistanceTo(nextStart) < tolMin)
{
if (c is Line)
{
Curve flippedCurve = /* Line.CreateBound */ dynRevitSettings.Revit.Application.Create.NewLineBound(prevEnd, thisStart);
prevEnd = thisStart;
curvesWithFlip.Add(flippedCurve);
continue;
}
}
}
}
}
}
prevEnd = c.Evaluate(1.0, true);
curvesWithFlip.Add(c);
}
Autodesk.Revit.DB.CurveLoop result = Autodesk.Revit.DB.CurveLoop.Create(curvesWithFlip);
return Value.NewContainer(result);
}
示例8: CreateLineSafe
public static Line CreateLineSafe(this Document doc, XYZ p1, XYZ p2)
{
if (p1.DistanceTo(p2) > doc.Application.ShortCurveTolerance)
{
return Line.CreateBound(p1, p2);
}
return null;
}