BRL-CAD
tol.h
Go to the documentation of this file.
1 /* T O L . H
2  * BRL-CAD
3  *
4  * Copyright (c) 1993-2024 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 
21 #ifndef RT_TOL_H
22 #define RT_TOL_H
23 
24 #include "common.h"
25 #include "vmath.h"
26 #include "bn/tol.h"
27 #include "rt/defines.h"
28 
29 __BEGIN_DECLS
30 
31 /** @addtogroup rt_tol
32  *
33  * @brief
34  * librt specific tolerance information.
35  *
36  * These routines provide access to the default tolerance values
37  * available within LIBRT. These routines assume working units of
38  * 'mm' and are idealized to only attempt to account for
39  * cross-platform hardware and floating point instability. That is to
40  * say that the default tolerance values are tight.
41 
42  */
43 /** @{ */
44 /** @file rt/tol.h */
45 
46 /*
47  * Unfortunately, to prevent divide-by-zero, some tolerancing needs to
48  * be introduced.
49  *
50  *
51  * RT_LEN_TOL is the shortest length, in mm, that can be stood as the
52  * dimensions of a primitive. Can probably become at least
53  * SQRT_SMALL_FASTF.
54  *
55  * Dot products smaller than RT_DOT_TOL are considered to have a dot
56  * product of zero, i.e., the angle is effectively zero. This is used
57  * to check vectors that should be perpendicular.
58  *
59  * asin(0.1) = 5.73917 degrees
60  * asin(0.01) = 0.572967 degrees
61  * asin(0.001) = 0.0572958 degrees
62  * asin(0.0001) = 0.00572958 degrees
63  *
64  * sin(0.01 degrees) = sin(0.000174 radians) = 0.000174533
65  *
66  * Many TGCs at least, in existing databases, will fail the
67  * perpendicularity test if DOT_TOL is much smaller than 0.001, which
68  * establishes a 1/20th degree tolerance. The intent is to eliminate
69  * grossly bad primitives, not pick nits.
70  *
71  * RT_PCOEF_TOL is a tolerance on polynomial coefficients to prevent
72  * the root finder from having heartburn.
73  *
74  * RT_ROOT_TOL is the tolerance on the imaginary component of complex
75  * roots, for determining whether a root is sufficiently near zero.
76  */
77 #define RT_LEN_TOL (1.0e-8)
78 #define RT_DOT_TOL (0.001)
79 #define RT_PCOEF_TOL (1.0e-10)
80 #define RT_ROOT_TOL (1.0e-5)
81 
82 /**
83  * Fills in the provided bn_tol structure with compile-time default
84  * tolerance values. These presently correspond to a distance
85  * tolerance of 5e-5 (assuming default working units is 1/2000th a mm)
86  * and a perpendicularity tolerance of 1e-6. If tol is NULL, a
87  * structure is allocated, initialized, and returned.
88  */
89 RT_EXPORT extern struct bn_tol *rt_tol_default(struct bn_tol *tol);
90 
91 /** @} */
92 
93 __END_DECLS
94 
95 #endif /* RT_TOL_H */
96 
97 /*
98  * Local Variables:
99  * tab-width: 8
100  * mode: C
101  * indent-tabs-mode: t
102  * c-file-style: "stroustrup"
103  * End:
104  * ex: shiftwidth=4 tabstop=8
105  */
Header file for the BRL-CAD common definitions.
struct bn_tol * rt_tol_default(struct bn_tol *tol)
Definition: tol.h:72
fundamental vector, matrix, quaternion math macros