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 /*
27 Description:
28  Intersect two lines.
29 Parameters:
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.
42 Returns:
43  True if a closest point can be calculated and the result passes
44  the tolerance parameter test.
45 See Also:
46  ON_Intersect( const ON_Line& lineA, const ON_Line& line B)
47 Remarks:
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 */
70 ON_DECL
71 bool 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 /*
81 Description:
82  Find the closest point between two infinte lines.
83 Parameters:
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).
89 Returns:
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.
98 See Also:
99  ON_IntersectLineLine
100 */
101 
102 /* 15 Sept 2016 - Already in opennurbs_math.h
103 ON_DECL
104 bool ON_Intersect(
105  const ON_Line& lineA,
106  const ON_Line& lineB,
107  double* a,
108  double* b
109  );
110  */
111 
112 /* 15 Sept 2016 - Already in opennurbs_math.h
113 
114 ON_DECL
115 bool ON_Intersect( // Returns false unless intersection is a single point
116  // If returned parameter is < 0 or > 1, then the line
117  // segment between line.m_point[0] and line.m_point[1]
118  // does not intersect the plane
119  const ON_Line&,
120  const ON_Plane&,
121  double* // parameter on line
122  );
123  */
124 
125 /*
126 Parameters:
127  line - [in]
128  plane_equation - [in]
129  line_parameter - [out]
130  If the returned parameter is < 0 or > 1, then the
131  line segment between line.from and line.to
132  does not intersect the plane.
133 Returns:
134  true if the interesection is a singe point.
135  and false otherwise.
136  If returned parameter is < 0 or > 1, then the line
137  segment between line.m_point[0] and line.m_point[1]
138  does not intersect the plane
139 */
140 ON_DECL
141 bool ON_Intersect(
142  const ON_Line& line,
143  const ON_PlaneEquation& plane_equation,
144  double* line_parameter
145  );
146 /* 15 Sept 2016 - Already in opennurbs_math.h
147 
148 ON_DECL
149 bool ON_Intersect( const ON_Plane&,
150  const ON_Plane&,
151  ON_Line& // intersection line is returned here
152  );
153 */
154 
155 /* 15 Sept 2016 - Already in opennurbs_math.h
156 
157 ON_DECL
158 bool ON_Intersect( const ON_Plane&,
159  const ON_Plane&,
160  const ON_Plane&,
161  ON_3dPoint& // intersection point is returned here
162  );
163  */
164 
165 /*
166 Description:
167  Intersect a plane and a sphere.
168 Parameters:
169  plane - [in]
170  sphere - [in]
171  circle - [out]
172 Returns:
173  0: no intersection
174  circle radius = 0 and circle origin = point on the plane
175  closest to the sphere.
176  1: intersection is a single point
177  circle radius = 0;
178  2: intersection is a circle
179  circle radius > 0.
180 */
181 /* 15 Sept 2016 - Already in opennurbs_math.h
182 
183 ON_DECL
184 int ON_Intersect(
185  const ON_Plane& plane,
186  const ON_Sphere& sphere,
187  ON_Circle& circle
188  );
189 */
190 
191 /* 15 Sept 2016 - Already in opennurbs_math.h
192 
193 ON_DECL
194 int ON_Intersect( // returns 0 = no intersections,
195  // 1 = one intersection,
196  // 2 = 2 intersections
197  // If 0 is returned, first point is point
198  // on line closest to sphere and 2nd point is the point
199  // on the sphere closest to the line.
200  // If 1 is returned, first point is obtained by evaluating
201  // the line and the second point is obtained by evaluating
202  // the sphere.
203  const ON_Line&, const ON_Sphere&,
204  ON_3dPoint&, ON_3dPoint& // intersection point(s) returned here
205  );
206 */
207 
208 /* 15 Sept 2016 - Already in opennurbs_math.h
209 
210 ON_DECL
211 int ON_Intersect( // returns 0 = no intersections,
212  // 1 = one intersection,
213  // 2 = 2 intersections
214  // 3 = line lies on cylinder
215  // If 0 is returned, first point is point
216  // on line closest to cylinder and 2nd point is the point
217  // on the sphere closest to the line.
218  // If 1 is returned, first point is obtained by evaluating
219  // the line and the second point is obtained by evaluating
220  // the sphere.
221  const ON_Line&, const ON_Cylinder&,
222  ON_3dPoint&, ON_3dPoint& // intersection point(s) returned here
223  );
224 */
225 /*
226 Description:
227  Intersect an infinite line and an axis aligned bounding box.
228 Parameters:
229  bbox - [in]
230  line - [in]
231  tolerance - [in] If tolerance > 0.0, then the intersection is
232  performed against a box that has each side
233  moved out by tolerance.
234  line_parameters - [out]
235  Pass null if you do not need the parameters.
236  If true is returned and line.from != line.to,
237  then the chord from line.PointAt(line_parameters[0])
238  to line.PointAt(line_parameters[1]) is the intersection.
239  If true is returned and line.from = line.to, then line.from
240  is in the box and the interval (0.0,0.0) is returned.
241  If false is returned, the input value of line_parameters
242  is not changed.
243 Returns:
244  True if the line intersects the box and false otherwise.
245 */
246 ON_DECL
247 bool ON_Intersect( const ON_BoundingBox& bbox,
248  const ON_Line& line,
249  double tolerance,
250  ON_Interval* line_parameters
251  );
252 
253 /*
254 Description:
255  Intersect two spheres using exact calculations.
256 Parameters:
257  sphere0 - [in]
258  sphere1 - [in]
259  circle - [out] If intersection is a point, then that point will be the center, radius 0.
260 Returns:
261  0 if no intersection,
262  1 if a single point,
263  2 if a circle,
264  3 if the spheres are the same.
265 */
266 ON_DECL
267 int ON_Intersect( const ON_Sphere& sphere0,
268  const ON_Sphere& sphere1,
269  ON_Circle& circle
270  );
271 #endif
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_bounding_box.h:25
Definition: opennurbs_line.h:20
Typically the vector portion is a unit vector and m_d = -(x*P.x + y*P.y + z*P.z) for a point P on the...
Definition: opennurbs_point.h:1433
Definition: opennurbs_point.h:46
Definition: opennurbs_sphere.h:22