/// <summary> /// Finds the intersecting face and the resulting point for an offset edge /// Based on a point where the edge will be. Edge stays parallel to itself. /// </summary> /// <param name="topoLink">The moved vertex from the edge</param> /// <param name="position">New position for the moved edge</param> /// <param name="capFace">The face intersected with the offset. </param> /// <returns>The point of intersection</returns> internal Point3d OffsetIntersection(PFVertex topoLink, PfoamRef coresp, out PFVertex otherVert, out PFFace capFace) { Point3d position = coresp.Vertices[topoLink].Position; // for this I need to build overloads to see for special cases - when starting point is in face, or in edge otherVert = Vertices.Single(x => x != topoLink); var edgeDirection = otherVert.Point - topoLink.Point; edgeDirection.Unitize(); // find all the unique faces of the other point to intersect with // get plane for face // find intersection closest to position -> get that face (use normal to find it and its cell) //----------------------------------------------------------- // for each face test to see if coresp object contains an updated plane for the face //----------------------------------------------------------- // this is the otherPosition - I should output also the point and the corresponding face (cell) // if some faces(or their pair) are part of open cells exclude those faces from the intersections var edgeFaces = new HashSet <PFFace>(Faces); edgeFaces.UnionWith(Pair.Faces); var otherVertFaces = new HashSet <PFFace>(otherVert.Faces); var edgeCapFaces = otherVertFaces.Except(edgeFaces); var facingCapFaces = edgeFaces.Where(x => !x.External && Dot(x.Normal, edgeDirection) > 0).ToList(); if (edgeCapFaces.Count() < 1) { capFace = null; return(position + edgeDirection * GetLength()); } var offsetLine = new Line(position, position + edgeDirection); // now intersect line with all face planes double minPara = double.MaxValue; int minParaIndex = 0; for (int i = 0; i < facingCapFaces.Count(); i++) { var facePlane = coresp.Faces[facingCapFaces[i]].Plane; if (Rhino.Geometry.Intersect.Intersection.LinePlane(offsetLine, facePlane, out double param)) { if (param < minPara) { minPara = param; minParaIndex = i; } } } capFace = facingCapFaces[minParaIndex]; return(offsetLine.PointAt(minPara)); }
/// <summary> /// Intersects an offset edge with another edge from the same face /// The second edge is at the end of the point /// </summary> /// <param name="topoLink"></param> /// <param name="position"></param> /// <param name="inFace"></param> /// <returns></returns> internal Point3d OffsetIntersection(PFVertex topoLink, PfoamRef coresp, PFFace inFace, out PFVertex otherVert, out PFEdge capEdge) { // test if position is in the inFace // intersect an edge with another edge - edges are part of the same face plane //----------------------------------------------------------- // for each edge test to see if coresp object contains an updated line for the edge //----------------------------------------------------------- // there will be an line/line intersection // if other point has more than 4 connections some connections will require type 1 calculations Point3d position = coresp.Vertices[topoLink].Position; otherVert = Vertices.Single(x => x != topoLink); var edgeDirection = otherVert.Point - topoLink.Point; var offsetLine = new Line(position, position + edgeDirection); capEdge = otherVert.Edges.Single(x => inFace.Edges.Contains(x)); var otherLine = coresp.Edges[capEdge].Line; var intersection = Rhino.Geometry.Intersect.Intersection.LineLine(offsetLine, otherLine, out double a, out double b); return(offsetLine.PointAt(a)); }