/
opennurbs_polyline.h
215 lines (193 loc) · 6.33 KB
/
opennurbs_polyline.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(ON_POLYLINE_INC_)
#define ON_POLYLINE_INC_
class ON_CLASS ON_Polyline : public ON_3dPointArray
{
public:
ON_Polyline();
ON_Polyline(const ON_3dPointArray&);
ON_Polyline& operator=(const ON_3dPointArray&);
~ON_Polyline();
// Description:
// Create a regular polygon inscribed in a circle.
// The vertices of the polygon will be on the circle.
// Parameters:
// circle - [in]
// side_count - [in] (>=3) number of sides
// Returns:
// true if successful. false if circle is invalid or
// side_count < 3.
bool CreateInscribedPolygon(
const ON_Circle& circle,
int side_count
);
// Description:
// Create a regular polygon circumscribe about a circle.
// The midpoints of the polygon's edges will be tanget to the
// circle.
// Parameters:
// circle - [in]
// side_count - [in] (>=3) number of sides
// Returns:
// true if successful. false if circle is invalid or
// side_count < 3.
bool CreateCircumscribedPolygon(
const ON_Circle& circle,
int side_count
);
// Description:
// Create a regular star polygon.
// The star begins at circle.PointAt(0) and the vertices alternate
// between being on circle and begin on a concentric circle of
// other_radius.
// Parameters:
// circle - [in] circle star polygon starts on
// other_radius - [in] radius of other circle
// corner_count - [in] (>=3) number of corners on circle
// There will be 2*corner_count sides and 2*corner_count
// vertices.
// Returns:
// true if successful. false if circle is invalid, other_radius < 0.0,
// or side_count < 3.
bool CreateStarPolygon(
const ON_Circle& circle,
double other_radius,
int side_count
);
// Description:
// Checks that polyline has at least two points
// and that sequential points are distinct. If the
// polyline has 2 or 3 points, then the start and end
// point must be distinct.
// Parameters:
// tolerance - [in] tolerance used to check for duplicate points.
// Returns:
// true if polyline is valid.
// See Also:
// ON_Polyline::Clean.
bool IsValid(
double tolerance = 0.0
) const;
// Description:
// Removes duplicate points that result in zero length segments.
// Parameters:
// tolerance - [in] tolerance used to check for duplicate points.
// Returns:
// Number of points removed.
// Remarks:
// If the distance between points polyline[i] and polyline[i+1]
// is <= tolerance, then the point with index (i+1) is removed.
int Clean(
double tolerance = 0.0
);
// Returns:
// Number of points in the polyline.
int PointCount() const;
// Returns:
// Number of segments in the polyline.
int SegmentCount() const;
// Description:
// Test a polyline to see if it is closed.
// Returns:
// true if polyline has 4 or more points, the distance between the
// start and end points is <= tolerance, and there is a
// point in the polyline whose distance from the start and end
// points is > tolerance.
bool IsClosed(
double tolerance = 0.0
) const;
// Returns:
// Length of the polyline.
double Length() const;
// Parameters:
// segment_index - [in] zero based segment index
// Returns:
// vector = point[segment_index+1] - point[segment_index].
ON_3dVector SegmentDirection (
int segment_index
) const;
// Parameters:
// segment_index - [in] zero based segment index
// Returns:
// Unit vector in the direction of the segment
ON_3dVector SegmentTangent (
int segment_index
) const;
// Description:
// Evaluate the polyline location at a parameter.
// Parameters:
// t - [in] the i-th segment goes from i <= t < i+1
ON_3dPoint PointAt( double t ) const;
// Description:
// Evaluate the polyline first derivative at a parameter.
// Parameters:
// t - [in] the i-th segment goes from i <= t < i+1
ON_3dVector DerivativeAt( double t ) const;
// Description:
// Evaluate the polyline unit tangent at a parameter.
// Parameters:
// t - [in] the i-th segment goes from i <= t < i+1
ON_3dVector TangentAt( double t ) const;
// Description:
// Find a point on the polyline that is closest
// to test_point.
// Parameters:
// test_point - [in]
// t - [out] parameter for a point on the polyline that
// is closest to test_point. If mulitple solutions
// exist, then the smallest solution is returned.
// Returns:
// true if successful.
bool ClosestPointTo(
const ON_3dPoint& test_point,
double* t
) const;
// Description:
// Find a point on the polyline that is closest
// to test_point.
// Parameters:
// test_point - [in]
// t - [out] parameter for a point on the polyline that
// is closest to test_point. If mulitple solutions
// exist, then the smallest solution is returned.
// segment_index0 - [in] index of segment where search begins
// segment_index1 - [in] index of segment where search ends
// This segment is NOT searched.
// Example:
// Search segments 3,4, and 5 for the point closest to (0,0,0).
// double t;
// ClosestPointTo( ON_3dPoint(0,0,0), &t, 3, 6 );
// Returns:
// true if successful.
bool ClosestPointTo(
const ON_3dPoint& test_point,
double* t,
int segment_index0, // index of segment where search begins
int segment_index1 // index + 1 of segment where search stops
) const;
// Description:
// Find a point on the polyline that is closest
// to test_point.
// Parameters:
// test_point - [in]
// Returns:
// point on polyline.
ON_3dPoint ClosestPointTo(
const ON_3dPoint& test_point
) const;
};
#endif