opennurbs_polyline.h
1 /* $NoKeywords: $ */
2 /*
3 //
4 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
5 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
6 // McNeel & Associates.
7 //
8 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
9 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
10 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
11 //
12 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
13 //
14 ////////////////////////////////////////////////////////////////
15 */
16 
17 #if !defined(ON_POLYLINE_INC_)
18 #define ON_POLYLINE_INC_
19 
20 class ON_CLASS ON_Polyline : public ON_3dPointArray
21 {
22 public:
23  ON_Polyline();
24  ~ON_Polyline();
27 
28 
29  // Description:
30  // Create a regular polygon inscribed in a circle.
31  // The vertices of the polygon will be on the circle.
32  // Parameters:
33  // circle - [in]
34  // side_count - [in] (>=3) number of sides
35  // Returns:
36  // true if successful. false if circle is invalid or
37  // side_count < 3.
38  bool CreateInscribedPolygon(
39  const ON_Circle& circle,
40  int side_count
41  );
42 
43  // Description:
44  // Create a regular polygon circumscribe about a circle.
45  // The midpoints of the polygon's edges will be tanget to the
46  // circle.
47  // Parameters:
48  // circle - [in]
49  // side_count - [in] (>=3) number of sides
50  // Returns:
51  // true if successful. false if circle is invalid or
52  // side_count < 3.
53  bool CreateCircumscribedPolygon(
54  const ON_Circle& circle,
55  int side_count
56  );
57 
58  // Description:
59  // Create a regular star polygon.
60  // The star begins at circle.PointAt(0) and the vertices alternate
61  // between being on circle and begin on a concentric circle of
62  // other_radius.
63  // Parameters:
64  // circle - [in] circle star polygon starts on
65  // other_radius - [in] radius of other circle
66  // corner_count - [in] (>=3) number of corners on circle
67  // There will be 2*corner_count sides and 2*corner_count
68  // vertices.
69  // Returns:
70  // true if successful. false if circle is invalid, other_radius < 0.0,
71  // or side_count < 3.
72  bool CreateStarPolygon(
73  const ON_Circle& circle,
74  double other_radius,
75  int side_count
76  );
77 
78  // Description:
79  // Checks that polyline has at least two points
80  // and that sequential points are distinct. If the
81  // polyline has 2 or 3 points, then the start and end
82  // point must be distinct.
83  // Parameters:
84  // tolerance - [in] tolerance used to check for duplicate points.
85  // Returns:
86  // true if polyline is valid.
87  // See Also:
88  // ON_Polyline::Clean.
89  bool IsValid(
90  double tolerance = 0.0
91  ) const;
92 
93  // Description:
94  // Removes duplicate points that result in zero length segments.
95  // Parameters:
96  // tolerance - [in] tolerance used to check for duplicate points.
97  // Returns:
98  // Number of points removed.
99  // Remarks:
100  // If the distance between points polyline[i] and polyline[i+1]
101  // is <= tolerance, then the point with index (i+1) is removed.
102  int Clean(
103  double tolerance = 0.0
104  );
105 
106  // Returns:
107  // Number of points in the polyline.
108  int PointCount() const;
109 
110  // Returns:
111  // Number of segments in the polyline.
112  int SegmentCount() const;
113 
114  // Description:
115  // Test a polyline to see if it is closed.
116  // Returns:
117  // true if polyline has 4 or more points, the distance between the
118  // start and end points is <= tolerance, and there is a
119  // point in the polyline whose distance from the start and end
120  // points is > tolerance.
121  bool IsClosed(
122  double tolerance = 0.0
123  ) const;
124 
125 
126  // Returns:
127  // Length of the polyline.
128  double Length() const;
129 
130  // Parameters:
131  // segment_index - [in] zero based segment index
132  // Returns:
133  // vector = point[segment_index+1] - point[segment_index].
134  ON_3dVector SegmentDirection (
135  int segment_index
136  ) const;
137 
138  // Parameters:
139  // segment_index - [in] zero based segment index
140  // Returns:
141  // Unit vector in the direction of the segment
142  ON_3dVector SegmentTangent (
143  int segment_index
144  ) const;
145 
146  // Description:
147  // Evaluate the polyline location at a parameter.
148  // Parameters:
149  // t - [in] the i-th segment goes from i <= t < i+1
150  ON_3dPoint PointAt( double t ) const;
151 
152  // Description:
153  // Evaluate the polyline first derivative at a parameter.
154  // Parameters:
155  // t - [in] the i-th segment goes from i <= t < i+1
156  ON_3dVector DerivativeAt( double t ) const;
157 
158  // Description:
159  // Evaluate the polyline unit tangent at a parameter.
160  // Parameters:
161  // t - [in] the i-th segment goes from i <= t < i+1
162  ON_3dVector TangentAt( double t ) const;
163 
164  // Description:
165  // Find a point on the polyline that is closest
166  // to test_point.
167  // Parameters:
168  // test_point - [in]
169  // t - [out] parameter for a point on the polyline that
170  // is closest to test_point. If mulitple solutions
171  // exist, then the smallest solution is returned.
172  // Returns:
173  // true if successful.
174  bool ClosestPointTo(
175  const ON_3dPoint& test_point,
176  double* t
177  ) const;
178 
179  // Description:
180  // Find a point on the polyline that is closest
181  // to test_point.
182  // Parameters:
183  // test_point - [in]
184  // t - [out] parameter for a point on the polyline that
185  // is closest to test_point. If mulitple solutions
186  // exist, then the smallest solution is returned.
187  // segment_index0 - [in] index of segment where search begins
188  // segment_index1 - [in] index of segment where search ends
189  // This segment is NOT searched.
190  // Example:
191  // Search segments 3,4, and 5 for the point closest to (0,0,0).
192  // double t;
193  // ClosestPointTo( ON_3dPoint(0,0,0), &t, 3, 6 );
194  // Returns:
195  // true if successful.
196  bool ClosestPointTo(
197  const ON_3dPoint& test_point,
198  double* t,
199  int segment_index0, // index of segment where search begins
200  int segment_index1 // index + 1 of segment where search stops
201  ) const;
202 
203  // Description:
204  // Find a point on the polyline that is closest
205  // to test_point.
206  // Parameters:
207  // test_point - [in]
208  // Returns:
209  // point on polyline.
210  ON_3dPoint ClosestPointTo(
211  const ON_3dPoint& test_point
212  ) const;
213 
214 };
215 
216 /*
217 Description:
218  Join all contiguous polylines of an array of ON_Polylines.
219 Parameters:
220  InPlines - [in] Array of polylines to be joined (not modified)
221  OutPlines - [out] Resulting joined polylines and copies of polylines that were not joined to anything
222  are appended.
223  join_tol - [in] Distance tolerance used to decide if endpoints are close enough
224  kink_tol - [in] Angle in radians. If > 0.0, then curves within join_tol will only be joined if the angle between them
225  is less than kink_tol. If <= 0, then the angle will be ignored and only join_tol will be used.
226  bUseTanAngle - [in] If true, choose the best match using angle between tangents.
227  If false, best match is the closest. This is used whether or not kink_tol is positive.
228  bPreserveDirection - [in] If true, polylines endpoints will be compared to polylines startpoints.
229  If false, all start and endpoints will be compared, and copies of input
230  curves may be reversed in output.
231  key - [out] if key is not null, InPlines[i] was joined into OutPlines[key[i]].
232 Returns:
233  Number of polylines added to OutPlines
234 Remarks:
235  Closed polylines are copied to OutPlines.
236  Plines that cannot be joined to others are copied to OutPlines.
237  */
238 ON_DECL
239 int ON_JoinPolylines(const ON_SimpleArray<const ON_Polyline*>& InPlines,
240  ON_SimpleArray<ON_Polyline*>& OutPlines,
241  double join_tol,
242  double kink_tol,
243  bool bUseTanAngle,
244  bool bPreserveDirection = false,
245  ON_SimpleArray<int>* key = 0
246  );
247 
248 
249 #endif
Definition: opennurbs_polyline.h:20
ON_3dPointArray & operator=(const ON_3dPointArray &)
Definition: opennurbs_array.h:36
ON_Circle is a circle in 3d. The cirle is represented by a radius and an orthonormal frame of the pla...
Definition: opennurbs_circle.h:32
Definition: opennurbs_point.h:2018
Definition: opennurbs_point.h:460
Definition: opennurbs_point.h:1152