本文整理汇总了C#中Plane.DistanceTo方法的典型用法代码示例。如果您正苦于以下问题:C# Plane.DistanceTo方法的具体用法?C# Plane.DistanceTo怎么用?C# Plane.DistanceTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Plane
的用法示例。
在下文中一共展示了Plane.DistanceTo方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssertThat_SignedDistanceIsCorrect_WithPointBelowPlane_WithNegativeD
public void AssertThat_SignedDistanceIsCorrect_WithPointBelowPlane_WithNegativeD()
{
var p = new Plane(new Vector3(0, 1, 0), -10);
var d = p.DistanceTo(new Vector3(0, -20, 0));
Assert.AreEqual(-30, d);
}
示例2: AssertThat_SignedDistanceIsCorrect_WithPointAbovePlane
public void AssertThat_SignedDistanceIsCorrect_WithPointAbovePlane()
{
var p = new Plane(new Vector3(0, 1, 0), 10);
var d = p.DistanceTo(new Vector3(0, 0, 0));
Assert.AreEqual(10, d);
}
示例3: IsSurfaceInPlane
private static bool IsSurfaceInPlane(Surface surface, Plane plane, double tolerance)
{
if (!surface.IsPlanar(tolerance))
return false;
var bbox = surface.GetBoundingBox(true);
return bbox.GetCorners().All(c => System.Math.Abs(plane.DistanceTo(c)) <= tolerance);
}
示例4: GrowHull
public static void GrowHull(ref Mesh Msh, Point3d Pt)
{
double Tol = RhinoDoc.ActiveDoc.ModelAbsoluteTolerance*0.1;//RhinoDoc.ActiveDoc.ModelAngleToleranceRadians;
double AngleTest = (Math.PI * 0.5) - ((0.1 / 360) * (Math.PI * 2.0));
MeshPoint CP = Msh.ClosestMeshPoint(Pt, 0);
if (CP.Point.DistanceTo(Pt) < Tol)
{
int[] EdgeIndices = Msh.TopologyEdges.GetEdgesForFace(CP.FaceIndex);
Msh.Faces.RemoveAt(CP.FaceIndex);
Msh.Vertices.Add(Pt);
List<MeshFace> AddFaces = new List<MeshFace>();
for (int EdgeIdx = 0; EdgeIdx < EdgeIndices.Length; EdgeIdx++)
{
Rhino.IndexPair VertexPair = Msh.TopologyEdges.GetTopologyVertices(EdgeIndices[EdgeIdx]);
AddFaces.Add(new MeshFace(Msh.TopologyVertices.MeshVertexIndices(VertexPair.I)[0], Msh.TopologyVertices.MeshVertexIndices(VertexPair.J)[0], Msh.Vertices.Count - 1));
}
Msh.Faces.AddFaces(AddFaces);
return;
}
else if (Msh.IsPointInside(Pt,Tol,true)) { return; }
else
{
Msh.FaceNormals.ComputeFaceNormals();
List<int> DeleteFaces = new List<int>();
for (int FaceIdx = 0; FaceIdx < Msh.Faces.Count; FaceIdx++)
{
Vector3d VecTest = new Vector3d(Msh.Faces.GetFaceCenter(FaceIdx) - Pt);
Plane PlaneTest = new Plane(Msh.Faces.GetFaceCenter(FaceIdx), Msh.FaceNormals[FaceIdx]);
if (Vector3d.VectorAngle(PlaneTest.ZAxis, VecTest) > AngleTest || Math.Abs(PlaneTest.DistanceTo(Pt)) < Tol) { DeleteFaces.Add(FaceIdx); }
}
Msh.Faces.DeleteFaces(DeleteFaces);
Msh.Vertices.Add(Pt);
List<MeshFace> AddFaces = new List<MeshFace>();
for (int EdgeIdx = 0; EdgeIdx < Msh.TopologyEdges.Count; EdgeIdx++)
{
if (!Msh.TopologyEdges.IsSwappableEdge(EdgeIdx))
{
IndexPair VertexPair = Msh.TopologyEdges.GetTopologyVertices(EdgeIdx);
AddFaces.Add(new MeshFace(Msh.TopologyVertices.MeshVertexIndices(VertexPair.I)[0], Msh.TopologyVertices.MeshVertexIndices(VertexPair.J)[0], Msh.Vertices.Count - 1));
}
}
Msh.Faces.AddFaces(AddFaces);
return;
}
}
示例5: ExtendThroughBox
/// <summary>
/// Utility function for creating a PlaneSurface through a Box.
/// </summary>
/// <param name="plane">Plane to extend.</param>
/// <param name="box">Box to extend through.</param>
/// <param name="fuzzyness">Box will be inflated by this amount.</param>
/// <returns>A Plane surface through the box or null.</returns>
internal static PlaneSurface ExtendThroughBox(Plane plane, BoundingBox box, double fuzzyness)
{
if (fuzzyness != 0.0) { box.Inflate(fuzzyness); }
Point3d[] corners = box.GetCorners();
int side = 0;
bool valid = false;
for (int i = 0; i < corners.Length; i++)
{
double d = plane.DistanceTo(corners[i]);
if (d == 0.0) { continue; }
if (d < 0.0)
{
if (side > 0) { valid = true; break; }
side = -1;
}
else
{
if (side < 0) { valid = true; break; }
side = +1;
}
}
if (!valid) { return null; }
Interval s, t;
if (!plane.ExtendThroughBox(box, out s, out t)) { return null; }
if (s.IsSingleton || t.IsSingleton)
return null;
return new PlaneSurface(plane, s, t);
}
示例6: PlaneCircle
/// <summary>
/// Intersects a plane with a circle using exact calculations.
/// </summary>
/// <param name="plane">Plane to intersect.</param>
/// <param name="circle">Circe to intersect.</param>
/// <param name="firstCircleParameter">First intersection parameter on circle if successful or RhinoMath.UnsetValue if not.</param>
/// <param name="secondCircleParameter">Second intersection parameter on circle if successful or RhinoMath.UnsetValue if not.</param>
/// <returns>The type of intersection that occured.</returns>
public static PlaneCircleIntersection PlaneCircle(Plane plane, Circle circle, out double firstCircleParameter, out double secondCircleParameter)
{
firstCircleParameter = RhinoMath.UnsetValue;
secondCircleParameter = RhinoMath.UnsetValue;
if (plane.ZAxis.IsParallelTo(circle.Plane.ZAxis, RhinoMath.ZeroTolerance * Math.PI) != 0)
{
if (Math.Abs(plane.DistanceTo(circle.Center)) < RhinoMath.ZeroTolerance)
return PlaneCircleIntersection.Coincident;
return PlaneCircleIntersection.Parallel;
}
Line L;
//At this point, the PlanePlane should never fail since I already checked for parallellillity.
if (!PlanePlane(plane, circle.Plane, out L)) { return PlaneCircleIntersection.Parallel; }
double Lt = L.ClosestParameter(circle.Center);
Point3d Lp = L.PointAt(Lt);
double d = circle.Center.DistanceTo(Lp);
//If circle radius equals the projection distance, we have a tangent intersection.
if (Math.Abs(d - circle.Radius) < RhinoMath.ZeroTolerance)
{
circle.ClosestParameter(Lp, out firstCircleParameter);
secondCircleParameter = firstCircleParameter;
return PlaneCircleIntersection.Tangent;
}
//If circle radius too small to get an intersection, then abort.
if (d > circle.Radius) { return PlaneCircleIntersection.None; }
double offset = Math.Sqrt((circle.Radius * circle.Radius) - (d * d));
Vector3d dir = offset * L.UnitTangent;
if (!circle.ClosestParameter(Lp + dir, out firstCircleParameter)) { return PlaneCircleIntersection.None; }
if (!circle.ClosestParameter(Lp - dir, out secondCircleParameter)) { return PlaneCircleIntersection.None; }
return PlaneCircleIntersection.Secant;
}
示例7: FoldAngle
public double FoldAngle(Point3d p1, Point3d p2, Point3d p3, Point3d p4, Point3d p5, Point3d p6)
{
Plane plane1 = new Plane(p1, p2, p3);
Plane plane2 = new Plane(p4, p5, p6);
Line l;
if (!Rhino.Geometry.Intersect.Intersection.PlanePlane(plane1, plane2, out l)) return double.NaN;
double max = l.DistanceTo(p4, false);
double max2 = l.DistanceTo(p5, false);
double max3 = l.DistanceTo(p6, false);
double t = 0;
if (max >= max2 && max >= max3) t = plane1.DistanceTo(p4);
if (max2 >= max && max2 >= max3) t = plane1.DistanceTo(p5);
if (max3 >= max2 && max3 >= max) t = plane1.DistanceTo(p6);
double rad = Vector3d.VectorAngle(plane1.Normal, plane2.Normal);
if (t < 0) rad *= -1;
return rad;
}
示例8: MakeConvexHull
/// <summary>
/// Generates a convex hull mesh for a set of points. Also removes all faces that lie on the ExoMesh plates.
/// </summary>
/// <param name="nodeIndex">Index of node being hulled.</param>
/// <param name="sides">Number of sides per strut.</param>
/// <param name="tol">The tolerance (RhinoDoc.ActiveDoc.ModelAbsoluteTolerance is a good bet).</param>
/// <param name="cleanPlates">If true, the plate faces will be removed from the hull, so that the sleeves can be directly attached.</param>
/// <remarks>
/// If a plate point is coplanar with another plate, the hull may be impossible to clean.
/// This is because the hulling process may remove the coplanar point and create a new face.
/// </remarks>
public Mesh MakeConvexHull(int nodeIndex, int sides, double tol, bool cleanPlates)
{
Mesh hullMesh = new Mesh();
ExoHull node = this.Hulls[nodeIndex];
double radius = node.AvgRadius;
double planeTolerance = tol * radius / 25;
// Collect all hull points (i.e. all plate points at the node)
List<Point3d> pts = new List<Point3d>();
foreach (int pIndex in node.PlateIndices)
{
pts.AddRange(this.Plates[pIndex].Vtc);
}
// 1. Create initial tetrahedron.
// Form triangle from 3 first points (lie on same plate, thus, same plane)
hullMesh.Vertices.Add(pts[0]);
hullMesh.Vertices.Add(pts[1]);
hullMesh.Vertices.Add(pts[2]);
Plane planeStart = new Plane(pts[0], pts[1], pts[2]);
// Form tetrahedron with a 4th point which does not lie on the same plane
int nextIndex = sides + 1;
while (Math.Abs(planeStart.DistanceTo(pts[nextIndex])) < planeTolerance)
{
nextIndex++;
}
hullMesh.Vertices.Add(pts[nextIndex]);
// Stitch faces of tetrahedron
hullMesh.Faces.AddFace(0, 2, 1);
hullMesh.Faces.AddFace(0, 3, 2);
hullMesh.Faces.AddFace(0, 1, 3);
hullMesh.Faces.AddFace(1, 2, 3);
// 2. Begin the incremental hulling process
// Remove points already checked
pts.RemoveAt(nextIndex);
pts.RemoveRange(0, 3);
// Loop through the remaining points
for (int i = 0; i < pts.Count; i++)
{
MeshTools.NormaliseMesh(ref hullMesh);
// Find visible faces
List<int> seenFaces = new List<int>();
for (int faceIndex = 0; faceIndex < hullMesh.Faces.Count; faceIndex++)
{
Vector3d testVect = pts[i] - hullMesh.Faces.GetFaceCenter(faceIndex);
double angle = Vector3d.VectorAngle(hullMesh.FaceNormals[faceIndex], testVect);
Plane planeTest = new Plane(hullMesh.Faces.GetFaceCenter(faceIndex), hullMesh.FaceNormals[faceIndex]);
if (angle < Math.PI * 0.5 || Math.Abs(planeTest.DistanceTo(pts[i])) < planeTolerance)
{
seenFaces.Add(faceIndex);
}
}
// Remove visible faces
hullMesh.Faces.DeleteFaces(seenFaces);
// Add current point
hullMesh.Vertices.Add(pts[i]);
List<MeshFace> addFaces = new List<MeshFace>();
// Close open hull based on new vertex
for (int edgeIndex = 0; edgeIndex < hullMesh.TopologyEdges.Count; edgeIndex++)
{
if (!hullMesh.TopologyEdges.IsSwappableEdge(edgeIndex))
{
IndexPair V = hullMesh.TopologyEdges.GetTopologyVertices(edgeIndex);
int I1 = hullMesh.TopologyVertices.MeshVertexIndices(V.I)[0];
int I2 = hullMesh.TopologyVertices.MeshVertexIndices(V.J)[0];
addFaces.Add(new MeshFace(I1, I2, hullMesh.Vertices.Count - 1));
}
}
hullMesh.Faces.AddFaces(addFaces);
}
MeshTools.NormaliseMesh(ref hullMesh);
// 3. If requested, delete the hull faces that lie on the plates (so sleeves can connect directly to the hulls)
if (cleanPlates)
{
List<int> deleteFaces = new List<int>();
foreach (int plateIndx in node.PlateIndices)
{
List<Point3f> plateVtc = MeshTools.Point3dToPoint3f(this.Plates[plateIndx].Vtc);
// Recall that strut plates have 'sides+1' vertices.
// If the plate has only 'sides' vertices, it is an extra plate (for acute nodes), so we should keep it
//.........这里部分代码省略.........
示例9: checkIfOnPlane
private bool checkIfOnPlane(Point3d pt1, Point3d pt2, Point3d pt3, Point3d pttested)
{
Plane p = new Plane(pt1, pt2, pt3);
// Print(p.DistanceTo(pttested).ToString());
return Math.Abs(p.DistanceTo(pttested)) > RhinoDoc.ActiveDoc.ModelAbsoluteTolerance;
}
示例10: intersect
public void intersect(Plane p)
{
for (int i = 0; i < pts.Count; i++)
{
double db = p.DistanceTo(pts[i].pos);
if (Math.Abs(db) < RhinoDoc.ActiveDoc.ModelAbsoluteTolerance) { pts[i].condition = 1; }
else if (db > 0) { pts[i].condition = 2; }
else if (db < 0) { pts[i].condition = 0; }
}
///////////////////////
int ii = 0;
while (ii < edges.Count)
{
if (edges[ii].p1.condition == 0 && edges[ii].p2.condition == 0)
{
edges.RemoveAt(ii);
}
else if (edges[ii].p1.condition == 1 && edges[ii].p2.condition == 0)
{
edges.RemoveAt(ii);
}
else if (edges[ii].p1.condition == 1 && edges[ii].p2.condition == 1)
{
edges.RemoveAt(ii);
}
else if (edges[ii].p1.condition == 0 && edges[ii].p2.condition == 1)
{
edges.RemoveAt(ii);
}
else if (edges[ii].p1.condition == 0 && edges[ii].p2.condition == 2)
{
double u; Line line = new Line(edges[ii].p1.pos, edges[ii].p2.pos);
Rhino.Geometry.Intersect.Intersection.LinePlane(line, p, out u);
pts.Add(new vertex(line.PointAt(u), this.center.DistanceTo(line.PointAt(u))));
edges[ii].p1 = pts[pts.Count - 1];
ii++;
}
else if (edges[ii].p1.condition == 2 && edges[ii].p2.condition == 0)
{
double u; Line line = new Line(edges[ii].p1.pos, edges[ii].p2.pos);
Rhino.Geometry.Intersect.Intersection.LinePlane(line, p, out u);
pts.Add(new vertex(line.PointAt(u), this.center.DistanceTo(line.PointAt(u))));
edges[ii].p2 = pts[pts.Count - 1];
ii++;
}
else { ii++; }
}
clearnull();
//////////////////////////////////
Transform w2p = Transform.PlaneToPlane(Plane.WorldXY, p);
Transform p2w = Transform.PlaneToPlane(p, Plane.WorldXY);
Grasshopper.Kernel.Geometry.Node2List ls = new Grasshopper.Kernel.Geometry.Node2List();
List<int> count = new List<int>();
for (int i = 0; i < pts.Count; i++)
{
if (pts[i].condition == 1 || pts[i].condition == -1)
{
pts[i].pos.Transform(w2p);
ls.Append(new Grasshopper.Kernel.Geometry.Node2(pts[i].pos.X, pts[i].pos.Y));
pts[i].pos.Transform(p2w);
count.Add(i);
}
}
if (count.Count == 2) edges.Add(new edge(pts[count[0]], pts[count[1]]));
else if (count.Count > 2)
{
List<int> count2 = new List<int>();
Grasshopper.Kernel.Geometry.ConvexHull.Solver.Compute(ls, count2);
for (int i = 0; i < count2.Count; i++)
{
int c = i + 1; if (c == count2.Count) c = 0;
edges.Add(new edge(pts[count[count2[i]]], pts[count[count2[c]]]));
}
}
}