Imported Upstream version 2.81
[platform/upstream/libbullet.git] / Extras / ConvexDecomposition / bestfit.h
1 #ifndef BEST_FIT_H
2
3 #define BEST_FIT_H
4
5 /*----------------------------------------------------------------------
6                 Copyright (c) 2004 Open Dynamics Framework Group
7                                         www.physicstools.org
8                 All rights reserved.
9
10                 Redistribution and use in source and binary forms, with or without modification, are permitted provided
11                 that the following conditions are met:
12
13                 Redistributions of source code must retain the above copyright notice, this list of conditions
14                 and the following disclaimer.
15
16                 Redistributions in binary form must reproduce the above copyright notice,
17                 this list of conditions and the following disclaimer in the documentation
18                 and/or other materials provided with the distribution.
19
20                 Neither the name of the Open Dynamics Framework Group nor the names of its contributors may
21                 be used to endorse or promote products derived from this software without specific prior written permission.
22
23                 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24                 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25                 DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26                 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27                 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
28                 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29                 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 -----------------------------------------------------------------------*/
31
32 // http://codesuppository.blogspot.com
33 //
34 // mailto: jratcliff@infiniplex.net
35 //
36 // http://www.amillionpixels.us
37 //
38
39
40 // This routine was released in 'snippet' form
41 // by John W. Ratcliff mailto:jratcliff@infiniplex.net
42 // on March 22, 2006.
43 //
44 // This routine computes the 'best fit' plane equation to
45 // a set of input data points with an optional per vertex
46 // weighting component.
47 //
48 // The implementation for this was lifted directly from
49 // David Eberly's Magic Software implementation.
50
51 // computes the best fit plane to a collection of data points.
52 // returns the plane equation as A,B,C,D format. (Ax+By+Cz+D)
53
54 bool getBestFitPlane(unsigned int vcount,     // number of input data points
55                      const float *points,     // starting address of points array.
56                      unsigned int vstride,    // stride between input points.
57                      const float *weights,    // *optional point weighting values.
58                      unsigned int wstride,    // weight stride for each vertex.
59                      float *plane);
60
61
62 float getBoundingRegion(unsigned int vcount,const float *points,unsigned int pstride,float *bmin,float *bmax); // returns the diagonal distance
63 bool  overlapAABB(const float *bmin1,const float *bmax1,const float *bmin2,const float *bmax2); // return true if the two AABB's overlap.
64
65 #endif