public static UV Evaluate(Plane plane, XYZ point) { if (!IsPointInPlane(plane, point)) { point = GetProjectPoint(plane, point); } Plane planeOx = Plane.CreateByOriginAndBasis(plane.Origin, plane.XVec, plane.Normal); Plane planeOy = Plane.CreateByOriginAndBasis(plane.Origin, plane.YVec, plane.Normal); double lenX = GetSignedDistance(planeOy, point); double lenY = GetSignedDistance(planeOx, point); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { double tLenX = lenX * Math.Pow(-1, i + 1); double tLenY = lenY * Math.Pow(-1, j + 1); XYZ tPoint = GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(plane.Origin, plane.XVec, tLenX), plane.YVec, tLenY); if (GeomUtil.IsEqual(tPoint, point)) { return(new UV(tLenX, tLenY)); } } } throw new Exception("Code complier should never be here!"); }
public static Plane GetPlaneWithBasisY(PlanarFace f, XYZ vecY) { if (!GeomUtil.IsEqual(GeomUtil.DotMatrix(vecY, f.FaceNormal), 0)) { throw new Exception("VecY is not perpendicular with Normal!"); } return(Plane.CreateByOriginAndBasis(f.Origin, GeomUtil.UnitVector(GeomUtil.CrossMatrix(vecY, f.FaceNormal)), vecY)); }
int IComparer <XYZ> .Compare(XYZ first, XYZ second) { if (GeomUtil.IsEqual(first.X, second.X)) { if (GeomUtil.IsEqual(first.Y, second.Y)) { return(0); // Equal } return((first.Y > second.Y) ? 1 : -1); } return((first.X > second.X) ? 1 : -1); }
public static bool IsPointInLineOrExtend(Line line, XYZ point) { if (GeomUtil.IsEqual(point, line.GetEndPoint(0)) || GeomUtil.IsEqual(point, line.GetEndPoint(1))) { return(true); } if (GeomUtil.IsSameOrOppositeDirection(GeomUtil.SubXYZ(point, line.GetEndPoint(0)), GeomUtil.SubXYZ(point, line.GetEndPoint(1)))) { return(true); } return(false); }
int IComparer <XYZ> .Compare(XYZ first, XYZ second) { // first compare z coordinate, then y coordiante, at last x coordinate if (GeomUtil.IsEqual(first.Z, second.Z)) { if (GeomUtil.IsEqual(first.Y, second.Y)) { if (GeomUtil.IsEqual(first.X, second.X)) { return(0); // Equal } return((first.X > second.X) ? 1 : -1); } return((first.Y > second.Y) ? 1 : -1); } return((first.Z > second.Z) ? 1 : -1); }
public static PointComparePolygonResult PointComparePolygon(UV p, List <UV> polygon) { bool check1 = IsPointInPolygon(p, polygon); for (int i = 0; i < polygon.Count; i++) { if (GeomUtil.IsEqual(p, polygon[i])) { return(PointComparePolygonResult.Node); } UV vec1 = GeomUtil.SubXYZ(p, polygon[i]); UV vec2 = null; if (i != polygon.Count - 1) { if (GeomUtil.IsEqual(p, polygon[i + 1])) { continue; } vec2 = GeomUtil.SubXYZ(p, polygon[i + 1]); } else { if (GeomUtil.IsEqual(p, polygon[0])) { continue; } vec2 = GeomUtil.SubXYZ(p, polygon[0]); } if (GeomUtil.IsOppositeDirection(vec1, vec2)) { return(PointComparePolygonResult.Boundary); } } if (check1) { return(PointComparePolygonResult.Inside); } return(PointComparePolygonResult.Outside); }
int IComparer <Element> .Compare(Element x, Element y) { XYZ loc1 = null; XYZ loc2 = null; if (x is Wall) { WallGeometryInfo wgi = new WallGeometryInfo(x as Wall); loc1 = wgi.TopPolygon.CentralXYZPoint; } if (x is FamilyInstance) { ColumnGeometryInfo cgi = new ColumnGeometryInfo(x as FamilyInstance); loc1 = cgi.TopPolygon.CentralXYZPoint; } if (y is Wall) { WallGeometryInfo wgi = new WallGeometryInfo(y as Wall); loc2 = wgi.TopPolygon.CentralXYZPoint; } if (y is FamilyInstance) { ColumnGeometryInfo cgi = new ColumnGeometryInfo(y as FamilyInstance); loc2 = cgi.TopPolygon.CentralXYZPoint; } loc1 = new XYZ(loc1.X, loc1.Y, 0); loc2 = new XYZ(loc2.X, loc2.Y, 0); if (Plane != null) { loc1 = CheckGeometry.GetProjectPoint(Plane, loc1); loc2 = CheckGeometry.GetProjectPoint(Plane, loc2); } if (GeomUtil.IsEqual(loc1.X, loc2.X)) { if (GeomUtil.IsEqual(loc1.Y, loc2.Y)) { return(0); // Equal } return((loc1.Y > loc2.Y) ? 1 : -1); } return((loc1.X > loc2.X) ? 1 : -1); }
public static bool CreateListPolygon(List <Curve> listCurve, out List <Polygon> pls) { pls = new List <Polygon>(); foreach (Curve c in listCurve) { List <Curve> cs = new List <Curve>(); cs.Add(Line.CreateBound(c.GetEndPoint(0), c.GetEndPoint(1))); int i = 0; bool check = true; while (!GeomUtil.IsEqual(cs[0].GetEndPoint(0), cs[cs.Count - 1].GetEndPoint(1))) { i++; foreach (Curve c1 in listCurve) { XYZ pnt = cs[cs.Count - 1].GetEndPoint(1); XYZ prePnt = cs[cs.Count - 1].GetEndPoint(0); if (GeomUtil.IsEqual(pnt, c1.GetEndPoint(0))) { if (GeomUtil.IsEqual(prePnt, c1.GetEndPoint(1))) { continue; } cs.Add(Line.CreateBound(c1.GetEndPoint(0), c1.GetEndPoint(1))); break; } else if (GeomUtil.IsEqual(pnt, c1.GetEndPoint(1))) { if (GeomUtil.IsEqual(prePnt, c1.GetEndPoint(0))) { continue; } cs.Add(Line.CreateBound(c1.GetEndPoint(1), c1.GetEndPoint(0))); break; } else { continue; } } if (i == 200) { check = false; break; } } if (check) { Polygon plgon = new Polygon(cs); if (pls.Count == 0) { pls.Add(plgon); } else { check = true; foreach (Polygon pl in pls) { if (pl == plgon) { check = false; break; } } if (check) { pls.Add(plgon); } } } } if (pls.Count == 0) { return(false); } return(true); }
public static bool IsPointInPlane(Plane plane, XYZ point) { return(GeomUtil.IsEqual(GetSignedDistance(plane, point), 0) ? true : false); }