BRL-CAD
obr.h
Go to the documentation of this file.
1/* O B R . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2004-2023 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/*----------------------------------------------------------------------*/
22/* @file obr.h */
23/** @addtogroup bg_obr */
24/** @{ */
25
26/**
27 * @brief Routines for the computation of oriented bounding rectangles 2D and 3D
28 */
29
30#ifndef BG_OBR_H
31#define BG_OBR_H
32
33#include "common.h"
34#include "vmath.h"
35#include "bg/defines.h"
36
37__BEGIN_DECLS
38
39/**
40 *@brief
41 * Uses the Rotating Calipers algorithm to find the
42 * minimum oriented bounding rectangle for a set of 2D
43 * points. Returns 0 on success.
44 *
45 * The box will be described by a center point and 2
46 * vectors:
47 *
48 * \verbatim
49 * ----------------------------
50 * | ^ |
51 * | | |
52 * | v | |
53 * | | |
54 * | *------------>|
55 * | center u |
56 * | |
57 * | |
58 * ----------------------------
59 * \endverbatim
60 *
61 * Note that the box is oriented, and thus not necessarily axis
62 * aligned (u and v are perpendicular, but not necessarily parallel
63 * with the coordinate space V=0 and U=0 axis vectors.)
64 *
65 * @param[out] center center of oriented bounding rectangle
66 * @param[out] u vector in the direction of obr x with
67 * vector length of 0.5 * obr length
68 * @param[out] v vector in the obr y direction with vector
69 * length of 0.5 * obr width
70 * @param points_2d array of 2D points
71 * @param pnt_cnt number of points in pnts array
72 */
73BG_EXPORT extern int bg_2d_obr(point2d_t *center,
74 vect2d_t *u,
75 vect2d_t *v,
76 const point2d_t *points_2d,
77 int pnt_cnt);
78
79/**
80 *@brief
81 * Uses the Rotating Calipers algorithm to find the
82 * minimum oriented bounding rectangle for a set of coplanar 3D
83 * points. Returns 0 on success.
84 *
85 * @param[out] center center of oriented bounding rectangle
86 * @param[out] v1 vector in the direction of obr x with
87 * vector length of 0.5 * obr length
88 * @param[out] v2 vector in the obr y direction with vector
89 * length of 0.5 * obr width
90 * @param points_3d array of coplanar 3D points
91 * @param pnt_cnt number of points in pnts array
92 */
93BG_EXPORT extern int bg_3d_coplanar_obr(point_t *center,
94 vect_t *v1,
95 vect_t *v2,
96 const point_t *points_3d,
97 int pnt_cnt);
98
99/**
100 *@brief
101 * Find the minimum oriented bounding rectangular cuboid
102 * for a set of 3D points. Returns 0 on success.
103 *
104 * TODO - the GeometricTools engine has an implementation
105 * of the stack needed to do this:
106 *
107 * https://github.com/davideberly/GeometricTools/blob/master/GTE/Mathematics/MinimumVolumeBox3.h
108 *
109 * The points in the output array are arranged as seen
110 * in the figure below, with the integer number at each
111 * vertex position corresponding to the pnts array index
112 * n-1 (for example, the first point, labeled 1 below,
113 * would be pnts[0].)
114 *
115 * \verbatim
116 * 8
117 * * | *
118 * * | *
119 * 4 | 7
120 * | * | * |
121 * | * * |
122 * | | 3 |
123 * | | | |
124 * | 5 | |
125 * | * |* |
126 * | * | * |
127 * 1 | 6
128 * * | *
129 * * | *
130 * 2
131 * \endverbatim
132 *
133 *
134 * @param[out] pnts eight points of oriented bounding box
135 * @param points_3d array of coplanar 3D points
136 * @param pnt_cnt number of points in pnts array
137 */
138BG_EXPORT extern int bg_3d_obb(point_t **pnts,
139 const point_t *points_3d,
140 int pnt_cnt);
141
142
143__END_DECLS
144
145#endif /* BG_OBR_H */
146/** @} */
147/*
148 * Local Variables:
149 * mode: C
150 * tab-width: 8
151 * indent-tabs-mode: t
152 * c-file-style: "stroustrup"
153 * End:
154 * ex: shiftwidth=4 tabstop=8
155 */
Header file for the BRL-CAD common definitions.
int bg_3d_obb(point_t **pnts, const point_t *points_3d, int pnt_cnt)
Find the minimum oriented bounding rectangular cuboid for a set of 3D points. Returns 0 on success.
int bg_2d_obr(point2d_t *center, vect2d_t *u, vect2d_t *v, const point2d_t *points_2d, int pnt_cnt)
Routines for the computation of oriented bounding rectangles 2D and 3D.
int bg_3d_coplanar_obr(point_t *center, vect_t *v1, vect_t *v2, const point_t *points_3d, int pnt_cnt)
Uses the Rotating Calipers algorithm to find the minimum oriented bounding rectangle for a set of cop...
fastf_t vect_t[ELEMENTS_PER_VECT]
3-tuple vector
Definition: vmath.h:345
fastf_t point2d_t[ELEMENTS_PER_POINT2D]
2-tuple point
Definition: vmath.h:339
fastf_t point_t[ELEMENTS_PER_POINT]
3-tuple point
Definition: vmath.h:351
fastf_t vect2d_t[ELEMENTS_PER_VECT2D]
2-tuple vector
Definition: vmath.h:333
fundamental vector, matrix, quaternion math macros