private static (bool, EdgeHL) ClippEdgeAtNearPlane(EdgeHL edge, double nearPlaneDist) { var start = edge.Start; var end = edge.End; if ((start.Y < nearPlaneDist) || (end.Y < nearPlaneDist)) { if ((start.Y < nearPlaneDist) && (end.Y < nearPlaneDist)) { return(false, null); } var direction = end - start; var intersection = start; if (direction.Y != 0.0) { double lamda = Math.Abs((start.Y - nearPlaneDist) / direction.Y); intersection += direction * lamda; } if (start.Y < nearPlaneDist) { start = intersection; } else { end = intersection; } } return(true, new EdgeHL { Start = start, End = end, First = edge.First, Second = edge.Second, Edge = edge.Edge }); }
private static LineHL ToLine2D(this EdgeHL edge, double nearPlaneDist) { var(x1, y1) = ViewProjection.ProjectCameraSystemToCameraPlane(edge.Start, nearPlaneDist); var(x2, y2) = ViewProjection.ProjectCameraSystemToCameraPlane(edge.End, nearPlaneDist); var line2d = new LineHL { Start = new PointHL(x1, y1), End = new PointHL(x2, y2), Edge = edge }; return(line2d); }
private static (bool, Position3D) GetRayIntersectionWithEdge(Axis3D rayAxis, EdgeHL edge) { var edgeEnd = edge.End; var edgeOffset = edge.Start; var edgeDirection = edgeEnd - edgeOffset; var edgeAxis = new Axis3D(edgeOffset, edgeDirection); var(success, intersection) = edgeAxis.CalculatePerpendicularPoint(rayAxis); return(success, intersection); }
private static EdgeHL ConvertToEdgeHL(Edge edge, Dictionary <Triangle, TriangleHL> dict, Matrix44D cameraAndBodyFrame) { var edgeHL = new EdgeHL() { Start = cameraAndBodyFrame * edge.Start.Position, End = cameraAndBodyFrame * edge.End.Position, First = dict.ContainsKey(edge.First.ParentTriangle) ? dict[edge.First.ParentTriangle] : null, Second = dict.ContainsKey(edge.Second.ParentTriangle) ? dict[edge.Second.ParentTriangle] : null, Edge = edge }; return(edgeHL); }
private static bool IsLineBorderEdge(EdgeHL edge) { var firstTriangle = edge.First; var secondTriangle = edge.Second; var isFirstTriangleVisible = IsTriangleVisible(firstTriangle); var isSecondTriangleVisible = IsTriangleVisible(secondTriangle); if (isFirstTriangleVisible != isSecondTriangleVisible) { return(true); } if (((firstTriangle.Face.HasBorder || secondTriangle.Face.HasBorder) && (firstTriangle.Face != secondTriangle.Face || firstTriangle == secondTriangle)) || (firstTriangle.Face.HasFacets || secondTriangle.Face.HasFacets)) { return(true); } return(false); }