コード例 #1
0
 public void AddRange(Vector3DCollection x)
 {
     for (int i = 0; i < x.Count; ++i)
     {
         Add(x[i]);
     }
 }
コード例 #2
0
        object ICloneable.Clone()
        {
            Vector3DCollection c = new Vector3DCollection();

            c._size = this._size;
            c._data = (T[])_data.Clone();
            return(c);
        }
コード例 #3
0
        /// <summary>
        /// Optimize the polygon by removing coincident points
        /// and collinear points.
        /// </summary>
        /// <returns>The number of points removed</returns>
        public int     Optimize()
        {
            int pointsRemoved = 0;

            // remove coincident points
            if (this.Points.Count >= 2)
            {
                int count = _points.Count;
                Vector3DCollection newPoints = new Vector3DCollection();

                for (int i = 0; i < count; i++)
                {
                    Vector3D pt0 = _points[(i + count - 1) % count];
                    Vector3D pt1 = _points[i];

                    if ((pt1 - pt0).GetMagnitude() > Math3D.EpsilonF)
                    {
                        newPoints.Add(pt1);
                    }
                }

                Debug.Assert(newPoints.Count <= _points.Count);
                if (newPoints.Count < _points.Count)
                {
                    pointsRemoved += _points.Count - newPoints.Count;
                    _points        = newPoints;
                }
            }

            // remove collinear points
            if (this.Points.Count >= 3)
            {
                int count = _points.Count;
                Vector3DCollection newPoints = new Vector3DCollection();

                for (int i = 0; i < count; i++)
                {
                    Vector3D pt0 = _points[(i + count - 1) % count];
                    Vector3D pt1 = _points[i];
                    Vector3D pt2 = _points[(i + 1) % count];

                    if (Vector3D.Orientation(pt0, pt1, pt2) != 0)
                    {
                        newPoints.Add(pt1);
                    }
                }

                Debug.Assert(newPoints.Count <= _points.Count);
                if (newPoints.Count < _points.Count)
                {
                    pointsRemoved += _points.Count - newPoints.Count;
                    _points        = newPoints;
                }
            }

            return(pointsRemoved);
        }
コード例 #4
0
ファイル: Plane3D.cs プロジェクト: 628426/Strive.NET
		//--------------------------------------------------------------------------------

		/// <summary>
		/// Clip the given polygon by the plane so that only the regions
		/// located positive of the plane remain.
		/// </summary>
		/// <param name="polygon"></param>
		public	void	ClipPolygon( Polygon3D polygon ) {

			Vector3D ptNormal = polygon.GetNormal();

			Vector3DCollection	vNewPoints = new Vector3DCollection();
			int iPoints = polygon.Points.Count;

			for ( int i = 0; i < iPoints; i ++ ) {
				Vector3D pt0 = polygon.Points[ ( i + iPoints - 1 ) % iPoints ];
				Vector3D pt1 = polygon.Points[ i ];

				int sign0 = (int) Math3D.GetSign( this.GetDistanceToPlane( pt0 ), Math3D.EpsilonF );
				int sign1 = (int) Math3D.GetSign( this.GetDistanceToPlane( pt1 ), Math3D.EpsilonF );

				if( sign0 > 0 ) {
					// line is infront
					if ( sign1 >= 0 ) {
						vNewPoints.Add( pt1 );
					}
						// line is entering plane
					else if( sign1 < 0 ) {
						Debug.Assert( sign0 > 0 && sign1 < 0 );
						vNewPoints.Add( this.GetIntersection( pt0, pt1 ) );
					}
				}
				else if( sign0 == 0 ) {
					// line is infront
					if( sign1 > 0 ) {
						vNewPoints.Add( pt1 );
					}
						// line is coplanar
					else if( sign1 == 0 ) {
						vNewPoints.Add( pt1 );
					}
						// line is behind
					else if( sign1 < 0 ) {
					}
				}
				else if( sign0 < 0 ) {
					// line is leaving plane
					if( sign1 > 0 ) {
						Debug.Assert( sign0 < 0 && sign1 > 0 );
						vNewPoints.Add( this.GetIntersection( pt0, pt1 ) );
						vNewPoints.Add( pt1 );
					}
						// line is leaving plane
					else if( sign1 == 0 ) {
						vNewPoints.Add( pt1 );
					}
						// line is behind
					else if( sign1 < 0 ) {
					}
				}
			}

			// set new points
			polygon.Points.Clear();
			polygon.Points.AddRange( vNewPoints );

			/*if( this.Points.Count >= 3 ) {
				if( Vector3D.Dot( this.GetNormal(), ptNormal ) < 0 ) {
					this.Flip();
				}
			}  */

			polygon.Optimize();
		}
