//offsets an input line by a given distance inside a poly public static Line2d OffsetLineInsidePoly(Line2d lineInp, Polygon2d poly, double distance) { if (lineInp == null || !ValidateObject.CheckPoly(poly)) { return(null); } Point2d ptStart = OffsetLinePointInsidePoly(lineInp, lineInp.StartPoint, poly, distance); Vector2d vec = new Vector2d(lineInp.StartPoint, ptStart); Point2d ptEnd = VectorUtility.VectorAddToPoint(lineInp.EndPoint, vec); return(new Line2d(ptStart, ptEnd)); }
//offsets an input line by a given distance public static Line2d Offset(Line2d lineInp, double distance) { if (lineInp == null) { return(null); } Point2d ptStart = OffsetLinePoint(lineInp, lineInp.StartPoint, distance); Vector2d vec = new Vector2d(lineInp.StartPoint, ptStart); Point2d ptEnd = VectorUtility.VectorAddToPoint(lineInp.EndPoint, vec); return(new Line2d(ptStart, ptEnd)); }
//computes the UGR value internal static double CalculateUGR(List <Point3d> lightPts, Point3d observer, List <double> posList, double lightSize = 2, double recompute = 1) { double backLum = 10; double lumin = 10; double angleEach = 0; double guthPos = 2; double value = 0; double summation = 0; int pos = 0, m = 0; for (int i = 0; i < lightPts.Count; i++) { if (m < posList.Count && i == (int)posList[m]) { lumin = recompute * lumin; m += 1; } else { lumin = 10; } if (lightPts[i].X > observer.X) { Point2d ptLight2d = ConvertToPoint2d(lightPts[i]); Point2d ptObserver2d = ConvertToPoint2d(observer); double distance = PointUtility.DistanceBetweenPoints(ptLight2d, ptObserver2d); guthPos = distance; Point3d lightPt1 = new Point3d((lightPts[i].X - lightSize), (lightPts[i].Y - lightSize), lightPts[i].Z); Point3d lightPt2 = new Point3d((lightPts[i].X + lightSize), (lightPts[i].Y + lightSize), lightPts[i].Z); Vector3d vec1 = new Vector3d(observer, lightPt1); Vector3d vec2 = new Vector3d(observer, lightPt2); angleEach = VectorUtility.AngleBetweenVec3d(vec1, vec2); summation += (lumin * lumin * angleEach) / (guthPos * guthPos); } } value = (0.25 / backLum) * summation; if (value == 0) { return(0); } double ugr = 8 * Math.Log10(value); if (ugr < 0) { ugr = 0; } return(ugr); }
internal static Dictionary <string, object> AddPointToFitPoly(Polygon2d poly, Polygon2d containerPoly, double distance = 16, double area = 0, double thresDistance = 10, double recompute = 5) { if (!ValidateObject.CheckPoly(poly)) { return(null); } if (distance < 1) { return(null); } Dictionary <string, object> lineOffsetCheckObj = ValidateObject.CheckLinesOffsetInPoly(poly, containerPoly, distance); List <int> indicesFalse = (List <int>)lineOffsetCheckObj["IndicesFalse"]; List <List <Point2d> > pointsFalse = (List <List <Point2d> >)lineOffsetCheckObj["PointsOutside"]; List <Point2d> probPointList = new List <Point2d>(); List <Point2d> polyNewPoints = new List <Point2d>(); List <Line2d> falseLines = new List <Line2d>(); Point2d ptNewEnd = new Point2d(0, 0); Point2d otherPt = new Point2d(0, 0); Point2d probPt = new Point2d(0, 0); Line2d line = new Line2d(ptNewEnd, otherPt); int count = 0, maxTry = 50; double ratio = 0, increment = .25; bool added = false, checkOffPtNew = false; for (int i = 0; i < poly.Points.Count; i++) { int a = i, b = i + 1; if (i == poly.Points.Count - 1) { b = 0; } polyNewPoints.Add(poly.Points[a]); if (indicesFalse[i] > -1) { falseLines.Add(poly.Lines[i]); } if (poly.Lines[i].Length > thresDistance && indicesFalse[i] > -1 && pointsFalse[i] != null && pointsFalse[i].Count == 1 && !added && LayoutUtility.CheckLineGetsExternalWall(poly.Lines[i], containerPoly)) { probPointList.AddRange(pointsFalse[i]); probPt = pointsFalse[i][0]; line = poly.Lines[i]; Point2d midPt = LineUtility.LineMidPoint(line); if (line.StartPoint.Compare(probPt)) { otherPt = line.EndPoint; } else { otherPt = line.StartPoint; } Vector2d vecToOther = new Vector2d(probPt, otherPt); while (!checkOffPtNew && count < maxTry && ratio < 0.9) { ratio += increment; ptNewEnd = VectorUtility.VectorAddToPoint(probPt, vecToOther, ratio); Point2d offPtNew = LineUtility.OffsetLinePointInsidePoly(line, ptNewEnd, poly, distance); checkOffPtNew = GraphicsUtility.PointInsidePolygonTest(poly, offPtNew); count += 1; } polyNewPoints.Add(ptNewEnd); added = true; } } Polygon2d polyAdded = new Polygon2d(polyNewPoints, 0); return(new Dictionary <string, object> { { "PolyAddedPts", (polyAdded) }, { "ProblemPoint", (probPt) }, { "IsAdded", (added) }, { "PointAdded", (ptNewEnd) }, { "Trials", (count) }, { "FinalRatio", (ratio) }, { "ProblemLine", (line) }, { "ProblemPtsList", (probPointList) }, { "FalseLineList", (falseLines) } }); }