Exemplo n.º 1
0
        //visualize glare lines
        public static List <Line3d> VisualizeGlareLines(List <Point3d> floorPoints, List <Point3d> furniturePoints,
                                                        List <Point3d> lightPoints, double threshDist = 10, int index = 0)
        {
            for (int i = 0; i < floorPoints.Count; i++)
            {
                List <Point3d> selectedPts = new List <Point3d>();
                Point2d        pt2FloorPt  = ConvertToPoint2d(floorPoints[i]);
                for (int j = 0; j < furniturePoints.Count; j++)
                {
                    Point2d pt2Furniture = ConvertToPoint2d(furniturePoints[j]);
                    double  distance     = PointUtility.DistanceBetweenPoints(pt2Furniture, pt2FloorPt);
                    if (distance < threshDist)
                    {
                        selectedPts.Add(furniturePoints[j]);
                    }
                }// end of j for loop
                if (selectedPts.Count > 1)
                {
                    lightPoints.AddRange(selectedPts);
                }
            }
            List <Line3d> glareLines = new List <Line3d>();

            for (int i = 0; i < lightPoints.Count; i++)
            {
                if (lightPoints[i].X > floorPoints[index].X)
                {
                    glareLines.Add(new Line3d(floorPoints[index], lightPoints[i]));
                }
            }
            return(glareLines);
        }
Exemplo n.º 2
0
        //check if a given polygon2d has any of its longer edges aligned with any edge of the containerpolygon2d
        internal static bool CheckPolyGetsExternalWall(Polygon2d poly, Polygon2d containerPoly, double shortEdgeDist = 16, bool tag = true)
        {
            bool check = false;

            if (!ValidateObject.CheckPoly(poly))
            {
                return(check);
            }
            Polygon2d polyReg = new Polygon2d(null);

            //make given polys reduce number of points
            if (tag)
            {
                polyReg = new Polygon2d(poly.Points);
            }
            else
            {
                polyReg = poly;
            }
            Polygon2d containerPolyReg = new Polygon2d(containerPoly.Points);

            for (int i = 0; i < polyReg.Points.Count; i++)
            {
                int    a = i, b = i + 1;
                double eps = 0;
                if (i == polyReg.Points.Count - 1)
                {
                    b = 0;
                }
                double        distance    = PointUtility.DistanceBetweenPoints(polyReg.Points[a], polyReg.Points[b]);
                List <double> spansSorted = PolygonUtility.GetPolySpan(containerPolyReg);
                if (distance <= spansSorted[0] * 0.75)
                {
                    continue;
                }
                Line2d lineA = Line2d.ByStartPointEndPoint(polyReg.Points[a], polyReg.Points[b]);
                for (int j = 0; j < containerPolyReg.Points.Count; j++)
                {
                    int c = j, d = j + 1;
                    if (j == containerPolyReg.Points.Count - 1)
                    {
                        d = 0;
                    }
                    Line2d lineB = Line2d.ByStartPointEndPoint(containerPolyReg.Points[c], containerPolyReg.Points[d]);
                    check = GraphicsUtility.LineAdjacencyCheck(lineA, lineB, eps);
                    if (check)
                    {
                        break;
                    }
                }
                if (check)
                {
                    break;
                }
            }
            return(check);
        }
Exemplo n.º 3
0
        // finds the angle between two points wrt Origin - not sure
        internal static double AngleBetweenPoint2d(Point2d A, Point2d center)
        {
            double angle = Math.Acos((A.X - center.X) / PointUtility.DistanceBetweenPoints(center, A));

            if (A.Y < center.Y)
            {
                angle = Math.PI + Math.PI - angle; //360-angle
            }
            return(angle);                         //return angle*180/Math.PI;
        }
