Exemplo n.º 1
0
 /// <summary>
 /// Overrides <see cref="CADability.Curve2D.GeneralCurve2D.MinDistance (ICurve2D)"/>
 /// </summary>
 /// <param name="Other"></param>
 /// <returns></returns>
 public override double MinDistance(ICurve2D Other)
 {
     if (Other is Line2D)
     {
         return(Other.MinDistance(this)); // bei der Linie ist es definiert
     }
     else if (Other is Circle2D)
     {
         double minDist = Curves2D.SimpleMinimumDistance(this, Other); // dort werden die Schnitt- Start- Endpunkte miteinander verrechnet
         // jetzt nur noch gucken, ob sich die beiden Kreise oder Bögen annähern
         Circle2D c     = Other as Circle2D;
         double   cdist = Geometry.Dist(c.center, center);
         if (cdist < Precision.eps)
         {
             return(minDist);                       // mit gleichen Mittelpunkten funktioniert
         }
         // das folgende nicht, aber der Abstand ist schon von SimpleMinimumDistance bestimmt
         // da dort auch die Fußpunkte verwendung finden
         if (cdist > c.radius + radius)
         {                                        // Annäherung zweier nicht schneidenden Kreise
             GeoVector2D dir = c.center - center; // von hier zum anderen
             dir.Norm();
             GeoPoint2D p1   = center + radius * dir;
             GeoPoint2D p2   = c.center + c.radius * dir.Opposite();
             double     pos1 = this.PositionOf(p1);
             double     pos2 = c.PositionOf(p2);
             if (pos1 >= 0.0 && pos1 <= 1.0 && pos2 >= 0.0 && pos2 <= 1.0)
             {
                 minDist = Math.Min(minDist, cdist - c.radius - radius);
             }
         }
         else if (radius - c.radius > cdist)
         {                                        // Kreis c liegt innerhalb von diesem Kreis
             GeoVector2D dir = c.center - center; // von hier zum anderen
             dir.Norm();
             GeoPoint2D p1   = center + radius * dir;
             GeoPoint2D p2   = c.center + c.radius * dir;
             double     pos1 = this.PositionOf(p1);
             double     pos2 = c.PositionOf(p2);
             if (pos1 >= 0.0 && pos1 <= 1.0 && pos2 >= 0.0 && pos2 <= 1.0)
             {
                 minDist = Math.Min(minDist, Geometry.Dist(p1, p2));
             }
         }
         else if (c.radius - radius > cdist)
         {       // dieser Kreis liegt innerhalb von c
             GeoVector2D dir = center - c.center;
             dir.Norm();
             GeoPoint2D p1   = c.center + c.radius * dir;
             GeoPoint2D p2   = center + radius * dir;
             double     pos1 = c.PositionOf(p1);
             double     pos2 = PositionOf(p2);
             if (pos1 >= 0.0 && pos1 <= 1.0 && pos2 >= 0.0 && pos2 <= 1.0)
             {
                 minDist = Math.Min(minDist, Geometry.Dist(p1, p2));
             }
         }
         return(minDist);
     }
     else
     {
         return(base.MinDistance(Other));
     }
 }
Exemplo n.º 2
0
        private void AdjustPeriodic(Face face2, ICurve2D curveOnFace2, GeoPoint leaveFace1)
        {
            if (!face2.Surface.IsUPeriodic && !face2.Surface.IsVPeriodic)
            {
                return;
            }
            double uperiod = 0.0, vperiod = 0.0;

            if (face2.Surface.IsUPeriodic)
            {
                uperiod = face2.Surface.UPeriod;
            }
            if (face2.Surface.IsVPeriodic)
            {
                vperiod = face2.Surface.VPeriod;
            }
            GeoPoint2D pos = face2.Surface.PositionOf(leaveFace1);

            if (!face2.area.Contains(pos, true))
            {   // dieser Punkt muss eigentlich in Area anthalten sein, er kann höchstens um die Periode verschoben sein
                bool          found = false;
                CompoundShape tst   = face2.area.Expand((uperiod + vperiod) / 100);
                if (tst.Contains(pos, true))
                {
                    found = true;
                }
                if (!found && uperiod > 0.0)
                {
                    if (tst.Contains(pos + uperiod * GeoVector2D.XAxis, true))
                    {
                        pos   = pos + uperiod * GeoVector2D.XAxis;
                        found = true;
                    }
                    if (!found && tst.Contains(pos - uperiod * GeoVector2D.XAxis, true))
                    {
                        pos   = pos - uperiod * GeoVector2D.XAxis;
                        found = true;
                    }
                }
                if (!found && vperiod > 0.0)
                {
                    if (tst.Contains(pos + vperiod * GeoVector2D.YAxis, true))
                    {
                        pos   = pos + vperiod * GeoVector2D.YAxis;
                        found = true;
                    }
                    if (!found && tst.Contains(pos - vperiod * GeoVector2D.YAxis, true))
                    {
                        pos   = pos - vperiod * GeoVector2D.YAxis;
                        found = true;
                    }
                }
            }
            // jetzt die Kurve so verschieben, dass der Punkt draufliegt
            double du = 0.0, dv = 0.0;
            double dist = curveOnFace2.MinDistance(pos);

            if (uperiod > 0.0)
            {
                double d = curveOnFace2.MinDistance(pos + uperiod * GeoVector2D.XAxis);
                if (d < dist)
                {
                    du   = -uperiod;
                    dist = d;
                }
                d = curveOnFace2.MinDistance(pos - uperiod * GeoVector2D.XAxis);
                if (d < dist)
                {
                    du   = uperiod;
                    dist = d;
                }
            }
            if (vperiod > 0.0)
            {
                double d = curveOnFace2.Distance(pos + vperiod * GeoVector2D.YAxis);
                if (d < dist)
                {
                    dv   = -vperiod;
                    dist = d;
                }
                d = curveOnFace2.Distance(pos - vperiod * GeoVector2D.YAxis);
                if (d < dist)
                {
                    dv   = vperiod;
                    dist = d;
                }
            }
            if (du != 0.0 || dv != 0.0)
            {
                curveOnFace2.Move(du, dv);
            }
        }