Posted on by Kalkicode
Code Conversion

Convert milliradian to degree

In the field of mathematics and science, angles are often measured in degrees. However, there are alternative units of measurement for angles, such as radians and milliradians. Radians are a unit of angular measurement that is closely related to the radius of a circle. On the other hand, milliradians (mrad) are even smaller units of angular measurement, where 1 milliradian is equal to 1/1000 of a radian.

The need to convert between different units of angular measurement arises in various applications, including physics, engineering, astronomy, and computer graphics. In this article, we will focus on the conversion of milliradians to degrees using a simple program.

Problem Statement

Given an angle in milliradians, the task is to convert it to degrees using a predefined formula. The formula involves multiplying the milliradian value by a conversion factor and dividing by π (pi).

Example

Let's take the example of an angle given in milliradians: 1000.5 mrad.

The formula for conversion is: degree = (milliradian * 180) / (π * 1000)

Here, π is a mathematical constant approximately equal to 3.14159.

Plugging in the values:
degree = (1000.5 * 180) / (3.14159 * 1000) ≈ 57.324427 degrees

Idea to Solve

To solve this problem, we need to implement a program that takes a milliradian value as input, applies the conversion formula, and outputs the corresponding angle in degrees. The program should use the defined formula and the mathematical constant π.

Pseudocode

FUNCTION milliradian_to_degree(milliradian)
    degree = (milliradian * 180) / (π * 1000)
    PRINT "Milliradian :", milliradian, "  Degree :", degree

FUNCTION main()
    milliradian_to_degree(1)
    milliradian_to_degree(70.8)
    milliradian_to_degree(1000.5)
    RETURN 0

Algorithm Explanation

  1. Define the function milliradian_to_degree(milliradian) that takes a milliradian value as input.
  2. Inside the function, calculate the corresponding degree using the formula provided: degree = (milliradian * 180) / (π * 1000).
  3. Print the milliradian and degree values using a formatted output.
  4. In the main() function, call milliradian_to_degree() with different milliradian values: 1, 70.8, and 1000.5.

Program Solution

//C Program 
//Convert milliradian to degree
#include <stdio.h>

#include <math.h>

//Find the degree of given milliradian
void milliradian_to_degree(double milliradian)
{
	// Formula : (milliradian*180)/(π*1000)
	// Calculate given milliradian to degree 
	double degree = (milliradian * 180) / (M_PI * 1000);
	//Display result
	printf("Milliradian : %lf  Degree : %lf\n", milliradian, degree);
}
int main()
{
	//Simple test
	milliradian_to_degree(1);
	milliradian_to_degree(70.8);
	milliradian_to_degree(1000.5);
	return 0;
}

Output

Milliradian : 1.000000  Degree : 0.057296
Milliradian : 70.800000  Degree : 4.056541
Milliradian : 1000.500000  Degree : 57.324427
/*
  C++ program
  Convert milliradian to degree 
*/
#include<iostream>
#include<math.h>
using namespace std;
class MyMath
{
	public:
		//Find the degree of given milliradian
		void milliradian_to_degree(double milliradian)
		{
			// Formula : (radian*180)/(π*1000)
			// Calculate given milliradian to degree 
			double degree = (milliradian * 180) / (M_PI * 1000);
			cout << "Milliradian : " << milliradian << " Degree : " << degree << "\n";
		}
};
int main()
{
	MyMath obj =  MyMath();
	//Simple test
	obj.milliradian_to_degree(1);
	obj.milliradian_to_degree(70.80);
	obj.milliradian_to_degree(1000.50);
	return 0;
}

Output

Milliradian : 1 Degree : 0.0572958
Milliradian : 70.8 Degree : 4.05654
Milliradian : 1000.5 Degree : 57.3244
/*
  Java program
  Convert milliradian to degree 
*/
class MyMath
{
	//Find the degree of given milliradian
	public void milliradian_to_degree(double milliradian)
	{
		// Formula : (radian*180)/(π*1000)
		// Calculate given milliradian to degree 
		double degree = (milliradian * 180) / (Math.PI * 1000);
		System.out.print("Milliradian : " + milliradian + " Degree : " + degree + "\n");
	}
	public static void main(String[] args)
	{
		MyMath obj = new MyMath();
		//Simple test
		obj.milliradian_to_degree(1);
		obj.milliradian_to_degree(70.80);
		obj.milliradian_to_degree(1000.50);
	}
}

Output

Milliradian : 1.0 Degree : 0.057295779513082325
Milliradian : 70.8 Degree : 4.056541189526229
Milliradian : 1000.5 Degree : 57.324427402838865
/*
  C# program
  Convert milliradian to degree 
*/
using System;
class MyMath
{
	//Find the degree of given milliradian
	public void milliradian_to_degree(double milliradian)
	{
		// Formula : (radian*180)/(π*1000)
		// Calculate given milliradian to degree 
		double degree = (milliradian * 180) / (Math.PI * 1000);
		Console.Write("Milliradian : " + milliradian + " Degree : " + degree + "\n");
	}
	public static void Main(String[] args)
	{
		MyMath obj = new MyMath();
		//Simple test
		obj.milliradian_to_degree(1);
		obj.milliradian_to_degree(70.80);
		obj.milliradian_to_degree(1000.50);
	}
}

Output