Exemplo n.º 4
0
        //line and polygon intersection - not using now
        public static Line2d LinePolygonIntersectionReturnLine(List <Point2d> poly, Line2d testLine, Point2d centerPt)
        {
            Random ran  = new Random();
            double dist = 10000000000000000;
            SortedDictionary <double, Line2d> sortedIntersectionLines = new SortedDictionary <double, Line2d>();
            List <Point2d> ptList = new List <Point2d>();
            double         x      = (testLine.StartPoint.X + testLine.EndPoint.X) / 2;
            double         y      = (testLine.StartPoint.Y + testLine.EndPoint.Y) / 2;
            Point2d        midPt  = new Point2d(x, y);
            Line2d         intersectedLineInPoly = null;
            int            count = 0;

            for (int i = 0; i < poly.Count - 1; i++)
            {
                Point2d pt1  = poly[i];
                Point2d pt2  = poly[i + 1];
                Line2d  edge = new Line2d(pt1, pt2);

                if (LineLineIntersectionNew(edge, testLine) != null)
                {
                    double  xE        = (edge.StartPoint.X + edge.EndPoint.X) / 2;
                    double  yE        = (edge.StartPoint.Y + edge.EndPoint.Y) / 2;
                    Point2d EdgeMidPt = new Point2d(xE, yE);
                    double  checkDist = PointUtility.DistanceBetweenPoints(centerPt, EdgeMidPt);
                    try
                    {
                        sortedIntersectionLines.Add(checkDist, edge);
                    }
                    catch (Exception)
                    {
                        double eps     = ran.NextDouble() * 2;
                        double newDist = checkDist - eps;
                        sortedIntersectionLines.Add(newDist, edge);
                    }
                    intersectedLineInPoly = edge;
                    count += 1;
                }
            }
            if (sortedIntersectionLines.Count > 0)
            {
                foreach (KeyValuePair <double, Line2d> p in sortedIntersectionLines)
                {
                    intersectedLineInPoly = p.Value;
                    break;
                }
            }
            else
            {
                intersectedLineInPoly = null;
            }
            return(intersectedLineInPoly);
        }
Exemplo n.º 5
0
        //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);
        }
Exemplo n.º 6
0
        //sorts list of points by distance from a given point
        public static List <Point2d> SortPointsByDistanceFromPoint(List <Point2d> ptList, Point2d testPoint)
        {
            List <Point2d> sortedPtList = new List <Point2d>();
            List <double>  distanceList = new List <double>();
            List <int>     indexList    = new List <int>();

            for (int i = 0; i < ptList.Count; i++)
            {
                distanceList.Add(PointUtility.DistanceBetweenPoints(ptList[i], testPoint));
            }
            indexList = BasicUtility.SortIndex(distanceList);
            for (int i = 0; i < indexList.Count; i++)
            {
                sortedPtList.Add(ptList[indexList[i]]);
            }
            return(sortedPtList);
        }
