Example #1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>	Catch special circle events and disallow them. </summary>
        /// <remarks>
        ///     In the book it says to add a circle event if it isn't already in the queue.  That seems a bit
        ///     wasteful to me - search the whole queue every time you add a circle event?  There has to be a
        ///     better way.  This routine is the alternative.  Just a few checks on the circle parameters
        ///     ensures that they'll only enter the queue once.  Much better than a searh of the queue. It's essentially
        ///     an extension of the counter clockwise generic routine which deals with collinear points as though
        ///     they were points on an infinitely large circle.
        /// </remarks>
        /// <param name="pt1">	First point for proposed circle event. </param>
        /// <param name="pt2">	Second point for proposed circle event. </param>
        /// <param name="pt3">	Third point for proposed circle event. </param>
        /// <returns>	Acceptable if less than or equal to zero, else rejected. </returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        // ReSharper disable once InconsistentNaming
        internal static int ICcwVoronoi(Vector pt1, Vector pt2, Vector pt3)
        {
            // Do the geometry to see if they're clockwise
            var iSign = Geometry2D.ICcw(pt1, pt2, pt3);

            // If they're not collilnear
            if (iSign != 0)
            {
                // Return their orientation
                return(iSign);
            }

            // RQS- Treat the Collinear points as though they are on an infinite circle
            var dx1 = pt2.X - pt1.X;
            var dx2 = pt3.X - pt1.X;
            var dy1 = pt2.Y - pt1.Y;
            var dy2 = pt3.Y - pt1.Y;

            if (dx1 * dx2 < 0 || dy1 * dy2 < 0)
            {
                return(-1);
            }

            if (dx1 * dx1 + dy1 * dy1 < dx2 * dx2 + dy2 * dy2)
            {
                return(+1);
            }
            // -RQS

            return(0);
        }
Example #2
0
        /// <summary>
        /// 设置当前起点位置
        /// </summary>
        /// <param name="p"></param>
        public void SetPoint(Vector2D p)
        {
            if (GeometryShape == null)
            {
                this.start       = p;
                this.end         = p;
                this.Geometry2ds = new List <Geometry2D>();
                for (int i = 0; i < number; i++)
                {
                    Geometry2D gs = this.tagert.Copy();
                    this.Geometry2ds.Add(gs);
                }


                if (DrawStartEvent != null)
                {
                    this.Geometry2ds.ForEach(x =>
                    {
                        this.GeometryShape             = x;
                        this.GeometryShape.IsActioning = true;
                        DrawStartEvent(new ActionEventArgs(x));
                    });
                }
            }
            else
            {
                this.end = p;
                //完成当前的移动
                this.Complete();
            }
        }
Example #3
0
        private static bool TestFor_AABB(TrackedObjectData item, Vector2 min, Vector2 max)
        {
            var itemMin = item.AABB.Min;
            var itemMax = item.AABB.Max;

            return(Geometry2D.IsOverlapping(itemMin, itemMax, min, max));
        }
Example #4
0
        /// <summary>
        /// <para>Returns a random point that is inside the unit circle.</para>
        /// <para>Lenght: 0 (inclusive) - 1 (exclusive), Rotation: 0 (inclusive) - 360 (exclusive)</para>
        /// </summary>
        /// <remarks> Unit Circle: A circle whose center is on the origin, with a radius of 1. </remarks>
        public Vector2 InUnitCircle()
        {
            var rndLength = Mathf.Sqrt(_parent.Float.Next01());
            var rndAngle  = _parent.Angle.NextInRadians();

            return(Geometry2D.PolarToCartesian(rndLength, rndAngle));
        }
 /// <summary>
 /// 在界面上添加一个
 /// </summary>
 /// <param name="v"></param>
 public void AddDrawingVisual(Geometry2D g)
 {
     DrawingVisuals.Add(g);
     this.AddVisual(g);
     g.Update();
     IsUpdated = true;
 }
