Trigonometry Calculator
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f8f9fa;
color: #333;
line-height: 1.6;
margin: 0;
padding: 20px;
}
.trig-calc-container {
max-width: 700px;
margin: 30px auto;
background-color: #ffffff;
padding: 30px;
border-radius: 8px;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
border: 1px solid #e0e0e0;
}
h1 {
color: #004a99;
text-align: center;
margin-bottom: 25px;
font-size: 2.2em;
}
.input-group {
margin-bottom: 20px;
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 15px;
}
.input-group label {
font-weight: 600;
min-width: 150px;
color: #004a99;
}
.input-group input[type="number"],
.input-group select {
flex-grow: 1;
padding: 10px 12px;
border: 1px solid #ced4da;
border-radius: 4px;
font-size: 1em;
min-width: 180px;
}
.input-group select {
cursor: pointer;
}
button {
display: block;
width: 100%;
padding: 12px 20px;
background-color: #004a99;
color: white;
border: none;
border-radius: 4px;
font-size: 1.1em;
font-weight: bold;
cursor: pointer;
transition: background-color 0.3s ease;
margin-top: 10px;
}
button:hover {
background-color: #003366;
}
.result-container {
margin-top: 30px;
padding: 20px;
background-color: #e7f3ff;
border: 1px dashed #004a99;
border-radius: 4px;
text-align: center;
}
.result-container h3 {
margin-top: 0;
color: #004a99;
font-size: 1.4em;
}
.result-value {
font-size: 2em;
font-weight: bold;
color: #28a745;
margin-top: 10px;
}
.explanation {
margin-top: 40px;
border-top: 1px solid #e0e0e0;
padding-top: 20px;
}
.explanation h2 {
color: #004a99;
text-align: center;
margin-bottom: 20px;
}
.explanation p, .explanation h3, .explanation ul {
margin-bottom: 15px;
}
.explanation h3 {
color: #003366;
margin-top: 20px;
}
code {
background-color: #f0f0f0;
padding: 2px 5px;
border-radius: 3px;
font-family: Consolas, monospace;
}
.formula {
font-style: italic;
color: #555;
margin-left: 10px;
}
.warning {
color: #dc3545;
font-weight: bold;
margin-top: 10px;
}
@media (max-width: 600px) {
.input-group {
flex-direction: column;
align-items: flex-start;
}
.input-group label {
min-width: auto;
margin-bottom: 5px;
}
.input-group input[type="number"],
.input-group select {
width: calc(100% – 24px); /* Adjust for padding */
}
h1 {
font-size: 1.8em;
}
.result-value {
font-size: 1.6em;
}
}
Trigonometry Calculator
Understanding Trigonometry
Trigonometry is a branch of mathematics concerned with relationships between the sides and angles of triangles. It is fundamental to many fields, including physics, engineering, computer graphics, and surveying. The core of trigonometry lies in six fundamental trigonometric functions: sine (sin), cosine (cos), tangent (tan), cosecant (csc), secant (sec), and cotangent (cot). These functions relate an angle of a right-angled triangle to the ratios of its side lengths.
The Six Trigonometric Functions
Consider a right-angled triangle with one angle θ (theta). Let 'opposite' be the side opposite to the angle θ, 'adjacent' be the side adjacent to the angle θ, and 'hypotenuse' be the side opposite the right angle.
- Sine (sin θ): The ratio of the length of the opposite side to the length of the hypotenuse. sin(θ) = opposite / hypotenuse
- Cosine (cos θ): The ratio of the length of the adjacent side to the length of the hypotenuse. cos(θ) = adjacent / hypotenuse
- Tangent (tan θ): The ratio of the length of the opposite side to the length of the adjacent side. tan(θ) = opposite / adjacent
- Cosecant (csc θ): The reciprocal of sine. csc(θ) = 1 / sin(θ) = hypotenuse / opposite
- Secant (sec θ): The reciprocal of cosine. sec(θ) = 1 / cos(θ) = hypotenuse / adjacent
- Cotangent (cot θ): The reciprocal of tangent. cot(θ) = 1 / tan(θ) = adjacent / opposite
This calculator focuses on evaluating these trigonometric functions for a given angle. The angle can be expressed in degrees or radians, which are the two most common units for measuring angles.
Use Cases:
- Physics: Analyzing wave motion, projectile trajectories, and forces.
- Engineering: Designing structures, electrical circuits, and mechanical systems.
- Navigation: Calculating distances and directions.
- Computer Graphics: Rendering 3D scenes and animations.
- Surveying: Measuring distances and elevations.
How to Use the Calculator:
- Enter the value of the angle you want to calculate a trigonometric function for in the "Angle Value" field.
- Select whether the angle is in "Degrees" or "Radians" using the dropdown menu.
- Choose the trigonometric "Function" (sin, cos, tan, csc, sec, cot) you want to evaluate.
- Click the "Calculate" button.
- The result will be displayed in the "Result" area.
Examples:
- Calculate sin(30 degrees): Enter
30 in "Angle Value", select "Degrees", choose "Sine (sin)", and click "Calculate". The result should be 0.5.
- Calculate tan(PI/4 radians): Enter
1.57079632679 (or simply use a calculator that provides PI value) in "Angle Value", select "Radians", choose "Tangent (tan)", and click "Calculate". The result should be approximately 1 (tan(PI/4) is exactly 1).
- Calculate sec(60 degrees): Enter
60 in "Angle Value", select "Degrees", choose "Secant (sec)", and click "Calculate". The result should be 2 (since cos(60) = 0.5, sec(60) = 1/0.5 = 2).
function calculateTrig() {
var angleValueInput = document.getElementById("angleValue");
var angleUnit = document.getElementById("angleUnit").value;
var functionType = document.getElementById("functionType").value;
var resultDiv = document.getElementById("result");
var errorMessageDiv = document.getElementById("errorMessage");
errorMessageDiv.textContent = ""; // Clear previous errors
resultDiv.textContent = "–"; // Reset result
var angleValue = parseFloat(angleValueInput.value);
if (isNaN(angleValue)) {
errorMessageDiv.textContent = "Please enter a valid number for the angle value.";
return;
}
var angleInRadians;
if (angleUnit === "deg") {
angleInRadians = angleValue * (Math.PI / 180);
} else {
angleInRadians = angleValue;
}
var result;
var denominatorCheck = 1; // For functions that might divide by zero
try {
switch (functionType) {
case "sin":
result = Math.sin(angleInRadians);
break;
case "cos":
result = Math.cos(angleInRadians);
break;
case "tan":
result = Math.tan(angleInRadians);
denominatorCheck = Math.cos(angleInRadians);
if (Math.abs(denominatorCheck) < 1e-10) { // Check if close to zero
throw new Error("Tangent is undefined for angles where cosine is zero (e.g., 90°, 270°, etc.).");
}
break;
case "csc":
result = 1 / Math.sin(angleInRadians);
denominatorCheck = Math.sin(angleInRadians);
if (Math.abs(denominatorCheck) < 1e-10) { // Check if close to zero
throw new Error("Cosecant is undefined for angles where sine is zero (e.g., 0°, 180°, 360°, etc.).");
}
break;
case "sec":
result = 1 / Math.cos(angleInRadians);
denominatorCheck = Math.cos(angleInRadians);
if (Math.abs(denominatorCheck) < 1e-10) { // Check if close to zero
throw new Error("Secant is undefined for angles where cosine is zero (e.g., 90°, 270°, etc.).");
}
break;
case "cot":
result = 1 / Math.tan(angleInRadians);
denominatorCheck = Math.tan(angleInRadians);
if (Math.abs(denominatorCheck) < 1e-10) { // Check if close to zero
throw new Error("Cotangent is undefined for angles where tangent is zero (e.g., 0°, 180°, 360°, etc.).");
}
break;
default:
throw new Error("Invalid function type selected.");
}
// Round to a reasonable precision
result = result.toFixed(10);
// Remove trailing zeros and decimal point if it's an integer
result = parseFloat(result);
resultDiv.textContent = result;
} catch (error) {
errorMessageDiv.textContent = error.message;
}
}