Beispiel #1
0
        public List <Vector3> AsPointGrid(double pointSpacing)
        {
            try
            {
                var     gridPoints   = new List <Vector3>();
                var     side1Points  = new List <Vector3>();
                var     side2Points  = new List <Vector3>();
                var     side12       = new Line(vert[1], vert[2]);
                var     side01       = new Line(vert[0], vert[1]);
                var     side02       = new Line(vert[0], vert[2]);
                Vector3 v20          = vert[0] - vert[2];
                Vector3 v02          = vert[2] - vert[0];
                Vector3 v01          = vert[1] - vert[0];
                Vector3 v12          = vert[2] - vert[1];
                Vector3 v21          = vert[1] - vert[2];
                Vector3 v10          = vert[0] - vert[1];
                double  theta0       = Math.Acos(v01.Dot(v02) / (v01.Length * v02.Length));
                double  theta1       = Math.Acos(v10.Dot(v12) / (v01.Length * v12.Length));
                double  theta2       = Math.Acos(v20.Dot(v21) / (v02.Length * v12.Length));
                double  thetaMax     = Math.Max(theta1, Math.Max(theta0, theta2));
                double  side1Spacing = pointSpacing / Math.Sin(thetaMax);
                Vector3 basePoint    = new Vector3(vert[0]);
                if (theta0 == thetaMax)
                {
                    side1Points.AddRange(GeomUtilities.BreakMany(side01, side1Spacing));
                    side2Points.AddRange(GeomUtilities.BreakMany(side02, pointSpacing));
                    basePoint = vert[0];
                }
                else
                {
                    if (theta1 == thetaMax)
                    {
                        side1Points.AddRange(GeomUtilities.BreakMany(side01, side1Spacing));
                        side2Points.AddRange(GeomUtilities.BreakMany(side12, pointSpacing));
                        basePoint = vert[1];
                    }
                    else
                    {
                        if (theta2 == thetaMax)
                        {
                            side1Points.AddRange(GeomUtilities.BreakMany(side02, side1Spacing));
                            side2Points.AddRange(GeomUtilities.BreakMany(side12, pointSpacing));
                            basePoint = vert[2];
                        }
                    }
                }

                foreach (Vector3 side1Point in side1Points)
                {
                    Vector3 translation = side1Point - basePoint;
                    foreach (Vector3 side2Point in side2Points)
                    {
                        Vector3 s2Trans = side2Point.Translate(translation);
                        if (Contains(s2Trans))
                        {
                            gridPoints.Add(s2Trans);
                        }
                    }
                }
                return(gridPoints);
            }
            catch (Exception)
            {
                throw;
            }
        }