Point Cloud Library (PCL) 1.15.0
Loading...
Searching...
No Matches
opennurbs_intersect.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_INTERSECT_INC_)
18#define ON_INTERSECT_INC_
19
20// These simple intersectors are fast and detect transverse intersections.
21// If the intersection is not a simple transverse case, then they
22// return false and you will have to use one of the slower but fancier
23// models.
24
25
26/*
27Description:
28 Intersect two lines.
29Parameters:
30 lineA - [in]
31 lineB - [in]
32 double* a - [out]
33 double* b - [out] The shortest distance between the lines is the
34 chord from lineA.PointAt(*a) to lineB.PointAt(*b).
35 tolerance - [in] If > 0.0, then an intersection is reported only
36 if the distance between the points is <= tolerance.
37 If <= 0.0, then the closest point between the lines
38 is reported.
39 bIntersectSegments - [in] if true, the input lines are treated
40 as finite segments. If false, the
41 input lines are treated as infinite lines.
42Returns:
43 True if a closest point can be calculated and the result passes
44 the tolerance parameter test.
45See Also:
46 ON_Intersect( const ON_Line& lineA, const ON_Line& line B)
47Remarks:
48 If the lines are exactly parallel, meaning the system of equations
49 used to find a and b has no numerical solution, then false is returned.
50 If the lines are nearly parallel, which is often numerically true
51 even if you think the lines look exactly parallel, then the
52 closest points are found and true is returned. So, if you
53 care about weeding out "parallel" lines, then you need to
54 do something like the following.
55
56 bool rc = ON_IntersectLineLine(lineA,lineB,
57 &a,&b,
58 tolerance,
59 bIntersectSegments);
60 if (rc)
61 {
62 double angle_tolerance_radians = 0.5*ON_PI/180.0; // or whatever
63 double parallel_tol = cos(angle_tolerance_radians);
64 if ( fabs(lineA.Tangent()*lineB.Tangent()) >= parallel_tol )
65 {
66 ... do whatever you think is appropriate
67 }
68 }
69*/
70ON_DECL
71bool ON_IntersectLineLine(
72 const ON_Line& lineA,
73 const ON_Line& lineB,
74 double* a,
75 double* b,
76 double tolerance,
77 bool bIntersectSegments
78 );
79
80/*
81Description:
82 Find the closest point between two infinte lines.
83Parameters:
84 lineA - [in]
85 lineB - [in]
86 double* a - [out]
87 double* b - [out] The shortest distance between the lines is the
88 chord from lineA.PointAt(*a) to lineB.PointAt(*b).
89Returns:
90 True if points are found and false if the lines are numerically parallel.
91 Numerically parallel means the 2x2 matrix
92
93 AoA -AoB
94 -AoB BoB
95
96 is numerically singluar, where A = lineA.to-lineA.from
97 and B = lineB.to-lineB.from.
98See Also:
99 ON_IntersectLineLine
100*/
101ON_DECL
102bool ON_Intersect(
103 const ON_Line& lineA,
104 const ON_Line& lineB,
105 double* a,
106 double* b
107 );
108
109ON_DECL
110bool ON_Intersect( // Returns false unless intersection is a single point
111 // If returned parameter is < 0 or > 1, then the line
112 // segment between line.m_point[0] and line.m_point[1]
113 // does not intersect the plane
114 const ON_Line&,
115 const ON_Plane&,
116 double* // parameter on line
117 );
118
119ON_DECL
120bool ON_Intersect( const ON_Plane&,
121 const ON_Plane&,
122 ON_Line& // intersection line is returned here
123 );
124
125ON_DECL
126bool ON_Intersect( const ON_Plane&,
127 const ON_Plane&,
128 const ON_Plane&,
129 ON_3dPoint& // intersection point is returned here
130 );
131
132/*
133Description:
134 Intersect a plane and a sphere.
135Parameters:
136 plane - [in]
137 sphere - [in]
138 circle - [out]
139Returns:
140 0: no intersection
141 circle radius = 0 and circle origin = point on the plane
142 closest to the sphere.
143 1: intersection is a single point
144 circle radius = 0;
145 2: intersection is a circle
146 circle radius > 0.
147*/
148ON_DECL
149int ON_Intersect(
150 const ON_Plane& plane,
151 const ON_Sphere& sphere,
152 ON_Circle& circle
153 );
154
155ON_DECL
156int ON_Intersect( // returns 0 = no intersections,
157 // 1 = one intersection,
158 // 2 = 2 intersections
159 // If 0 is returned, first point is point
160 // on line closest to sphere and 2nd point is the point
161 // on the sphere closest to the line.
162 // If 1 is returned, first point is obtained by evaluating
163 // the line and the second point is obtained by evaluating
164 // the sphere.
165 const ON_Line&, const ON_Sphere&,
166 ON_3dPoint&, ON_3dPoint& // intersection point(s) returned here
167 );
168
169ON_DECL
170int ON_Intersect( // returns 0 = no intersections,
171 // 1 = one intersection,
172 // 2 = 2 intersections
173 // 3 = line lies on cylinder
174 // If 0 is returned, first point is point
175 // on line closest to cylinder and 2nd point is the point
176 // on the sphere closest to the line.
177 // If 1 is returned, first point is obtained by evaluating
178 // the line and the second point is obtained by evaluating
179 // the sphere.
180 const ON_Line&, const ON_Cylinder&,
181 ON_3dPoint&, ON_3dPoint& // intersection point(s) returned here
182 );
183
184/*
185Description:
186 Intersect an infinite line and an axis aligned bounding box.
187Parameters:
188 bbox - [in]
189 line - [in]
190 tolerance - [in] If tolerance > 0.0, then the intersection is
191 performed against a box that has each side
192 moved out by tolerance.
193 line_parameters - [out]
194 Pass null if you do not need the parameters.
195 If true is returned and line.from != line.to,
196 then the chord from line.PointAt(line_parameters[0])
197 to line.PointAt(line_parameters[1]) is the intersection.
198 If true is returned and line.from = line.to, then line.from
199 is in the box and the interval (0.0,0.0) is returned.
200 If false is returned, the input value of line_parameters
201 is not changed.
202Returns:
203 True if the line intersects the box and false otherwise.
204*/
205ON_DECL
206bool ON_Intersect( const ON_BoundingBox& bbox,
207 const ON_Line& line,
208 double tolerance,
209 ON_Interval* line_parameters
210 );
211
212/*
213Description:
214 Intersect two spheres using exact calculations.
215Parameters:
216 sphere0 - [in]
217 sphere1 - [in]
218 circle - [out] If intersection is a point, then that point will be the center, radius 0.
219Returns:
220 0 if no intersection,
221 1 if a single point,
222 2 if a circle,
223 3 if the spheres are the same.
224*/
225ON_DECL
226int ON_Intersect( const ON_Sphere& sphere0,
227 const ON_Sphere& sphere1,
228 ON_Circle& circle
229 );
230#endif