Exemple #1
0
 public vec3(vec3 v)
 {
     easting  = v.easting;
     northing = v.northing;
     heading  = v.heading;
 }
Exemple #2
0
        public void FixBoundaryLine(int bndNum)
        {
            //count the points from the boundary
            int ptCount = bndLine.Count;

            //quick area test
            CalculateBoundaryArea();

            double spacing;

            //close if less then 30 ha
            if (area < 300000)
            {
                spacing = 0.5;
            }
            else if (area < 600000)
            {
                spacing = 1.0;
            }
            else
            {
                spacing = 2.0;
            }

            //first find out which side is inside the boundary
            double oneSide = glm.PIBy2;
            vec3   point   = new vec3(bndLine[2].easting - (Math.Sin(oneSide + bndLine[2].heading) * 2.0),
                                      bndLine[2].northing - (Math.Cos(oneSide + bndLine[2].heading) * 2.0), 0.0);

            //make sure boundaries are wound correctly
            if (bndNum == 0)
            {
                //outside an outer boundary means its wound clockwise
                if (!IsPointInsideBoundary(point))
                {
                    ReverseWinding();
                }
            }
            else
            {
                //inside an inner boundary means its wound clockwise
                if (IsPointInsideBoundary(point))
                {
                    ReverseWinding();
                }
                spacing = 0.5;
            }

            //make sure distance isn't too small between points on boundary
            int    bndCount = bndLine.Count;
            double distance;

            for (int i = 0; i < bndCount - 1; i++)
            {
                distance = glm.Distance(bndLine[i], bndLine[i + 1]);
                if (distance < spacing * 0.5)
                {
                    bndLine.RemoveAt(i + 1);
                    bndCount = bndLine.Count;
                    i--;
                }
            }

            //make sure distance isn't too big between points on boundary
            bndCount = bndLine.Count;

            for (int i = 0; i < bndCount; i++)
            {
                int j = i + 1;

                if (j == bndCount)
                {
                    j = 0;
                }
                distance = glm.DistanceSquared(bndLine[i], bndLine[j]);
                if (distance > 12)
                {
                    vec3 pointB = new vec3((bndLine[i].easting + bndLine[j].easting) / 2.0,
                                           (bndLine[i].northing + bndLine[j].northing) / 2.0, bndLine[i].heading);

                    bndLine.Insert(j, pointB);
                    bndCount = bndLine.Count;
                    i--;
                }
            }

            bndCount = bndLine.Count;

            for (int i = 0; i < bndCount; i++)
            {
                int j = i + 1;

                if (j == bndCount)
                {
                    j = 0;
                }
                distance = glm.DistanceSquared(bndLine[i], bndLine[j]);
                if (distance > 14)
                {
                    vec3 pointB = new vec3((bndLine[i].easting + bndLine[j].easting) / 2.0,
                                           (bndLine[i].northing + bndLine[j].northing) / 2.0, bndLine[i].heading);

                    bndLine.Insert(j, pointB);
                    bndCount = bndLine.Count;
                    i        = 0;
                }
            }


            ////make sure distance isn't too big between points on boundary

            int cnt = bndLine.Count;

            vec3[] arr = new vec3[cnt];
            bndLine.CopyTo(arr);
            bndLine.Clear();

            //add the first point of loop - it will be p1
            bndLine.Add(arr[0]);

            //use the last loop point as p0 - distance between p1 and p2 is arr[0] and arr[1]
            distance = glm.Distance(arr[0], arr[1]);

            // fill in spline points if small spacing
            if (distance > spacing)
            {
                int loopTimes = (int)(distance / spacing + 2);
                for (int j = 1; j < loopTimes; j++)
                {
                    vec3 pos = new vec3(glm.Catmull(j / (double)(loopTimes), arr[cnt - 1], arr[0], arr[1], arr[2]));
                    bndLine.Add(pos);
                }
            }

            //bndLine.Add(arr[1]);

            //do all the points in between
            for (int i = 0; i < cnt - 3; i++)
            {
                // add p1
                bndLine.Add(arr[i + 1]);

                distance = glm.Distance(arr[i + 1], arr[i + 2]);

                if (distance > spacing)
                {
                    int loopTimes = (int)(distance / spacing + 2);
                    for (int j = 1; j < loopTimes; j++)
                    {
                        vec3 pos = new vec3(glm.Catmull(j / (double)(loopTimes), arr[i], arr[i + 1], arr[i + 2], arr[i + 3]));
                        bndLine.Add(pos);
                    }
                }
            }

            bndLine.Add(arr[cnt - 2]);

            //second last to last point
            distance = glm.Distance(arr[cnt - 1], arr[cnt - 2]);

            // fill in spline points if small spacing
            if (distance > spacing)
            {
                int loopTimes = (int)(distance / spacing + 2);
                for (int j = 1; j < loopTimes; j++)
                {
                    vec3 pos = new vec3(glm.Catmull(j / (double)(loopTimes), arr[cnt - 3], arr[cnt - 2], arr[cnt - 1], arr[0]));
                    bndLine.Add(pos);
                }
            }

            //add last point
            bndLine.Add(arr[cnt - 1]);

            //last to first point
            distance = glm.Distance(arr[cnt - 1], arr[0]);

            // fill in spline points if small spacing
            if (distance > spacing)
            {
                int loopTimes = (int)(distance / spacing + 2);
                for (int j = 1; j < loopTimes; j++)
                {
                    vec3 pos = new vec3(glm.Catmull(j / (double)(loopTimes), arr[cnt - 2], arr[cnt - 1], arr[0], arr[1]));
                    bndLine.Add(pos);
                }
            }

            //make sure headings are correct for calculated points
            CalculateBoundaryHeadings();
        }