00001 /* $NoKeywords: $ */ 00002 /* 00003 // 00004 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved. 00005 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert 00006 // McNeel & Associates. 00007 // 00008 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. 00009 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF 00010 // MERCHANTABILITY ARE HEREBY DISCLAIMED. 00011 // 00012 // For complete openNURBS copyright information see <http://www.opennurbs.org>. 00013 // 00015 */ 00016 00017 #if !defined(ON_POLYLINE_INC_) 00018 #define ON_POLYLINE_INC_ 00019 00020 class ON_CLASS ON_Polyline : public ON_3dPointArray 00021 { 00022 public: 00023 ON_Polyline(); 00024 ON_Polyline(const ON_3dPointArray&); 00025 ON_Polyline& operator=(const ON_3dPointArray&); 00026 ~ON_Polyline(); 00027 00028 // Description: 00029 // Create a regular polygon inscribed in a circle. 00030 // The vertices of the polygon will be on the circle. 00031 // Parameters: 00032 // circle - [in] 00033 // side_count - [in] (>=3) number of sides 00034 // Returns: 00035 // true if successful. false if circle is invalid or 00036 // side_count < 3. 00037 bool CreateInscribedPolygon( 00038 const ON_Circle& circle, 00039 int side_count 00040 ); 00041 00042 // Description: 00043 // Create a regular polygon circumscribe about a circle. 00044 // The midpoints of the polygon's edges will be tanget to the 00045 // circle. 00046 // Parameters: 00047 // circle - [in] 00048 // side_count - [in] (>=3) number of sides 00049 // Returns: 00050 // true if successful. false if circle is invalid or 00051 // side_count < 3. 00052 bool CreateCircumscribedPolygon( 00053 const ON_Circle& circle, 00054 int side_count 00055 ); 00056 00057 // Description: 00058 // Create a regular star polygon. 00059 // The star begins at circle.PointAt(0) and the vertices alternate 00060 // between being on circle and begin on a concentric circle of 00061 // other_radius. 00062 // Parameters: 00063 // circle - [in] circle star polygon starts on 00064 // other_radius - [in] radius of other circle 00065 // corner_count - [in] (>=3) number of corners on circle 00066 // There will be 2*corner_count sides and 2*corner_count 00067 // vertices. 00068 // Returns: 00069 // true if successful. false if circle is invalid, other_radius < 0.0, 00070 // or side_count < 3. 00071 bool CreateStarPolygon( 00072 const ON_Circle& circle, 00073 double other_radius, 00074 int side_count 00075 ); 00076 00077 // Description: 00078 // Checks that polyline has at least two points 00079 // and that sequential points are distinct. If the 00080 // polyline has 2 or 3 points, then the start and end 00081 // point must be distinct. 00082 // Parameters: 00083 // tolerance - [in] tolerance used to check for duplicate points. 00084 // Returns: 00085 // true if polyline is valid. 00086 // See Also: 00087 // ON_Polyline::Clean. 00088 bool IsValid( 00089 double tolerance = 0.0 00090 ) const; 00091 00092 // Description: 00093 // Removes duplicate points that result in zero length segments. 00094 // Parameters: 00095 // tolerance - [in] tolerance used to check for duplicate points. 00096 // Returns: 00097 // Number of points removed. 00098 // Remarks: 00099 // If the distance between points polyline[i] and polyline[i+1] 00100 // is <= tolerance, then the point with index (i+1) is removed. 00101 int Clean( 00102 double tolerance = 0.0 00103 ); 00104 00105 // Returns: 00106 // Number of points in the polyline. 00107 int PointCount() const; 00108 00109 // Returns: 00110 // Number of segments in the polyline. 00111 int SegmentCount() const; 00112 00113 // Description: 00114 // Test a polyline to see if it is closed. 00115 // Returns: 00116 // true if polyline has 4 or more points, the distance between the 00117 // start and end points is <= tolerance, and there is a 00118 // point in the polyline whose distance from the start and end 00119 // points is > tolerance. 00120 bool IsClosed( 00121 double tolerance = 0.0 00122 ) const; 00123 00124 00125 // Returns: 00126 // Length of the polyline. 00127 double Length() const; 00128 00129 // Parameters: 00130 // segment_index - [in] zero based segment index 00131 // Returns: 00132 // vector = point[segment_index+1] - point[segment_index]. 00133 ON_3dVector SegmentDirection ( 00134 int segment_index 00135 ) const; 00136 00137 // Parameters: 00138 // segment_index - [in] zero based segment index 00139 // Returns: 00140 // Unit vector in the direction of the segment 00141 ON_3dVector SegmentTangent ( 00142 int segment_index 00143 ) const; 00144 00145 // Description: 00146 // Evaluate the polyline location at a parameter. 00147 // Parameters: 00148 // t - [in] the i-th segment goes from i <= t < i+1 00149 ON_3dPoint PointAt( double t ) const; 00150 00151 // Description: 00152 // Evaluate the polyline first derivative at a parameter. 00153 // Parameters: 00154 // t - [in] the i-th segment goes from i <= t < i+1 00155 ON_3dVector DerivativeAt( double t ) const; 00156 00157 // Description: 00158 // Evaluate the polyline unit tangent at a parameter. 00159 // Parameters: 00160 // t - [in] the i-th segment goes from i <= t < i+1 00161 ON_3dVector TangentAt( double t ) const; 00162 00163 // Description: 00164 // Find a point on the polyline that is closest 00165 // to test_point. 00166 // Parameters: 00167 // test_point - [in] 00168 // t - [out] parameter for a point on the polyline that 00169 // is closest to test_point. If mulitple solutions 00170 // exist, then the smallest solution is returned. 00171 // Returns: 00172 // true if successful. 00173 bool ClosestPointTo( 00174 const ON_3dPoint& test_point, 00175 double* t 00176 ) const; 00177 00178 // Description: 00179 // Find a point on the polyline that is closest 00180 // to test_point. 00181 // Parameters: 00182 // test_point - [in] 00183 // t - [out] parameter for a point on the polyline that 00184 // is closest to test_point. If mulitple solutions 00185 // exist, then the smallest solution is returned. 00186 // segment_index0 - [in] index of segment where search begins 00187 // segment_index1 - [in] index of segment where search ends 00188 // This segment is NOT searched. 00189 // Example: 00190 // Search segments 3,4, and 5 for the point closest to (0,0,0). 00191 // double t; 00192 // ClosestPointTo( ON_3dPoint(0,0,0), &t, 3, 6 ); 00193 // Returns: 00194 // true if successful. 00195 bool ClosestPointTo( 00196 const ON_3dPoint& test_point, 00197 double* t, 00198 int segment_index0, // index of segment where search begins 00199 int segment_index1 // index + 1 of segment where search stops 00200 ) const; 00201 00202 // Description: 00203 // Find a point on the polyline that is closest 00204 // to test_point. 00205 // Parameters: 00206 // test_point - [in] 00207 // Returns: 00208 // point on polyline. 00209 ON_3dPoint ClosestPointTo( 00210 const ON_3dPoint& test_point 00211 ) const; 00212 00213 }; 00214 00215 #endif