How to normalize a mesh into -1 to 1, then revert from normalized mesh to original one?

元气小坏坏 提交于 2019-12-04 23:26:42

I know how easy it can be to get lost in programming and completely miss the simplicity of the underlying math. But trust me, it really is simple.

The most intuitive way to go about your problem is probably this:

  1. determine the minimum and maximum value for all three coordinate axes (i.e., x, y and z). This information is contained by the eight corner vertices of your cube. Save these six values in six variables (e.g., min_x, max_x, etc.).

  2. For all points p = (x,y,z) in the mesh, compute

    q =  ( 2.0*(x-min_x)/(max_x-min_x) - 1.0
           2.0*(y-min_y)/(max_y-min_y) - 1.0
           2.0*(z-min_z)/(max_z-min_z) - 1.0 )
    

    now q equals p translated to the interval (-1,-1,-1) -- (+1,+1,+1).

  3. Do whatever you need to do on this intermediate grid.

  4. Convert all coordinates q = (xx, yy, zz) back to the original grid by doing the inverse operation:

    p =  ( (xx+1.0)*(max_x-min_x)/2.0 + min_x
           (yy+1.0)*(max_y-min_y)/2.0 + min_y
           (zz+1.0)*(max_z-min_z)/2.0 + min_z )
    
  5. Clean up any mess you've made and continue with the rest of your program.

This is so easy, it's probably a lot more work to find out which library contains these functions than it is to write them yourself.

It's easy - use shape functions. Here's a 1D example for two points:

-1 <= u <= +1
x(u) = x1*(1-u)/2.0 + x2*(1+u)/2.0
x(-1) = x1
x(+1) = x2

You can transform between coordinate systems using the Jacobean.

Let's see what it looks like in 2D:

-1 <= u <= =1
-1 <= v <= =1
x(u, v) = x1*(1-u)*(1-v)/4.0 + x2*(1+u)*(1-v)/4.0 + x3*(1+u)*(1+v)/4.0 + x4*(1-u)*(1+v)/4.0
y(u, v) = y1*(1-u)*(1-v)/4.0 + y2*(1+u)*(1-v)/4.0 + y3*(1+u)*(1+v)/4.0 + y4*(1-u)*(1+v)/4.0
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!