Example #6
0
 static public double OffsetInSpace(Tiler.Settings settings, double p = 0, double q = 0, double r = 1)
 {
     return
         (p * Geometry2D.GetTrianglePSide(settings.P, settings.Q) +
          q * Geometry2D.GetTriangleQSide(settings.P, settings.Q) +
          r * Geometry2D.GetTriangleHypotenuse(settings.P, settings.Q));
 }
 /// <summary>
 /// 移除一个临时可见对象
 /// </summary>
 /// <param name="e"></param>
 public void RemoveTemporaryVisual(Geometry2D g)
 {
     TemporaryVisuals.Remove(g);
     this.RemoveVisual(g);
     g.Update();
     IsUpdated = true;
 }
 /// <summary>
 /// 添加临时可见对象
 /// </summary>
 /// <param name="e"></param>
 public void AddTemporaryVisual(Geometry2D g)
 {
     TemporaryVisuals.Add(g);
     this.AddVisual(g);
     g.Update();
     IsUpdated = true;
 }
 /// <summary>
 /// 移除一个参照对象
 /// </summary>
 /// <param name="e"></param>
 public void RemoveAuxiliaryVisual(Geometry2D g)
 {
     AuxiliaryVisuals.Remove(g);
     this.RemoveVisual(g);
     g.Update();
     IsUpdated = true;
 }
Example #10
0
 /// <summary>
 /// 删除界面上一个图形元素
 /// </summary>
 /// <param name="gs"></param>
 public void RemoveGeometryShape(Geometry2D gs)
 {
     if (gs != null)
     {
         this.DrawingControl.RemoveDrawingVisual(gs);
     }
 }
Example #11
0
 /// <summary>
 /// 指定当前的目标图形
 /// </summary>
 /// <param name="shape"></param>
 public void SetIntersectGeometry(IntersectGeometry shape)
 {
     if (shape.GeometryShape != null && shape.IntersectPoint.Line != null)
     {
         if (this.tagert == null)
         {
             if (this.Filter != null)
             {
                 //判断是不是过滤的对象
                 if (this.Filter.AllowElement(shape.GeometryShape))
                 {
                     this.tagert     = shape.GeometryShape;
                     this.targetLine = shape.IntersectPoint.Line;
                     TipMessage      = "请选择参照边";
                 }
             }
         }
         else
         {
             this.referShape = shape.GeometryShape;
             this.referLine  = shape.IntersectPoint.Line;
             this.Complete();
         }
     }
 }
Example #12
0
        //calculates the normal of the two given points
        public double Normal(TPoint2D p1, TPoint2D p2, bool leftNormal)
        {
            var vec    = Vector2d.Subtract(p2.AsVector(), p1.AsVector());
            var normal = leftNormal ? vec.PerpendicularLeft : vec.PerpendicularRight;

            return(ConvertToHullAngle(Geometry2D.Angle(normal)));
        }
 /// <summary>
 /// 添加一个参照对象
 /// </summary>
 /// <param name="e"></param>
 public void AddAuxiliaryVisual(Geometry2D g)
 {
     AuxiliaryVisuals.Add(g);
     this.AddVisual(g);
     g.Update();
     IsUpdated = true;
 }
Example #14
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>	Order the three edges around this vertex. </summary>
        /// <remarks>	Darrellp, 2/19/2011. </remarks>
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        internal void OrderEdges()
        {
            // If this vertex has already been ordered or is a vertex at infinity
            if (_fAlreadyOrdered || FAtInfinity)
            {
                return;
            }

            // If we have the usual case of 3 edges
            if (CtEdges == 3)
            {
                // Get the points at the other end of each of the 3 edges
                var pt0 = PtAtOtherEnd(FortuneEdges[0]);
                var pt1 = PtAtOtherEnd(FortuneEdges[1]);
                var pt2 = PtAtOtherEnd(FortuneEdges[2]);

                // If ordered incorrectly
                if (Geometry2D.ICcw(pt0, pt1, pt2) > 0)
                {
                    // Swap the first two
                    var edge0 = FortuneEdges[0];
                    FortuneEdges[0] = FortuneEdges[1];
                    FortuneEdges[1] = edge0;
                }

                // Mark ourselves as ordered
                _fAlreadyOrdered = true;
            }
            else
            {
                // Do the more complicated sort
                FortuneEdges.Sort(CompareEdges);
                _fAlreadyOrdered = true;
            }
        }
Example #15
0
        private static IEnumerable <HoneycombDef> GetEuclidImageSet()
        {
            for (int p = 3; p <= 8; p++)
            {
                for (int q = 3; q <= 8; q++)
                {
                    for (int r = 3; r <= 8; r++)
                    {
                        if (!(Geometry2D.GetGeometry(p, q) == Geometry.Euclidean ||
                              Geometry2D.GetGeometry(q, r) == Geometry.Euclidean))
                        {
                            continue;
                        }

                        // Do the last as infinity
                        System.Func <int, int> iSafe = input => input == 8 ? -1 : input;
                        yield return(new HoneycombDef()
                        {
                            P = iSafe(p),
                            Q = iSafe(q),
                            R = iSafe(r)
                        });
                    }
                }
            }
        }
