Skip to content

The XYZ TO UVW Python function #50

Open

Description

@dinghanwang

Howdy, thank you for explaining two systems, do you know any built Python function to transform, thank you!

Activity

  1. PauloCarvalhoRJ commented on Jul 3, 2025

    @PauloCarvalhoRJ

    Hello,

    Here's my implementation in C++ from here) which was an extension to 3D of this one:

        
    
    	//Obtain the topological coordinates (IJK) of the cell that contains the location.
    	uint i, j, k;
    	if( ! XYZtoIJK( x, y, z, i, j, k ) )
    		return false;
    
    	//Obtain the index of the cell.
    	uint cellIndex = IJKtoIndex( i, j, k );
    
    	//Make a point object corresponding to the query location.
    	Vertex3D location{ x, y, z };
    
    	//Get the faces' geometries of the cell.
    	std::vector<Face3D> cellFaces = getFaces( cellIndex );
    
    	//faces 2 and 3 are along I direction, thus are respect to U depositional coordinate
    	//faces 4 and 5 are along J direction, thus are respect to V depositional coordinate
    	//faces 0 and 1 are along K direction, thus are respect to W depositional coordinate
    	//compute the six distances between the location and the faces
    	double dU0 = cellFaces[2].distance( location );
    	double dU1 = cellFaces[3].distance( location );
    	double dV0 = cellFaces[4].distance( location );
    	double dV1 = cellFaces[5].distance( location );
    	double dW0 = cellFaces[0].distance( location );
    	double dW1 = cellFaces[1].distance( location );
    
    	//compute the UVW within the cell (min = 0.0, max = 1.0)
    	double local_u = dU0 / (dU0 + dU1);
    	double local_v = dV0 / (dV0 + dV1);
    	double local_w = dW0 / (dW0 + dW1);
    
    	//compute the global UVW steps.
    	double du = 1.0 / m_nI;
    	double dv = 1.0 / m_nJ;
    	double dw = 1.0 / m_nK;
    
    	//compute the UVW coordinates.
    	u = du * i + du * local_u;
    	v = dv * j + dv * local_v;
    	w = dw * k + dw * local_w;
    
        //enforcing sanity
        if( std::isfinite( u ) && std::isfinite( v ) && std::isfinite( w ) )
            return true;
        else
            return false;

    Maybe this can help someone get started on a Python implementation.

    best,

    PC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions