Jump to content
  • Advertisement
Sign in to follow this  

Scaling a 3D mesh (vertices, tetrahedra)

This topic is 3793 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, I am currently implementing an isosurface extracting algorithm for a 3D mesh (made of vertices and vertices collections -> tetrahedra). In order to add some flexibility i want to write a scale function that allows scaling up and down the length of the edges of the tetrahedra. My first attempt was taking the current edge length of the mesh (same for all edges), e.g. edgeLength = 1, scaling it up by 10% to 1.1, dividing new edgeLength by old edgeLength = 1.1/1 and using this scaleFactor to multiply with the coordinates of every vertex of the mesh: v_new.x = v_old.x * scaleFactor; v_new.y = v_old.y * scaleFactor; v_new.z = v_old.z * scaleFactor; This was apparently a foolish attempt. Are there any suggestions how to scale a mesh consistently. Thanks and greets

Share this post

Link to post
Share on other sites

could you clarify what is wrong with your method? As far as I can see, it should work perfectly if the mesh is centered at the origin, and should work in other cases as well, with the problem of offsetting the whole mesh somewhat.

Share this post

Link to post
Share on other sites
Your question is absolutely right. I have to admit that i am using a mesh of tetrahedra of two shapes: one part is regular and the other has a rectangular form (meaning there are angles of 90 and 45 in it). The center point of the coordinate system lies inside, but anyway, as you mentioned, this should "only" offset the tetrahedron but not change its shape (except scaling it bigger). My function looks as that:

[code lang=cpp]

std::vector < Polyhedron * const > ::iterator polyhedronIter;
float scale, oldScaledEdgeLength;

oldScaledEdgeLength = scaledPolyhedronEdgeLength;

scaledPolyhedronEdgeLength = scaledPolyhedronEdgeLength + value * polyhedronEdgeLength;

scaledPolyhedronEdgeLength = ( scaledPolyhedronEdgeLength / polyhedronEdgeLength ) <= 2.0 && ( scaledPolyhedronEdgeLength / polyhedronEdgeLength ) >= 0.5 ? scaledPolyhedronEdgeLength : oldScaledEdgeLength;

scale = scaledPolyhedronEdgeLength / oldScaledEdgeLength;

for( polyhedronIter = m_polyhedrons.begin();
polyhedronIter != m_polyhedrons.end();
++polyhedronIter )

Vertex * vx[4];
Vector vc0, vc1, vc2, vc3;

vx[0] = (*polyhedronIter)->getVertex(0);
vx[1] = (*polyhedronIter)->getVertex(1);
vx[2] = (*polyhedronIter)->getVertex(2);
vx[3] = (*polyhedronIter)->getVertex(3);

vc0 = *(vx[0]) * scale;
vc1 = *(vx[1]) * scale;
vc2 = *(vx[2]) * scale;
vc3 = *(vx[3]) * scale;

vx[0]->setCoordinates( vc0 );
vx[1]->setCoordinates( vc1 );
vx[2]->setCoordinates( vc2 );
vx[3]->setCoordinates( vc3 );


so it does exactly what i wrote: just scaling the vertex-coords with the same scale factor.

Nevertheless it is producing bad scaled tetras. Here is one example for up- and one for downscaling:



Share this post

Link to post
Share on other sites
The relative position of the vertices shouldn't affect anything, the method should work for any type of shapes.

The mistake has to be in your code somewhere, although I'm having trouble finding it. Your "rectangular tetrahedron" still has 4 vertices right? Did you copy/paste the code here - is it exactly the same code that produced the results on the screenshot? On the screenshot, the scaling looks obviously non-uniform, maybe it would help to further localize the problem if you could show a screenshot with only 1 tetrahedron and a more radical scaling value (e.g. 1.5 and 0.5).

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!