Exemplo n.º 7
0
        internal static Dictionary <string, object> PolygonPolygonCommonEdgeDict(Polygon2d poly, Polygon2d other)
        {
            bool check = false;

            if (poly == null || other == null)
            {
                return(null);
            }

            double    eps      = 200;
            Polygon2d polyReg  = new Polygon2d(poly.Points);
            Polygon2d otherReg = new Polygon2d(other.Points);
            Dictionary <string, object> UpdatedCenters = ComputePolyCentersAlign(polyReg, otherReg);

            Point2d centerPoly  = (Point2d)UpdatedCenters["CenterPolyA"];
            Point2d centerOther = (Point2d)UpdatedCenters["CenterPolyB"];

            polyReg  = (Polygon2d)UpdatedCenters["PolyA"];
            otherReg = (Polygon2d)UpdatedCenters["PolyB"];
            //make vectors
            Vector2d centerToCen  = new Vector2d(centerPoly, centerOther);
            Vector2d centerToCenX = new Vector2d(centerToCen.X, 0);
            Vector2d centerToCenY = new Vector2d(0, centerToCen.Y);
            //make centerLine
            Line2d   centerLine = new Line2d(centerPoly, centerOther);
            Vector2d keyVec;

            if (centerToCenX.Length > centerToCenY.Length)
            {
                keyVec = new Vector2d(centerToCenX.X, centerToCenX.Y);
            }
            else
            {
                keyVec = new Vector2d(centerToCenY.X, centerToCenY.Y);
            }
            //check line poly intersection between centertocen vector and each polys
            Line2d lineInPolyReg  = CodeToBeTested.LinePolygonIntersectionReturnLine(polyReg.Points, centerLine, centerOther);
            Line2d lineInOtherReg = CodeToBeTested.LinePolygonIntersectionReturnLine(otherReg.Points, centerLine, centerPoly);

            //find distance d1 and d2 from two centers to linepolyintersection line
            Point2d projectedPtOnPolyReg  = GraphicsUtility.ProjectedPointOnLine(lineInPolyReg, centerPoly);
            Point2d projectedPtOnOtherReg = GraphicsUtility.ProjectedPointOnLine(lineInOtherReg, centerOther);

            double dist1 = PointUtility.DistanceBetweenPoints(centerPoly, projectedPtOnPolyReg);
            double dist2 = PointUtility.DistanceBetweenPoints(centerOther, projectedPtOnOtherReg);

            double totalDistance = 2 * (dist1 + dist2);
            Line2d lineMoved     = new Line2d(lineInPolyReg.StartPoint, lineInPolyReg.EndPoint);

            lineMoved = LineUtility.Move(lineMoved, centerPoly);
            Point2d projectedPt = GraphicsUtility.ProjectedPointOnLine(lineMoved, centerOther);
            double  distance    = PointUtility.DistanceBetweenPoints(projectedPt, centerOther);

            bool isNeighbour = false;

            if (totalDistance - eps < distance && distance < totalDistance + eps)
            {
                isNeighbour = true;
            }
            else
            {
                isNeighbour = false;
            }

            return(new Dictionary <string, object>
            {
                { "Neighbour", (isNeighbour) },
                { "SharedEdgeA", (lineInPolyReg) },
                { "SharedEdgeB", (lineInOtherReg) },
                { "LineMoved", (lineMoved) },
                { "CenterToCenterLine", (centerLine) },
                { "CenterPolyPoint", (centerPoly) },
                { "CenterPolyOtherPoint", (centerOther) },
            });
        }
Exemplo n.º 8
0
        //compute glare  values
        public static List <List <double> > ComputeGlareValues(List <Point3d> floorPoints, List <Point3d> furniturePoints,
                                                               List <Point3d> lightPoints, double threshDist = 10, double lightSize = 3, double numSpecialLights = 2, double recompute = 1)
        {
            int           pos      = 0;
            List <double> posList  = new List <double>();
            List <double> distList = new List <double>();
            List <double> ugrList  = new List <double>();
            int           count    = 0;
            double        numD     = BasicUtility.RandomBetweenNumbers(new Random(), 0.1, 0.35);

            for (int i = 0; i < numSpecialLights; i++)
            {
                posList.Add(lightPoints.Count * (i + 1) * numD);
            }

            pos = (int)(lightPoints.Count * 0.20);
            for (int i = 0; i < floorPoints.Count; i++)
            {
                List <Point3d> selectedPts = new List <Point3d>();
                Point2d        pt2FloorPt  = ConvertToPoint2d(floorPoints[i]);
                for (int j = 0; j < furniturePoints.Count; j++)
                {
                    Point2d pt2Furniture = ConvertToPoint2d(furniturePoints[j]);
                    double  distance     = PointUtility.DistanceBetweenPoints(pt2Furniture, pt2FloorPt);
                    distList.Add(distance);
                    if (distance < threshDist)
                    {
                        selectedPts.Add(furniturePoints[j]);
                    }
                }// end of j for loop
                if (selectedPts.Count > 0)
                {
                    lightPoints.AddRange(selectedPts);
                }
                double ugrValue = CalculateUGR(lightPoints, floorPoints[i], posList, lightSize, recompute);
                ugrList.Add(ugrValue);
                count += 1;
            }
            List <double> val2 = new List <double>(), val3 = new List <double>();

            for (int n = 0; n < ugrList.Count; n++)
            {
                val2.Add(0); val3.Add(0);
            }
            List <double>         ugrListNormalized = BasicUtility.NormalizeList(ugrList, 0, 255);
            List <List <double> > result            = new List <List <double> >();

            result.Add(ugrListNormalized);
            result.Add(val2);
            result.Add(val3);
            result.Add(distList);
            result.Add(new List <double> {
                count
            });
            result.Add(ugrList);
            result.Add(new List <double> {
                lightSize
            });
            result.Add(posList);
            return(result);
        }