///////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2025 Equinor ASA // // ResInsight is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY // WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE. // // See the GNU General Public License at // for more details. // ///////////////////////////////////////////////////////////////////////////////// #include #include namespace Ria { //================================================================================================== // Degrees normalization //================================================================================================== template inline Degrees Degrees::normalized() const { T normalized = cvf::Math::fmod( m_value, T( 360 ) ); if ( normalized < T( 0 ) ) { normalized += T( 360 ); } return Degrees( normalized ); } //================================================================================================== // Radians normalization //================================================================================================== template inline Radians Radians::normalized() const { T twoPi = T( 2 ) * ( std::is_same_v ? cvf::PI_F : cvf::PI_D ); T normalized = cvf::Math::fmod( m_value, twoPi ); if ( normalized < T( 0 ) ) { normalized += twoPi; } return Radians( normalized ); } //================================================================================================== // Coordinate conversion implementations //================================================================================================== template inline cvf::Vector3 CoordinateConverter::cylindricalToCartesian( T radius, const Radians& angle, T height ) { T x = radius * cvf::Math::cos( angle.value() ); T y = radius * cvf::Math::sin( angle.value() ); return cvf::Vector3( x, y, height ); } template inline cvf::Vector3 CoordinateConverter::cylindricalToCartesian( T radius, const Degrees& angle, T height ) { T angleRad = cvf::Math::toRadians( angle.value() ); T x = radius * cvf::Math::cos( angleRad ); T y = radius * cvf::Math::sin( angleRad ); return cvf::Vector3( x, y, height ); } template inline cvf::Vector3 CoordinateConverter::cylindricalToCartesian( const CylindricalCoordinate& coord ) { T x = static_cast( coord.radius * cvf::Math::cos( coord.angle ) ); T y = static_cast( coord.radius * cvf::Math::sin( coord.angle ) ); T z = static_cast( coord.height ); return cvf::Vector3( x, y, z ); } template inline CylindricalCoordinate CoordinateConverter::cartesianToCylindrical( const cvf::Vector3& cartesian ) { return cartesianToCylindrical( cartesian.x(), cartesian.y(), cartesian.z() ); } template inline CylindricalCoordinate CoordinateConverter::cartesianToCylindrical( T x, T y, T z ) { double radius = cvf::Math::sqrt( static_cast( x * x + y * y ) ); double angle = std::atan2( static_cast( y ), static_cast( x ) ); double height = static_cast( z ); return CylindricalCoordinate( radius, Radiansd( angle ), height ); } } // namespace Ria