Comments (6)
Oh, very interesting!
Would you be able to dump the good and bad input vertices into a single .cpp test case file to showcase the error?
from mathgeolib.
First suspect might be to play around with the epsilon value at
MathGeoLib/src/Geometry/Sphere.cpp
Lines 325 to 326 in 55053da
which was needed to improve the numerical stability of the algorithm.
from mathgeolib.
Indeed, 1e-3f
works, even with further more detail. Thanks!
from mathgeolib.
I can try to make a repro case some time later.
from mathgeolib.
Np.. another possibility to try if numerical stability is giving grief can be to duplicate the function into a version that uses double
s.
from mathgeolib.
Repro:
#include <stdio.h>
#include <stdlib.h>
#include "../src/MathGeoLib.h"
#include "../src/Geometry/Sphere.h"
#include "../src/Math/myassert.h"
#include "TestRunner.h"
#include "TestData.h"
MATH_IGNORE_UNUSED_VARS_WARNING
MATH_BEGIN_NAMESPACE
std::vector<math::vec> GenerateTorus(
double major_radius,
double minor_radius,
int major_axis_steps,
int minor_axis_steps
)
{
std::vector<math::vec> points;
constexpr double pi = 3.14159265358979323846264338327950288;
const double R = major_radius;
const double r = minor_radius;
for (int major = 0; major < major_axis_steps; ++major)
{
const double rel_major = static_cast<double>(major) / static_cast<double>(major_axis_steps);
for (int minor = 0; minor < minor_axis_steps; ++minor)
{
const double rel_minor = static_cast<double>(minor) / static_cast<double>(minor_axis_steps);
const double theta = (pi * 2.0 * rel_major);
const double phi = (pi * 2.0 * rel_minor);
const double sin_theta = std::sin(theta);
const double cos_theta = std::cos(theta);
const double sin_phi = std::sin(phi);
const double cos_phi = std::cos(phi);
const double x = (R + r * cos_phi) * cos_theta;
const double z = (R + r * cos_phi) * sin_theta;
const double y = r * sin_phi;
const float fx = static_cast<float>(x);
const float fy = static_cast<float>(y);
const float fz = static_cast<float>(z);
points.push_back(math::vec{fx, fy, fz});
}
}
return points;
}
UNIQUE_TEST(BoundingSphere)
{
const auto points = GenerateTorus(0.5, 0.125, 40, 32);
const math::Sphere sphere = math::Sphere::OptimalEnclosingSphere(
points.data(),
static_cast<int>(points.size())
);
assert(sphere.r < (0.5 + 0.125 + 0.001));
}
MATH_END_NAMESPACE
from mathgeolib.
Related Issues (20)
- Polyhedron::ConvexHull segmentation faults HOT 2
- Plane clipping is too inaccurate (sorry best description)
- MathGeoLibJS live interpreter gives HTTP 404
- Documentation Website is not working(?) HOT 3
- Triangle - AABB Intersection bug? HOT 2
- Polyhedron.cpp // TODO: Do 2D convex hull. HOT 2
- When will the new version be released? HOT 1
- aabb capsule intersection bug HOT 4
- bug:aabb capsule intersection, gjk.cpp wrong assert,wrong calculation result HOT 3
- KdTree not working with a single item/multiple items that cannot be split HOT 2
- Unexpected results with Polyhedron::Triangulate() HOT 2
- Forward-declared float2x2 & float2x3 do not exist HOT 2
- Set3x3PartRotateEulerYZX and ExtractEulerYZX need to modify in Matrix.inl HOT 2
- Missing Feature in Quadtree? HOT 2
- support multiplication of two float3 operands HOT 2
- How to build the lib with visual studio 2017 HOT 3
- Does not compile with /std:c++20 in msvc HOT 1
- Polyhedron against plane split
- float3::ProjectTo assumes that given direction is normalized
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mathgeolib.