本文整理汇总了C#中Curve.Tessellate方法的典型用法代码示例。如果您正苦于以下问题:C# Curve.Tessellate方法的具体用法?C# Curve.Tessellate怎么用?C# Curve.Tessellate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Curve
的用法示例。
在下文中一共展示了Curve.Tessellate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPlaneFromCurve
public static Plane GetPlaneFromCurve(Curve c, bool planarOnly)
{
//find the plane of the curve and generate a sketch plane
double period = c.IsBound ? 0.0 : (c.IsCyclic ? c.Period : 1.0);
var p0 = c.IsBound ? c.Evaluate(0.0, true) : c.Evaluate(0.0, false);
var p1 = c.IsBound ? c.Evaluate(0.5, true) : c.Evaluate(0.25 * period, false);
var p2 = c.IsBound ? c.Evaluate(1.0, true) : c.Evaluate(0.5 * period, false);
if (IsLineLike(c))
{
XYZ norm = null;
//keep old plane computations
if (System.Math.Abs(p0.Z - p2.Z) < Tolerance)
{
norm = XYZ.BasisZ;
}
else
{
var v1 = p1 - p0;
var v2 = p2 - p0;
var p3 = new XYZ(p2.X, p2.Y, p0.Z);
var v3 = p3 - p0;
norm = v1.CrossProduct(v3);
if (norm.IsZeroLength())
{
norm = v2.CrossProduct(XYZ.BasisY);
}
norm = norm.Normalize();
}
return new Plane(norm, p0);
}
var cLoop = new CurveLoop();
cLoop.Append(c.Clone());
if (cLoop.HasPlane())
{
return cLoop.GetPlane();
}
if (planarOnly)
return null;
// Get best fit plane using tesselation
var points = c.Tessellate().Select(x => x.ToPoint(false));
var bestFitPlane =
Autodesk.DesignScript.Geometry.Plane.ByBestFitThroughPoints(points);
return bestFitPlane.ToPlane(false);
}
示例2: GetCurveNormal
/// <summary>
/// Get Curves Normal
/// From Jeremy Tammik
/// </summary>
/// <param name="curve">Curve</param>
/// <returns>Normal Vector</returns>
public static XYZ GetCurveNormal(Curve curve)
{
IList<XYZ> pts = curve.Tessellate();
int n = pts.Count;
XYZ p = pts[0];
XYZ q = pts[n - 1];
XYZ v = q - p;
XYZ w, normal = null;
if (2 == n)
{
// for non-vertical lines, use Z axis to
// span the plane, otherwise Y axis:
double dxy = Math.Abs(v.X) + Math.Abs(v.Y);
w = (dxy > 0.001)
? XYZ.BasisZ
: XYZ.BasisY;
normal = v.CrossProduct(w).Normalize();
}
else
{
int i = 0;
while (++i < n - 1)
{
w = pts[i] - p;
normal = v.CrossProduct(w);
if (!normal.IsZeroLength())
{
normal = normal.Normalize();
break;
}
}
}
return normal;
}
示例3: DrawCurve
private void DrawCurve(Curve c)
{
List<XYZ> points;
points = c.Tessellate() as List<XYZ>;
XYZ pt1;
XYZ pt2;
Point3D ptVis1;
Point3D ptVis2;
int lastPointColor = Points.Count() - 1;//master Point list for color assignment
for (int i = 0; i < points.Count - 1; i++)
{
pt1 = points[i] as XYZ;
pt2 = points[i + 1] as XYZ;
ptVis1 = new Point3D(pt1.X, pt1.Y, pt1.Z);
ptVis2 = new Point3D(pt2.X, pt2.Y, pt2.Z);
Points[lastPointColor].Add(ptVis1);
Points[lastPointColor].Add(ptVis2);
}
}
示例4: Stream
//.........这里部分代码省略.........
{
// if the curve is unbound, those don't mean anything
data.Add(new Snoop.Data.String("Start point reference", "N/A"));
data.Add(new Snoop.Data.String("End point reference", "N/A"));
}
try
{
data.Add(new Snoop.Data.Object("Reference", crv.Reference));
}
catch (System.Exception ex)
{
data.Add(new Snoop.Data.Exception("Reference", ex));
}
try
{
data.Add(new Snoop.Data.Object("Derivative at Start", crv.ComputeDerivatives(0.0, normalized: true)));
}
catch (System.Exception ex)
{
data.Add(new Snoop.Data.Exception("Derivative at Start", ex));
}
try
{
data.Add(new Snoop.Data.Object("Derivative at Center", crv.ComputeDerivatives(0.5, normalized: true)));
}
catch (System.Exception ex)
{
data.Add(new Snoop.Data.Exception("Derivative at Center", ex));
}
try
{
data.Add(new Snoop.Data.Object("Derivative at End", crv.ComputeDerivatives(1.0, normalized: true)));
}
catch (System.Exception ex)
{
data.Add(new Snoop.Data.Exception("Derivative at End", ex));
}
try
{
data.Add(new Snoop.Data.CategorySeparator("Tesselated Points"));
}
catch
{
data.Add(new Snoop.Data.String("Tesselated Points", "N/A"));
}
try
{
System.Collections.Generic.IList<XYZ> pts = crv.Tessellate();
int i = 0;
foreach (XYZ pt in pts)
{
data.Add(new Snoop.Data.Xyz(string.Format("PT [{0:d}]", i++), pt));
}
}
catch (System.Exception ex)
{
data.Add(new Snoop.Data.Exception("Xyz", ex));
}
Line line = crv as Line;
if (line != null)
{
Stream(data, line);
return;
}
Arc arc = crv as Arc;
if (arc != null)
{
Stream(data, arc);
return;
}
Ellipse ellipse = crv as Ellipse;
if (ellipse != null)
{
Stream(data, ellipse);
return;
}
NurbSpline nurbSpline = crv as NurbSpline;
if (nurbSpline != null)
{
Stream(data, nurbSpline);
return;
}
HermiteSpline hermiteSpline = crv as HermiteSpline;
if (hermiteSpline != null)
{
Stream(data, hermiteSpline);
return;
}
}
示例5: GetCurveNormal
/// <summary>
/// Determine the plane that a given curve resides in and return its normal vector.
/// Ask the curve for its start and end points and some curve in the middle.
/// The latter can be obtained by asking the curve for its parameter range and
/// evaluating it in the middle, or by tessellation. In case of tessellation,
/// you could iterate through the tessellation points and use each one together
/// with the start and end points to try and determine a valid plane.
/// Once one is found, you can add debug assertions to ensure that the other
/// tessellation points (if there are any more) are in the same plane.
/// In the case of the line, the tessellation only returns two points.
/// I once heard that that is the only element that can do that, all
/// non-linear curves return at least three. So you could use this property
/// to determine that a line is a line (and add an assertion as well, if you like).
/// Update, later: please note that the Revit API provides an overload of the
/// NewPlane method taking a CurveArray argument.
/// </summary>
XYZ GetCurveNormal( Curve curve )
{
IList<XYZ> pts = curve.Tessellate();
int n = pts.Count;
Debug.Assert( 1 < n,
"expected at least two points "
+ "from curve tessellation" );
XYZ p = pts[0];
XYZ q = pts[n - 1];
XYZ v = q - p;
XYZ w, normal = null;
if( 2 == n )
{
Debug.Assert( curve is Line,
"expected non-line element to have "
+ "more than two tessellation points" );
// for non-vertical lines, use Z axis to
// span the plane, otherwise Y axis:
double dxy = Math.Abs( v.X ) + Math.Abs( v.Y );
w = ( dxy > Util.TolPointOnPlane )
? XYZ.BasisZ
: XYZ.BasisY;
normal = v.CrossProduct( w ).Normalize();
}
else
{
int i = 0;
while( ++i < n - 1 )
{
w = pts[i] - p;
normal = v.CrossProduct( w );
if( !normal.IsZeroLength() )
{
normal = normal.Normalize();
break;
}
}
#if DEBUG
{
XYZ normal2;
while( ++i < n - 1 )
{
w = pts[i] - p;
normal2 = v.CrossProduct( w );
Debug.Assert( normal2.IsZeroLength()
|| Util.IsZero( normal2.AngleTo( normal ) ),
"expected all points of curve to "
+ "lie in same plane" );
}
}
#endif // DEBUG
}
return normal;
}
示例6: CreateRoughTessellation
private static IList<XYZ> CreateRoughTessellation(ExporterIFC exporterIFC, Curve curve)
{
IList<XYZ> originalTessellation = curve.Tessellate();
int numPoints = originalTessellation.Count;
int numTargetPoints = Math.Min(numPoints, 12);
int numInteriorPoints = numTargetPoints - 2;
IList<XYZ> roughTessellation = new List<XYZ>(numTargetPoints);
// Always add the first point, scaled; then add approximately equally spaced interior points. Never add the last point
// As this should be part of a closed curve loop.
AddScaledPointToList(exporterIFC, roughTessellation, originalTessellation[0]);
for (int ii = 0; ii < numInteriorPoints; ii++)
{
AddScaledPointToList(exporterIFC, roughTessellation, originalTessellation[(int)(numPoints - 2) * (ii + 1) / numInteriorPoints]);
}
return roughTessellation;
}
示例7: CreateRoughParametricTessellation
private static IList<double> CreateRoughParametricTessellation(Curve curve)
{
IList<XYZ> originalTessellation = curve.Tessellate();
int numPoints = originalTessellation.Count;
int numTargetPoints = Math.Min(numPoints, 12);
int numInteriorPoints = numTargetPoints - 2;
IList<double> roughTessellation = new List<double>(numTargetPoints);
// Skip the first point as redundant.
IntersectionResult result = null;
for (int ii = 0; ii < numInteriorPoints; ii++)
{
XYZ initialPoint = originalTessellation[(int)(numPoints - 2) * (ii + 1) / numInteriorPoints];
result = curve.Project(initialPoint);
roughTessellation.Add(result.Parameter);
}
XYZ finalPoint = originalTessellation[numPoints - 1];
result = curve.Project(finalPoint);
roughTessellation.Add(result.Parameter);
return roughTessellation;
}
示例8: DrawCurve
private void DrawCurve(ref RenderDescription description, Curve curve)
{
IList<XYZ> points = curve.Tessellate();
for (int i = 0; i < points.Count; ++i)
{
XYZ xyz = points[i];
description.lines.Add(new Point3D(xyz.X, xyz.Y, xyz.Z));
if (i == 0 || i == (points.Count - 1))
continue;
description.lines.Add(new Point3D(xyz.X, xyz.Y, xyz.Z));
}
}
示例9: buildFaceOnPlaneByCurveExtensions
public static Face buildFaceOnPlaneByCurveExtensions(Curve crv, Autodesk.Revit.DB.Plane thisPlane)
{
Face face = null;
// tesselate curve and find uv envelope in projection to the plane
IList<XYZ> tessCurve = crv.Tessellate();
var curvePointEnum = tessCurve.GetEnumerator();
var corner1 = new XYZ();
var corner2 = new XYZ();
bool cornersSet = false;
for (; curvePointEnum.MoveNext(); )
{
if (!cornersSet)
{
corner1 = curvePointEnum.Current;
corner2 = curvePointEnum.Current;
cornersSet = true;
}
else
{
for (int coord = 0; coord < 3; coord++)
{
if (corner1[coord] > curvePointEnum.Current[coord])
corner1 = new XYZ(coord == 0 ? curvePointEnum.Current[coord] : corner1[coord],
coord == 1 ? curvePointEnum.Current[coord] : corner1[coord],
coord == 2 ? curvePointEnum.Current[coord] : corner1[coord]);
if (corner2[coord] < curvePointEnum.Current[coord])
corner2 = new XYZ(coord == 0 ? curvePointEnum.Current[coord] : corner2[coord],
coord == 1 ? curvePointEnum.Current[coord] : corner2[coord],
coord == 2 ? curvePointEnum.Current[coord] : corner2[coord]);
}
}
}
double dist1 = thisPlane.Origin.DistanceTo(corner1);
double dist2 = thisPlane.Origin.DistanceTo(corner2);
double sizeRect = 2.0 * (dist1 + dist2) + 100.0;
var cLoop = new Autodesk.Revit.DB.CurveLoop();
for (int index = 0; index < 4; index++)
{
double coord0 = (index == 0 || index == 3) ? -sizeRect : sizeRect;
double coord1 = (index < 2) ? -sizeRect : sizeRect;
XYZ pnt0 = thisPlane.Origin + coord0 * thisPlane.XVec + coord1 * thisPlane.YVec;
double coord3 = (index < 2) ? sizeRect : -sizeRect;
double coord4 = (index == 0 || index == 3) ? -sizeRect : sizeRect;
XYZ pnt1 = thisPlane.Origin + coord3 * thisPlane.XVec + coord4 * thisPlane.YVec;
Line cLine = dynRevitSettings.Revit.Application.Create.NewLineBound(pnt0, pnt1);
cLoop.Append(cLine);
}
var listCLoops = new List<Autodesk.Revit.DB.CurveLoop> { cLoop };
Solid tempSolid = GeometryCreationUtilities.CreateExtrusionGeometry(listCLoops, thisPlane.Normal, 100.0);
//find right face
FaceArray facesOfExtrusion = tempSolid.Faces;
for (int indexFace = 0; indexFace < facesOfExtrusion.Size; indexFace++)
{
Face faceAtIndex = facesOfExtrusion.get_Item(indexFace);
if (faceAtIndex is PlanarFace)
{
var pFace = faceAtIndex as PlanarFace;
if (Math.Abs(thisPlane.Normal.DotProduct(pFace.Normal)) < 0.99)
continue;
if (Math.Abs(thisPlane.Normal.DotProduct(thisPlane.Origin - pFace.Origin)) > 0.1)
continue;
face = faceAtIndex;
break;
}
}
if (face == null)
throw new Exception("Curve Face Intersection could not process supplied Plane.");
return face;
}
示例10: CreateCurveByPoints
private Autodesk.Revit.DB.CurveByPoints CreateCurveByPoints(Autodesk.Revit.DB.CurveByPoints c, Curve gc, XYZ start, XYZ end)
{
//Add the geometry curves start and end points to a ReferencePointArray.
ReferencePointArray refPtArr = new ReferencePointArray();
if (gc.GetType() == typeof(Line))
{
ReferencePoint refPointStart = this.UIDocument.Document.FamilyCreate.NewReferencePoint(start);
ReferencePoint refPointEnd = this.UIDocument.Document.FamilyCreate.NewReferencePoint(end);
refPtArr.Append(refPointStart);
refPtArr.Append(refPointEnd);
//c = dynRevitSettings.Doc.Document.FamilyCreate.NewCurveByPoints(refPtArr);
}
else if (gc.GetType() == typeof(Arc) && foundCreateArcThroughPoints)
{
Type CurveByPointsUtilsType = typeof(Autodesk.Revit.DB.CurveByPointsUtils);
MethodInfo[] curveElementMethods = CurveByPointsUtilsType.GetMethods(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
System.String nameOfMethodSetCurve = "CreateArcThroughPoints";
foreach (MethodInfo m in curveElementMethods)
{
if (m.Name == nameOfMethodSetCurve)
{
object[] argsM = new object[4];
ReferencePoint refPointStart = this.UIDocument.Document.FamilyCreate.NewReferencePoint(start);
ReferencePoint refPointEnd = this.UIDocument.Document.FamilyCreate.NewReferencePoint(end);
XYZ midPoint = gc.Evaluate(0.5, true);
ReferencePoint refMidPoint = this.UIDocument.Document.FamilyCreate.NewReferencePoint(midPoint);
argsM[0] = this.UIDocument.Document;
argsM[1] = refPointStart;
argsM[2] = refPointEnd;
argsM[3] = refMidPoint;
c = (Autodesk.Revit.DB.CurveByPoints)m.Invoke(null, argsM);
if (c != null && c.GeometryCurve.GetType() == typeof(Arc))
return c;
if (c != null)
this.DeleteElement(c.Id);
break;
}
}
foundCreateArcThroughPoints = false;
}
if (gc.GetType() != typeof(Line))
{
IList <XYZ> xyzList = gc.Tessellate();
int numPoints = xyzList.Count;
for (int ii = 0; ii < numPoints; ii++)
{
ReferencePoint refPoint = this.UIDocument.Document.FamilyCreate.NewReferencePoint(xyzList[ii]);
refPtArr.Append(refPoint);
}
}
c = dynRevitSettings.Doc.Document.FamilyCreate.NewCurveByPoints(refPtArr);
return c;
}
示例11: StreamCurveAsTesselatedPointsWcs
/// <summary>
/// By default, everything goes out as tesselated vectors. This function allows all the
/// base class functions to easily tesselate. But, if derived classes override individual
/// curve types, they can intercept before they are tesselated.
/// </summary>
/// <param name="crv">Curve to tesselate into vectors</param>
private void StreamCurveAsTesselatedPointsWcs(Curve crv)
{
StreamWcs(crv.Tessellate(), false); // stream out as array of points
}
示例12: StreamCurveAsTesselatedPoints
StreamCurveAsTesselatedPoints(Curve crv)
{
Stream(crv.Tessellate(), false); // stream out as array of points
}
示例13: CreateEdgeCurveFromCurve
private static IFCAnyHandle CreateEdgeCurveFromCurve(IFCFile file, ExporterIFC exporterIFC, Curve currCurve, IFCAnyHandle edgeStart, IFCAnyHandle edgeEnd, bool sameSense)
{
IFCAnyHandle baseCurve = null;
// if the Curve is a line, do the following
if (currCurve is Line)
{
// Unbounded line doesn't make sense, skip if somehow it is
if (!currCurve.IsBound)
{
Line curveLine = currCurve as Line;
IFCAnyHandle point = XYZtoIfcCartesianPoint(exporterIFC, curveLine.GetEndPoint(0), true);
IList<double> direction = new List<double>();
direction.Add(UnitUtil.ScaleLength(curveLine.Direction.X));
direction.Add(UnitUtil.ScaleLength(curveLine.Direction.Y));
direction.Add(UnitUtil.ScaleLength(curveLine.Direction.Z));
IFCAnyHandle vector = IFCInstanceExporter.CreateVector(file, direction, curveLine.Direction.GetLength());
baseCurve = IFCInstanceExporter.CreateLine(file, point, vector);
}
}
// if the Curve is an Arc do following
else if (currCurve is Arc)
{
Arc curveArc = currCurve as Arc;
IFCAnyHandle location = XYZtoIfcCartesianPoint2D(exporterIFC, curveArc.Center, true);
IList<double> direction = new List<double>();
direction.Add(UnitUtil.ScaleLength(curveArc.XDirection.X));
direction.Add(UnitUtil.ScaleLength(curveArc.YDirection.Y));
IFCAnyHandle dir = IFCInstanceExporter.CreateDirection(file, direction);
IFCAnyHandle position = IFCInstanceExporter.CreateAxis2Placement2D(file, location, null, dir);
baseCurve = IFCInstanceExporter.CreateCircle(file, position, UnitUtil.ScaleLength(curveArc.Radius));
}
// If curve is an ellipse or elliptical Arc type
else if (currCurve is Ellipse)
{
Ellipse curveEllipse = currCurve as Ellipse;
IFCAnyHandle location = XYZtoIfcCartesianPoint2D(exporterIFC, curveEllipse.Center, true);
IList<double> direction = new List<double>();
direction.Add(UnitUtil.ScaleLength(curveEllipse.XDirection.X));
direction.Add(UnitUtil.ScaleLength(curveEllipse.YDirection.Y));
IFCAnyHandle dir = IFCInstanceExporter.CreateDirection(file, direction);
IFCAnyHandle position = IFCInstanceExporter.CreateAxis2Placement2D(file, location, null, dir);
baseCurve = IFCInstanceExporter.CreateEllipse(file, position, UnitUtil.ScaleLength(curveEllipse.RadiusX), UnitUtil.ScaleLength(curveEllipse.RadiusY));
}
// if the Curve is of any other type, tessellate it and use polyline to represent it
else
{
// any other curve is not supported, we will tessellate it
IList<XYZ> tessCurve = currCurve.Tessellate();
IList<IFCAnyHandle> polylineVertices = new List<IFCAnyHandle>();
foreach (XYZ vertex in tessCurve)
{
IFCAnyHandle ifcVert = XYZtoIfcCartesianPoint(exporterIFC, vertex, true);
polylineVertices.Add(ifcVert);
}
baseCurve = IFCInstanceExporter.CreatePolyline(file, polylineVertices);
}
if (IFCAnyHandleUtil.IsNullOrHasNoValue(baseCurve))
return null;
IFCAnyHandle edgeCurve = IFCInstanceExporter.CreateEdgeCurve(file, edgeStart, edgeEnd, baseCurve, sameSense);
return edgeCurve;
}
示例14: GetPlaneFromCurve
public static Plane GetPlaneFromCurve(Curve c, bool planarOnly)
{
//cases to handle
//straight line - normal will be inconclusive
//find the plane of the curve and generate a sketch plane
double period = c.IsBound ? 0.0 : (c.IsCyclic ? c.Period : 1.0);
var p0 = c.IsBound ? c.Evaluate(0.0, true) : c.Evaluate(0.0, false);
var p1 = c.IsBound ? c.Evaluate(0.5, true) : c.Evaluate(0.25 * period, false);
var p2 = c.IsBound ? c.Evaluate(1.0, true) : c.Evaluate(0.5 * period, false);
if (c is Line)
{
var v1 = p1 - p0;
var v2 = p2 - p0;
XYZ norm = null;
//keep old plane computations
if (Math.Abs(p0.Z - p2.Z) < 0.0001)
{
norm = XYZ.BasisZ;
}
else
{
var p3 = new XYZ(p2.X, p2.Y, p0.Z);
var v3 = p3 - p0;
norm = v1.CrossProduct(v3);
if (norm.IsZeroLength())
{
norm = v2.CrossProduct(XYZ.BasisY);
}
norm = norm.Normalize();
}
return new Plane(norm, p0);
}
Autodesk.Revit.DB.CurveLoop cLoop = new Autodesk.Revit.DB.CurveLoop();
cLoop.Append(c.Clone());
if (cLoop.HasPlane())
{
return cLoop.GetPlane();
}
if (planarOnly)
return null;
IList<XYZ> points = c.Tessellate();
List<XYZ> xyzs = new List<XYZ>();
for (int iPoint = 0; iPoint < points.Count; iPoint++)
xyzs.Add(points[iPoint]);
//var v1 = p1 - p0;
//var v2 = p2 - p0;
//var norm = v1.CrossProduct(v2).Normalize();
////Normal can be zero length in the case of a straight line
////or a curve whose three parameter points as measured above
////happen to lie along the same line. In this case, project
////the last point down to a plane and use the projected vector
////and one of the vectors from above to calculate a normal.
//if (norm.IsZeroLength())
//{
// if (p0.Z == p2.Z)
// {
// norm = XYZ.BasisZ;
// }
// else
// {
// var p3 = new XYZ(p2.X, p2.Y, p0.Z);
// var v3 = p3 - p0;
// norm = v1.CrossProduct(v3);
// }
//}
//var curvePlane = new Plane(norm, p0);
XYZ meanPt;
List<XYZ> orderedEigenvectors;
BestFitLine.PrincipalComponentsAnalysis(xyzs, out meanPt, out orderedEigenvectors);
var normal = orderedEigenvectors[0].CrossProduct(orderedEigenvectors[1]);
var plane = dynRevitSettings.Doc.Application.Application.Create.NewPlane(normal, meanPt);
return plane;
}
示例15: DrawCurve
/// <summary>
/// Draw the curve in GDI.
/// </summary>
/// <param name="graphics"></param>
/// <param name="pen"></param>
/// <param name="curve"></param>
private void DrawCurve(Graphics graphics, System.Drawing.Pen pen, Curve curve)
{
List<PointF> poinsts = new List<PointF>();
foreach (Autodesk.Revit.DB.XYZ point in curve.Tessellate())
{
poinsts.Add(Util.Translate(point,m_boundingbox));
}
graphics.DrawCurve(pen, poinsts.ToArray());
}