Milliradian : 1 Degree : 0.0572957795130823
Milliradian : 70.8 Degree : 4.05654118952623
Milliradian : 1000.5 Degree : 57.3244274028389
<?php
/*
  Php program
  Convert milliradian to degree 
*/
class MyMath
{
	//Find the degree of given milliradian
	public	function milliradian_to_degree($milliradian)
	{
		// Formula : (radian*180)/(π*1000)
		// Calculate given milliradian to degree 
		$degree = ($milliradian * 180) / (M_PI * 1000);
		echo "Milliradian : ". $milliradian ." Degree : ". $degree ."\n";
	}
}

function main()
{
	$obj = new MyMath();
	//Simple test
	$obj->milliradian_to_degree(1);
	$obj->milliradian_to_degree(70.80);
	$obj->milliradian_to_degree(1000.50);
}
main();

Output

Milliradian : 1 Degree : 0.057295779513082
Milliradian : 70.8 Degree : 4.0565411895262
Milliradian : 1000.5 Degree : 57.324427402839
/*
  Node Js program
  Convert milliradian to degree 
*/
class MyMath
{
	//Find the degree of given milliradian
	milliradian_to_degree(milliradian)
	{
		// Formula : (radian*180)/(π*1000)
		// Calculate given milliradian to degree 
		var degree = (milliradian * 180) / (Math.PI * 1000);
		process.stdout.write("Milliradian : " + milliradian + " Degree : " + degree + "\n");
	}
}

function main()
{
	var obj = new MyMath();
	//Simple test
	obj.milliradian_to_degree(1);
	obj.milliradian_to_degree(70.80);
	obj.milliradian_to_degree(1000.50);
}
main();

Output

Milliradian : 1 Degree : 0.057295779513082325
Milliradian : 70.8 Degree : 4.056541189526229
Milliradian : 1000.5 Degree : 57.324427402838865
#   Python 3 program
#   Convert milliradian to degree 
import math

class MyMath :
	# Find the degree of given milliradian
	def milliradian_to_degree(self, milliradian) :
		#  Formula : (radian*180)/(π*1000)
		#  Calculate given milliradian to degree 
		degree = (milliradian * 180) / (math.pi * 1000)
		print("Milliradian : ", milliradian ," Degree : ", degree ,"\n", end = "")
	

def main() :
	obj = MyMath()
	# Simple test
	obj.milliradian_to_degree(1)
	obj.milliradian_to_degree(70.80)
	obj.milliradian_to_degree(1000.50)

if __name__ == "__main__": main()

Output

Milliradian :  1  Degree :  0.057295779513082325
Milliradian :  70.8  Degree :  4.056541189526229
Milliradian :  1000.5  Degree :  57.324427402838865
#   Ruby program
#   Convert milliradian to degree 

class MyMath

	# Find the degree of given milliradian
	def milliradian_to_degree(milliradian)
	
		#  Formula : (radian*180)/(π*1000)
		#  Calculate given milliradian to degree 
		degree = (milliradian * 180) / (Math::PI * 1000)
		print("Milliradian : ", milliradian ," Degree : ", degree ,"\n")
	end
end
def main()

	obj = MyMath.new()
	# Simple test
	obj.milliradian_to_degree(1)
	obj.milliradian_to_degree(70.80)
	obj.milliradian_to_degree(1000.50)
end
main()

Output

Milliradian : 1 Degree : 0.057295779513082325
Milliradian : 70.8 Degree : 4.056541189526229
Milliradian : 1000.5 Degree : 57.324427402838865
/*
  Scala program
  Convert milliradian to degree 
*/
class MyMath
{
	//Find the degree of given milliradian
	def milliradian_to_degree(milliradian: Double): Unit = {
		// Formula : (radian*180)/(π*1000)
		// Calculate given milliradian to degree 
		var degree: Double = (milliradian * 180) / (Math.PI * 1000);
		print("Milliradian : " + milliradian + " Degree : " + degree + "\n");
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var obj: MyMath = new MyMath();
		//Simple test
		obj.milliradian_to_degree(1);
		obj.milliradian_to_degree(70.80);
		obj.milliradian_to_degree(1000.50);
	}
}

Output

Milliradian : 1.0 Degree : 0.057295779513082325
Milliradian : 70.8 Degree : 4.056541189526229
Milliradian : 1000.5 Degree : 57.324427402838865
/*
  Swift program
  Convert milliradian to degree 
*/

import Foundation

class MyMath
{
	//Find the degree of given milliradian
	func milliradian_to_degree(_ milliradian: Double)
	{
		// Formula : (radian*180)/(π*1000)
		// Calculate given milliradian to degree 
		let degree: Double = (milliradian * 180) / (Double.pi * 1000);
		print("Milliradian : ", milliradian ," Degree : ", degree ,"\n", terminator: "");
	}
}
func main()
{
	let obj: MyMath = MyMath();
	//Simple test
	obj.milliradian_to_degree(1);
	obj.milliradian_to_degree(70.80);
	obj.milliradian_to_degree(1000.50);
}
main();

Output

Milliradian :  1.0  Degree :  0.0572957795130823
Milliradian :  70.8  Degree :  4.05654118952623
Milliradian :  1000.5  Degree :  57.3244274028389

Time Complexity

The time complexity of this program is constant for each conversion. The calculations involved are basic arithmetic operations, which are generally executed in constant time on modern computers. Therefore, the time complexity can be considered O(1), indicating constant time complexity.

Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment