Skip to content
Snippets Groups Projects
Select Git revision
  • 7fdd2bf3962b1f47a6ec2d8c1e0c26b2a5b3b1b6
  • main default protected
2 results

Utils.jl

Blame
  • Utils.jl 4.59 KiB
    """
    This is the module with the Julia implementations of the generic utilities of the IN-NOVA project.
    --------------------------------------------------
    Author: Achilles Kappis
    e-mail: axilleaz@protonmail.com
    
    Date: 10/08/2024 (DD/MM/YYYY)
    
    Copyright: MIT
    --------------------------------------------------
    
    # Functions included
    - stepFunc
    - isEven
    - isOdd
    - rotMat3d
    --------------------------------------------------
    """
    module Utils
    
    
    
    """
    Numerical (simple) Heaviside function
    --------------------------------------------------
    Author: Achilles Kappis
    e-mail: axilleaz@protonmail.com
    
    Date: 10/08/2024 (DD/MM/YYYY)
    
    Copyright: MIT
    --------------------------------------------------
    Functionality: A Heaviside numerical (step) function
    --------------------------------------------------
    # Input
    
    x::Real: The argument of the function.
    
    zeroHalf::Bool (Optional): The way x = 0 is treated. If this argument is true, the returned value is 0.5 when x = 0, otherwise it is 1. [Default: false].
    
    --------------------------------------------------
    # Output
    result::Float64: Either 0 or 1 based on whether the argument of the function is greater or equal to zero.
    --------------------------------------------------
    # Notes
    
    --------------------------------------------------
    """
    function stepFunc(x::Real; zeroHalf::Bool = false)
        if zeroHalf && x == 0
            result = 0.5
        else
            result = x >= 0
        end
        
        return convert(Float64, result)
    end
    
    
    
    
    
    """
    Determine whether a number is even
    --------------------------------------------------
    Author: Achilles Kappis
    e-mail: axilleaz@protonmail.com
    
    Date: 10/08/2024 (DD/MM/YYYY)
    
    Copyright: MIT
    --------------------------------------------------
    Functionality: Function to check if a real integer is even.
    --------------------------------------------------
    # Input arguments
    
    num::Integer: The number to check.
    
    --------------------------------------------------
    # Output arguments
    
    result::Bool: True if the number is even, False else.
    
    --------------------------------------------------
    # Notes
    
    --------------------------------------------------
    """
    function isEven(num::Integer)
        return mod(num, 2) == 0
    end
    
    
    
    
    """
    Determine whether a number is odd
    --------------------------------------------------
    Author: Achilles Kappis
    e-mail: axilleaz@protonmail.com
    
    Date: 10/08/2024 (DD/MM/YYYY)
    
    Copyright: MIT
    --------------------------------------------------
    Functionality: Function to check if a real integer is odd.
    --------------------------------------------------
    # Input arguments
    
    num::Integer: The number to check.
    
    --------------------------------------------------
    # Output arguments
    
    result::Bool: True if the number is even, False else.
    
    --------------------------------------------------
    # Notes
    
    --------------------------------------------------
    """
    function isOdd(num::Integer)
        return mod(num, 2) != 0
    end
    
    
    
    
    """
    Calculate a 3D rotation matrix
    --------------------------------------------------
    Author: Achilles Kappis
    e-mail: axilleaz@protonmail.com
    
    Date: 10/08/2024 (DD/MM/YYYY)
    
    Copyright: MIT
    --------------------------------------------------
    Functionality: Calculate a 3D rotation matrix.
    --------------------------------------------------
    # Input
    
    xAng::Real: Rotation angle around the x-axis.
    
    yAng::Real (Optional): Rotation angle around the y-axis. [Default: 0].
    
    zAng::Real (Optional): Rotation angle around the z-axis. [Default: 0].
    
    deg::Bool (Optional) [keyword]: This value declares if the provided angles are in degrees or not. If not, radians are assumed. [Default: false].
    --------------------------------------------------
    # Output
    
    rotMat::Matrix{Real}: A 3x3 matrix which applies the rotation.
    
    xRotMat::Matrix{Real}: A 3x3 matrix which applies the rotation around the x-axis.
    
    yRotMat::Matrix{Real}: A 3x3 matrix which applies the rotation around the y-axis.
    
    zRotMat::Matrix: A 3x3 matrix which applies the rotation around the z-axis.
    --------------------------------------------------
    # Notes
    
    --------------------------------------------------
    """
    function rotMat3d(xAng::Real, yAng::Real = 0, zAng::Real = 0; deg::Bool = false)
        # Check for units of the angles
        if deg
            xAng = deg2rad(xAng)
            yAng = deg2rad(yAng)
            zAng = deg2rad(zAng)
        end
        
        # Generate the respective matrices
        xRotMat = [1 0 0; 0 cos(xAng) -sin(xAng); 0 sin(xAng) cos(xAng)]
        yRotMat = [cos(yAng) 0 sin(yAng); 0 1 0; -sin(yAng) 0 cos(yAng)]
        zRotMat = [cos(zAng) -sin(zAng) 0; sin(zAng) cos(zAng) 0; 0 0 1]
        
        # Calculate the "total" matrix
        rotMat = xRotMat * yRotMat * zRotMat
        
        # Return
        return rotMat, xRotMat, yRotMat, zRotMat
    end
    
    
    
    
    end # Module end