コード例 #5
0
        //--------------------------------------------------------------------------------

        /// <summary>
        /// Clip the given polygon by the plane so that only the regions
        /// located positive of the plane remain.
        /// </summary>
        /// <param name="polygon"></param>
        public void    ClipPolygon(Polygon3D polygon)
        {
            Vector3D ptNormal = polygon.GetNormal();

            Vector3DCollection vNewPoints = new Vector3DCollection();
            int iPoints = polygon.Points.Count;

            for (int i = 0; i < iPoints; i++)
            {
                Vector3D pt0 = polygon.Points[(i + iPoints - 1) % iPoints];
                Vector3D pt1 = polygon.Points[i];

                int sign0 = (int)Math3D.GetSign(this.GetDistanceToPlane(pt0), Math3D.EpsilonF);
                int sign1 = (int)Math3D.GetSign(this.GetDistanceToPlane(pt1), Math3D.EpsilonF);

                if (sign0 > 0)
                {
                    // line is infront
                    if (sign1 >= 0)
                    {
                        vNewPoints.Add(pt1);
                    }
                    // line is entering plane
                    else if (sign1 < 0)
                    {
                        Debug.Assert(sign0 > 0 && sign1 < 0);
                        vNewPoints.Add(this.GetIntersection(pt0, pt1));
                    }
                }
                else if (sign0 == 0)
                {
                    // line is infront
                    if (sign1 > 0)
                    {
                        vNewPoints.Add(pt1);
                    }
                    // line is coplanar
                    else if (sign1 == 0)
                    {
                        vNewPoints.Add(pt1);
                    }
                    // line is behind
                    else if (sign1 < 0)
                    {
                    }
                }
                else if (sign0 < 0)
                {
                    // line is leaving plane
                    if (sign1 > 0)
                    {
                        Debug.Assert(sign0 < 0 && sign1 > 0);
                        vNewPoints.Add(this.GetIntersection(pt0, pt1));
                        vNewPoints.Add(pt1);
                    }
                    // line is leaving plane
                    else if (sign1 == 0)
                    {
                        vNewPoints.Add(pt1);
                    }
                    // line is behind
                    else if (sign1 < 0)
                    {
                    }
                }
            }

            // set new points
            polygon.Points.Clear();
            polygon.Points.AddRange(vNewPoints);

            /*if( this.Points.Count >= 3 ) {
             *      if( Vector3D.Dot( this.GetNormal(), ptNormal ) < 0 ) {
             *              this.Flip();
             *      }
             * }  */

            polygon.Optimize();
        }
コード例 #6
0
 /// <summary>
 /// Create a new polygon with a set of points
 /// </summary>
 /// <param name="points"></param>
 public Polygon3D(Vector3DCollection points)
 {
     Debug.Assert(points != null);
     _points.AddRange(points);
 }
コード例 #7
0
 public Vector3DCollection(Vector3DCollection x)
 {
     _data = new T[x.Count * 2];
     AddRange(x);
 }
コード例 #8
0
 public Vector3DEnumerator(Vector3DCollection col)
 {
     temp   = col;
     cursor = -1;
 }
コード例 #9
0
ファイル: Polygon3D.cs プロジェクト: 628426/Strive.NET
		/// <summary>
		/// Create a new polygon with a set of points
		/// </summary>
		/// <param name="points"></param>
		public Polygon3D( Vector3DCollection points ) {
			Debug.Assert( points != null );
			_points.AddRange( points );
		}
コード例 #10
0
ファイル: Polygon3D.cs プロジェクト: 628426/Strive.NET
		/// <summary>
		/// Optimize the polygon by removing coincident points
		/// and collinear points.
		/// </summary>
		/// <returns>The number of points removed</returns>
		public	int	Optimize() {
			int pointsRemoved = 0;

			// remove coincident points
			if( this.Points.Count >= 2 ) {
				int					count		= _points.Count;
				Vector3DCollection	newPoints	= new Vector3DCollection();

				for( int i = 0; i < count; i ++ ) {
					Vector3D pt0	= _points[ ( i + count - 1 ) % count ];
					Vector3D pt1 = _points[ i ];
				
					if( ( pt1 - pt0 ).GetMagnitude() > Math3D.EpsilonF ) {
						newPoints.Add( pt1 );
					}
				}

				Debug.Assert( newPoints.Count <= _points.Count );
				if( newPoints.Count < _points.Count ) {
					pointsRemoved += _points.Count - newPoints.Count;
					_points = newPoints;
				}
			}

			// remove collinear points
			if( this.Points.Count >= 3 ) {
				int					count		= _points.Count;
				Vector3DCollection	newPoints	= new Vector3DCollection();

				for( int i = 0; i < count; i ++ ) {
					Vector3D pt0 = _points[ ( i + count - 1 ) % count ];
					Vector3D pt1 = _points[ i ];
					Vector3D pt2 = _points[ ( i + 1 ) % count ];

					if( Vector3D.Orientation( pt0, pt1, pt2 ) != 0 ) {
						newPoints.Add( pt1 );
					}
				}

				Debug.Assert( newPoints.Count <= _points.Count );
				if( newPoints.Count < _points.Count ) {
					pointsRemoved += _points.Count - newPoints.Count;
					_points = newPoints;
				}
			}

			return	pointsRemoved;
		}
コード例 #11
0
		public Vector3DCollection(Vector3DCollection x) {
			_data = new T[x.Count * 2];
			AddRange(x);
		}
コード例 #12
0
		public Vector3DEnumerator(Vector3DCollection col) {
			temp = col;
			cursor = -1;
		}
コード例 #13
0
		object ICloneable.Clone(){
			Vector3DCollection c = new Vector3DCollection();
			c._size = this._size;
			c._data = (T[])_data.Clone();
			return c;
		}
コード例 #14
0
		public void AddRange(Vector3DCollection x) {
			for (int i=0; i < x.Count; ++i)
				Add(x[i]);
		}