Example #16
0
        public static void DoStuff(Settings settings)
        {
            HoneycombDef imageData = new HoneycombDef(settings.P, settings.Q, settings.R);

            ////////////////////////////////////////////////////////////// Various things we've run over time.
            //Sandbox.CalcSelfSimilarityScale();
            //Sandbox.Check_pq_Distances();
            //HyperidealSquares();
            //S3.Hypercube();
            //R3.Geometry.Euclidean.GenEuclidean();
            //HoneycombGen.OneHoneycombOldCode();
            //AnimateCell( imageData );
            //CreateCellPovRay( imageData, "cell.pov" );
            //CreateSimplex( imageData );
            //HoneycombGen_old.OneHoneycombNew( new HoneycombDef() { P = imageData.P, Q = imageData.Q, R = imageData.R } );
            //SphericalAnimate( imageData );
            OneImage(settings);

            HoneycombDef[] scaleLarger = GetImageSet().Where(h =>
                                                             Geometry2D.GetGeometry(h.P, h.Q) == Geometry.Euclidean ||
                                                             Geometry2D.GetGeometry(h.P, h.Q) == Geometry.Spherical).ToArray();
            int count = scaleLarger.Length;
            //foreach( HoneycombAndView h in scaleLarger )
            //	Trace.WriteLine( h.FormatFilename() );

            //BatchRun( settings );
        }
        public double GetMinEpsilon(TPoint2D shortcutEnd, bool doExtremePointQueries)
        {
            double[] distances;

            if (doExtremePointQueries)
            {
                //O(4log n)
                distances = new []
                {
                    Geometry2D.Distance(shortcutStart, shortcutEnd, upper.ExtremePointFromShortcutLine(shortcutEnd)),
                    Geometry2D.Distance(shortcutStart, shortcutEnd, lower.ExtremePointFromShortcutLine(shortcutEnd)),
                    upper.ExtremeDistanceLeftOfShortcut(shortcutEnd),
                    lower.ExtremeDistanceLeftOfShortcut(shortcutEnd)
                };
            }
            else
            {
                //O(2log n)
                distances = new []
                {
                    upper.ExtremeDistanceLeftOfShortcut(shortcutEnd),
                    lower.ExtremeDistanceLeftOfShortcut(shortcutEnd)
                };
            }

            return(distances.Max());
        }
Example #18
0
            private static void ConnectTop(List <Vector2> left, List <Vector2> right, Vector2 A, Vector2 B, float width)
            {
                Vector2 eAB = (B - A).normalized;
                Vector2 tAB = Geometry2D.RotateVector(eAB, Mathf.PI / 2);

                left.Add(A + tAB * width / 2);
                right.Add(A - tAB * width / 2);
            }
Example #19
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>	Compare edges clockwise around this vertex. </summary>
        /// <remarks>	Darrellp, 2/19/2011. </remarks>
        /// <param name="e1">	The first WeEdge. </param>
        /// <param name="e2">	The second WeEdge. </param>
        /// <returns>	+1 if they are CW around the generator, -1 if they're CCW, 0 if neither. </returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        private int CompareEdges(WeEdge e1, WeEdge e2)
        {
            // Compare edges for clockwise order
            var fe1 = (FortuneEdge)e1;
            var fe2 = (FortuneEdge)e2;

            return(Geometry2D.ICompareCw(Pt, fe1.PolyOrderingTestPoint, fe2.PolyOrderingTestPoint));
        }
        public Wedge(TPoint2D origin, double startAngle, double endAngle)
        {
            Origin = origin;

            StartAngle  = Geometry2D.SimplifyRadians(startAngle);
            EndAngle    = Geometry2D.SimplifyRadians(endAngle);
            IsFullPlane = false;
        }
Example #21
0
 /// <summary>
 /// Return the distance we represent for a particular {p,q} tiling.
 /// </summary>
 public double Dist(int p, int q)
 {
     return
         (this.P * Geometry2D.GetTrianglePSide(p, q) +
          this.Q * Geometry2D.GetTriangleQSide(p, q) +
          this.R * Geometry2D.GetTriangleHypotenuse(p, q) +
          this.D);
 }
