A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by JoeJ » Wed Apr 08, 2015 7:42 am
Is there an easy way to use Newton for that?
Actually i need the volume of the convex hull, and to calculate that i need a bounding triangle list.
The only 'simple' code on web i've found is from Joseph O'Rourke, but it crashes sometimes after i've converted it from integer to floating point.
If someone knows some other simple and robust code, please let me know.
I have 4-10 points, for asset pre-processing, so it does not need to be fast.
Stuff like qHull looks too bloated for my needs.
- Code: Select all
float verts[] = {
-0.783095717, 0.584569395, 0.212225780,
-0.540878713, 0.799171329, 0.262250662,
-0.788511813, 0.588095009, 0.179981545,
-0.513972282, 0.816857636, 0.261870265,
-0.732940018, 0.637774587, 0.236732647,
-0.506947637, 0.825368643, 0.248537064,
-0.720508039, 0.649915934, 0.241821036,
-0.901874065, 0.413956910, 0.123543225,
};
for (int i=0; i<sizeof(verts) / (sizeof(float) * 3); i++)
cHull.AddVertex (verts[i*3], verts[i*3+1], verts[i*3+2]);
cHull.BuildConvexHull();
float vol = cHull.Volume();
-

JoeJ
-
- Posts: 1489
- Joined: Tue Dec 21, 2010 6:18 pm
by Julio Jerez » Wed Apr 08, 2015 8:33 am
if you look at class dgConvexHull3d:
it has function
void dgConvexHull3d::CalculateVolumeAndSurfaceArea (dgFloat64& volume, dgFloat64& surcafeArea) const;
you can expose that class by including the header to library code.h
or copy the class and made you own.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by JoeJ » Wed Apr 08, 2015 9:45 am
Thanks!
Really simple to use

But now i don't know how to setup the Memory Allocator (actually it crashes).
I'd like to do it in a way that it is independent from memory used by physics,
and it should not not matter if physics are in use or not.
(I'm not experienced about Memory Managers)
- Code: Select all
struct ConvexHull
{
std::vector<dgFloat64 >tempPointData;
dgConvexHull3d *newtonHull;
dgMemoryAllocator *allocator;
dgFloat64 volume;
dgFloat64 surcafeArea;
ConvexHull ()
{
allocator = new dgMemoryAllocator;
if (allocator)
{
//allocator->SetAllocatorsCallback (); ???
}
newtonHull = 0;
volume = 0;
surcafeArea = 0;
}
~ConvexHull ()
{
if (newtonHull) delete newtonHull;
if (allocator) delete allocator;
}
void AddVertex (float x, float y, float z, int userIndex)
{
tempPointData.push_back (x);
tempPointData.push_back (y);
tempPointData.push_back (z);
}
bool BuildConvexHull ()
{
if (allocator)
{
newtonHull = new dgConvexHull3d (allocator, &tempPointData[0], sizeof(double), tempPointData.size()/3, 0.0001, 200);
if (newtonHull)
{ newtonHull->CalculateVolumeAndSurfaceArea (volume, surcafeArea);
return true;
}
}
return false;
}
float Volume ()
{
return volume;
}
};
-

JoeJ
-
- Posts: 1489
- Joined: Tue Dec 21, 2010 6:18 pm
by Julio Jerez » Wed Apr 08, 2015 1:01 pm
you got some options options
1- you can make you own copy.
2- you can use the NewtonCores Library. this si no relate to the phsic sin any way. and is ti a ver ypaweful comutation geometry library
if you the core library, you can call the hull like this
- Code: Select all
dgMemoryAllocator allocation;
dgConvexHull3d::dgConvexHull3d myhull (&allocation);
3-you can get the allocation class and the hull library.
I would go for the core library, is very small and quiet powerfull.
There is one forth option, the people at NVidia took that class and extracted as a stand along tool.
The use in some their tools,
http://code.google.com/p/juliohull/I still go for the core library
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by JoeJ » Wed Apr 08, 2015 2:46 pm
Ok Thanks, it works now.
I'll paste the working code for reference.
- Code: Select all
#include <../core/dgConvexHull3d.h>
#include <vector>
struct ConvexHull
{
std::vector<dgFloat64> tempPointData;
dgMemoryAllocator allocation;
dgFloat64 volume;
dgFloat64 surcafeArea;
ConvexHull ()
{
volume = 0;
surcafeArea = 0;
}
~ConvexHull ()
{
}
void AddVertex (float x, float y, float z, int userIndex)
{
tempPointData.push_back (x);
tempPointData.push_back (y);
tempPointData.push_back (z);
}
bool BuildConvexHull ()
{
dgConvexHull3d myhull (&allocation, &tempPointData[0], sizeof(double)*3, tempPointData.size()/3, 0.0001, 200);
myhull.CalculateVolumeAndSurfaceArea (volume, surcafeArea);
return true;
}
float Volume ()
{
return volume;
}
};
-

JoeJ
-
- Posts: 1489
- Joined: Tue Dec 21, 2010 6:18 pm
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 2 guests