Example #22
0
 internal override void Mirror(Geometry2D target, Line2D mirrorLine)
 {
     if (target is ColumnGeometry)
     {
         ColumnGeometry column = (target as ColumnGeometry);
         this.start = TransformUtil.Mirror(column.start, mirrorLine);
         this.end   = TransformUtil.Mirror(column.end, mirrorLine);
     }
 }
Example #23
0
 internal override void Mirror(Geometry2D target, Line2D mirrorLine)
 {
     if (target is CircleGeometry)
     {
         CircleGeometry circle = (target as CircleGeometry);
         this.start = TransformUtil.Mirror(circle.start, mirrorLine);
         this.end   = TransformUtil.Mirror(circle.end, mirrorLine);
     }
 }
Example #24
0
 /// <summary>
 /// 对当前图形进行镜像处理
 /// </summary>
 /// <param name="mirrorLine"></param>
 internal override void Mirror(Geometry2D target, Line2D mirrorLine)
 {
     if (target is LineGeometry)
     {
         LineGeometry line = (target as LineGeometry);
         this.start = TransformUtil.Mirror(line.start, mirrorLine);
         this.end   = TransformUtil.Mirror(line.end, mirrorLine);
     }
 }
Example #25
0
        /// <summary>
        /// 指定当前物品高亮
        /// </summary>
        /// <param name="g"></param>
        public void SetHightLight(Geometry2D g)
        {
            List <Line2D> lines = g.Lines;

            if (lines != null)
            {
                this.SetHightLight(lines);
            }
        }
Example #26
0
 internal override void Mirror(Geometry2D target, Line2D mirrorLine)
 {
     if (target is BeamGeometry)
     {
         BeamGeometry beam = (target as BeamGeometry);
         this.start = TransformUtil.Mirror(beam.start, mirrorLine);
         this.end   = TransformUtil.Mirror(beam.end, mirrorLine);
     }
 }
Example #27
0
 internal override void Mirror(Geometry2D target, Line2D mirrorLine)
 {
     if (target is EllipseGeometry)
     {
         EllipseGeometry ellipse = (target as EllipseGeometry);
         this.central   = TransformUtil.Mirror(ellipse.central, mirrorLine);
         this.reference = TransformUtil.Mirror(ellipse.reference, mirrorLine);
     }
 }
Example #28
0
 /// <summary> Constructor </summary>
 public Triangle2D(Vector2 a, Vector2 b, Vector2 c)
 {
     _a    = a;
     _b    = b;
     _c    = c;
     _A    = Vector2.Distance(b, c);
     _B    = Vector2.Distance(a, c);
     _C    = Vector2.Distance(a, c);
     _area = Geometry2D.ShoelaceFormula(a, b, c);
 }
Example #29
0
        internal override void Mirror(Geometry2D target, Line2D mirrorLine)
        {
            if (target is MeasureGeometry)
            {
                MeasureGeometry measure = (target as MeasureGeometry);

                this.start = TransformUtil.Mirror(measure.start, mirrorLine);
                this.end   = TransformUtil.Mirror(measure.end, mirrorLine);
            }
        }
Example #30
0
 /// <summary>
 /// 图形镜像
 /// </summary>
 /// <param name="target"></param>
 /// <param name="mirrorLine"></param>
 internal override void Mirror(Geometry2D target, Line2D mirrorLine)
 {
     if (target is BeamGeometry)
     {
         ArcGeometry arc = (target as ArcGeometry);
         this.start   = TransformUtil.Mirror(arc.start, mirrorLine);
         this.end     = TransformUtil.Mirror(arc.end, mirrorLine);
         this.central = TransformUtil.Mirror(arc.central, mirrorLine);
     }
 }
Example #31
0
 /// <summary>
 /// Compute the distance between the specified points a and b in the Cartesian Plan.
 /// </summary>
 /// <param name='a'>
 /// Point a with x and y
 /// </param>
 /// <param name='b'>
 /// Point b with x and y
 /// </param>
 public static double Distance(Geometry2D.Point2D a, Geometry2D.Point2D b)
 {
     return Math.Sqrt(Math.Pow (a.X - b.X)+Math.Pow(a.Y - b.Y));
 }
Example #32
0
 ///<exclude/>
 public bool Equals(Geometry2D other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return other._Pose.Equals(_Pose) && other._Size.Equals(_Size);
 }