Spaces:
Running
Running
Download index.html from onlyoneritz/visual-trigonometry: direct link, hf CLI and curl.
- Browser
- Download file 22.5 kB
-
https://huggingface.co/spaces/onlyoneritz/visual-trigonometry/resolve/main/index.html
- Command line
-
hf download hf://spaces/onlyoneritz/visual-trigonometry/index.html
-
curl -L -o index.html https://huggingface.co/spaces/onlyoneritz/visual-trigonometry/resolve/main/index.html
22.5 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Visual Trigonometry</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> | |
| <script src="https://kit.fontawesome.com/a076d05399.js" crossorigin="anonymous"></script> | |
| <style> | |
| .unit-circle { | |
| width: 300px; | |
| height: 300px; | |
| border: 2px solid #3b82f6; | |
| border-radius: 50%; | |
| position: relative; | |
| margin: 0 auto; | |
| background-color: #f8fafc; | |
| } | |
| .center-point { | |
| width: 6px; | |
| height: 6px; | |
| background-color: #ef4444; | |
| border-radius: 50%; | |
| position: absolute; | |
| top: 50%; | |
| left: 50%; | |
| transform: translate(-50%, -50%); | |
| } | |
| .radius-line { | |
| position: absolute; | |
| top: 50%; | |
| left: 50%; | |
| height: 2px; | |
| background-color: #10b981; | |
| transform-origin: left center; | |
| z-index: 1; | |
| } | |
| .triangle { | |
| position: absolute; | |
| border: 1px dashed #8b5cf6; | |
| background-color: rgba(139, 92, 246, 0.1); | |
| } | |
| .angle-display { | |
| position: absolute; | |
| top: 10px; | |
| right: 10px; | |
| background-color: rgba(255, 255, 255, 0.8); | |
| padding: 5px; | |
| border-radius: 4px; | |
| font-size: 0.8rem; | |
| } | |
| .highlight { | |
| box-shadow: 0 0 10px 2px rgba(251, 191, 36, 0.7); | |
| transition: all 0.3s ease; | |
| } | |
| </style> | |
| </head> | |
| <body class="bg-gray-50 min-h-screen"> | |
| <header class="bg-indigo-600 text-white py-6"> | |
| <div class="container mx-auto px-4"> | |
| <h1 class="text-3xl md:text-4xl font-bold text-center">Visual Trigonometry</h1> | |
| <p class="text-center mt-2 text-indigo-100">See the relationships between angles and ratios come to life</p> | |
| </div> | |
| </header> | |
| <main class="container mx-auto px-4 py-8"> | |
| <div class="grid grid-cols-1 lg:grid-cols-2 gap-8"> | |
| <div class="bg-white rounded-lg shadow-lg p-6"> | |
| <h2 class="text-2xl font-semibold text-gray-800 mb-4">Unit Circle Interactive</h2> | |
| <div class="unit-circle" id="unitCircle"> | |
| <div class="center-point"></div> | |
| <div class="radius-line" id="radiusLine" style="width: 120px; transform: rotate(45deg);"></div> | |
| <div class="triangle" id="sineTriangle" style="width: 85px; height: 85px; left: 165px; top: 150px;"></div> | |
| <div class="triangle" id="cosineTriangle" style="width: 85px; height: 85px; left: 150px; top: 165px;"></div> | |
| <div class="angle-display">θ = <span id="angleValue">45</span>°</div> | |
| </div> | |
| <div class="mt-6 flex justify-center space-x-4"> | |
| <button id="increaseAngle" class="bg-indigo-600 text-white px-4 py-2 rounded-md hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500"> | |
| <i class="fas fa-plus mr-2"></i>Increase Angle | |
| </button> | |
| <button id="decreaseAngle" class="bg-indigo-600 text-white px-4 py-2 rounded-md hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500"> | |
| <i class="fas fa-minus mr-2"></i>Decrease Angle | |
| </button> | |
| </div> | |
| <div class="mt-6 flex justify-center"> | |
| <input type="range" id="angleSlider" min="0" max="360" value="45" class="w-full max-w-md"> | |
| </div> | |
| </div> | |
| <div class="bg-white rounded-lg shadow-lg p-6"> | |
| <h2 class="text-2xl font-semibold text-gray-800 mb-4">Trigonometric Functions</h2> | |
| <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6"> | |
| <div class="bg-indigo-50 p-4 rounded-lg cursor-pointer" id="sinBtn"> | |
| <h3 class="font-medium text-indigo-700">Sine (sin)</h3> | |
| <p class="text-indigo-600">Opposite / Hypotenuse</p> | |
| <p class="mt-2 text-xl font-bold">sin(θ) = <span id="sinValue">0.707</span></p> | |
| </div> | |
| <div class="bg-green-50 p-4 rounded-lg cursor-pointer" id="cosBtn"> | |
| <h3 class="font-medium text-green-700">Cosine (cos)</h3> | |
| <p class="text-green-600">Adjacent / Hypotenuse</p> | |
| <p class="mt-2 text-xl font-bold">cos(θ) = <span id="cosValue">0.707</span></p> | |
| </div> | |
| <div class="bg-purple-50 p-4 rounded-lg cursor-pointer" id="tanBtn"> | |
| <h3 class="font-medium text-purple-700">Tangent (tan)</h3> | |
| <p class="text-purple-600">Opposite / Adjacent</p> | |
| <p class="mt-2 text-xl font-bold">tan(θ) = <span id="tanValue">1.000</span></p> | |
| </div> | |
| </div> | |
| <div class="bg-gray-100 p-4 rounded-lg"> | |
| <canvas id="trigChart" height="200"></canvas> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="mt-8 grid grid-cols-1 md:grid-cols-3 gap-6"> | |
| <div class="bg-white rounded-lg shadow-lg p-6"> | |
| <h2 class="text-xl font-semibold text-gray-800 mb-4">Right Triangle</h2> | |
| <div class="relative h-40 w-full bg-blue-50 flex items-center justify-center"> | |
| <div class="triangle-shape" style="width: 100px; height: 100px; border-right: 2px solid #3b82f6; border-bottom: 2px solid #ef4444;"></div> | |
| <div class="absolute top-0 left-0 bg-blue-100 text-blue-800 px-2 py-1 text-xs rounded" style="top: 10px; left: 60px;">Hypotenuse</div> | |
| <div class="absolute bottom-0 left-0 bg-red-100 text-red-800 px-2 py-1 text-xs rounded" style="bottom: 30px; left: 10px;">Opposite</div> | |
| <div class="absolute bottom-0 right-0 bg-green-100 text-green-800 px-2 py-1 text-xs rounded" style="bottom: 10px; right: 30px;">Adjacent</div> | |
| <div class="absolute bottom-0 left-0 text-xs" style="bottom: 10px; left: 40px;">θ</div> | |
| </div> | |
| <p class="mt-4 text-gray-600">In a right-angled triangle, trigonometric functions relate the angles to the ratios of sides.</p> | |
| </div> | |
| <div class="bg-white rounded-lg shadow-lg p-6"> | |
| <h2 class="text-xl font-semibold text-gray-800 mb-4">Special Angles</h2> | |
| <table class="w-full border-collapse"> | |
| <thead> | |
| <tr class="bg-gray-100"> | |
| <th class="p-2 text-left">Angle</th> | |
| <th class="p-2">sin</th> | |
| <th class="p-2">cos</th> | |
| <th class="p-2">tan</th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| <tr class="border-b border-gray-200"> | |
| <td class="p-2">0°</td> | |
| <td class="p-2 text-center">0</td> | |
| <td class="p-2 text-center">1</td> | |
| <td class="p-2 text-center">0</td> | |
| </tr> | |
| <tr class="border-b border-gray-200"> | |
| <td class="p-2">30°</td> | |
| <td class="p-2 text-center">1/2</td> | |
| <td class="p-2 text-center">√3/2</td> | |
| <td class="p-2 text-center">√3/3</td> | |
| </tr> | |
| <tr class="border-b border-gray-200"> | |
| <td class="p-2">45°</td> | |
| <td class="p-2 text-center">√2/2</td> | |
| <td class="p-2 text-center">√2/2</td> | |
| <td class="p-2 text-center">1</td> | |
| </tr> | |
| <tr> | |
| <td class="p-2">60°</td> | |
| <td class="p-2 text-center">√3/2</td> | |
| <td class="p-2 text-center">1/2</td> | |
| <td class="p-2 text-center">√3</td> | |
| </tr> | |
| </tbody> | |
| </table> | |
| </div> | |
| <div class="bg-white rounded-lg shadow-lg p-6"> | |
| <h2 class="text-xl font-semibold text-gray-800 mb-4">Real World Applications</h2> | |
| <ul class="space-y-3"> | |
| <li class="flex items-start"> | |
| <span class="text-yellow-500 mr-2">🏗️</span> | |
| <span>Architecture & Construction (calculating heights and distances)</span> | |
| </li> | |
| <li class="flex items-start"> | |
| <span class="text-blue-500 mr-2">🌊</span> | |
| <span>Navigation & GPS (determining position)</span> | |
| </li> | |
| <li class="flex items-start"> | |
| <span class="text-green-500 mr-2">📡</span> | |
| <span>Physics & Engineering (wave patterns, forces)</span> | |
| </li> | |
| <li class="flex items-start"> | |
| <span class="text-purple-500 mr-2">🎨</span> | |
| <span>Art & Animation (rotations and perspectives)</span> | |
| </li> | |
| </ul> | |
| </div> | |
| </div> | |
| </main> | |
| <footer class="bg-gray-800 text-white py-6 mt-8"> | |
| <div class="container mx-auto px-4 text-center"> | |
| <p>© 2023 Visual Trigonometry - Helping visual learners master trigonometry</p> | |
| </div> | |
| </footer> | |
| <script> | |
| // Initialize variables | |
| let currentAngle = 45; | |
| let trigChart; | |
| // DOM elements | |
| const unitCircle = document.getElementById('unitCircle'); | |
| const radiusLine = document.getElementById('radiusLine'); | |
| const sineTriangle = document.getElementById('sineTriangle'); | |
| const cosineTriangle = document.getElementById('cosineTriangle'); | |
| const angleValue = document.getElementById('angleValue'); | |
| const angleSlider = document.getElementById('angleSlider'); | |
| const increaseAngle = document.getElementById('increaseAngle'); | |
| const decreaseAngle = document.getElementById('decreaseAngle'); | |
| const sinValue = document.getElementById('sinValue'); | |
| const cosValue = document.getElementById('cosValue'); | |
| const tanValue = document.getElementById('tanValue'); | |
| const sinBtn = document.getElementById('sinBtn'); | |
| const cosBtn = document.getElementById('cosBtn'); | |
| const tanBtn = document.getElementById('tanBtn'); | |
| // Initialize chart | |
| function initializeChart() { | |
| const ctx = document.getElementById('trigChart').getContext('2d'); | |
| trigChart = new Chart(ctx, { | |
| type: 'line', | |
| data: { | |
| labels: Array.from({length: 181}, (_, i) => i), // 0 to 180 degrees | |
| datasets: [ | |
| { | |
| label: 'Sine', | |
| data: [], | |
| borderColor: '#3b82f6', | |
| backgroundColor: 'rgba(59, 130, 246, 0.1)', | |
| tension: 0.4, | |
| pointRadius: 0 | |
| }, | |
| { | |
| label: 'Cosine', | |
| data: [], | |
| borderColor: '#10b981', | |
| backgroundColor: 'rgba(16, 185, 129, 0.1)', | |
| tension: 0.4, | |
| pointRadius: 0 | |
| }, | |
| { | |
| label: 'Tangent', | |
| data: [], | |
| borderColor: '#8b5cf6', | |
| backgroundColor: 'rgba(139, 92, 246, 0.1)', | |
| tension: 0.4, | |
| pointRadius: 0, | |
| borderDash: [5, 5] | |
| } | |
| ] | |
| }, | |
| options: { | |
| responsive: true, | |
| plugins: { | |
| legend: { | |
| position: 'top' | |
| }, | |
| tooltip: { | |
| callbacks: { | |
| label: function(context) { | |
| return context.dataset.label + ': ' + context.raw.toFixed(3); | |
| } | |
| } | |
| } | |
| }, | |
| scales: { | |
| x: { | |
| title: { | |
| display: true, | |
| text: 'Angle (degrees)' | |
| } | |
| }, | |
| y: { | |
| title: { | |
| display: true, | |
| text: 'Value' | |
| }, | |
| min: -1.2, | |
| max: 1.2 | |
| } | |
| } | |
| } | |
| }); | |
| // Pre-calculate data for the chart | |
| const sineData = []; | |
| const cosineData = []; | |
| const tangentData = []; | |
| for (let i = 0; i <= 180; i++) { | |
| const radians = i * Math.PI / 180; | |
| sineData.push(Math.sin(radians)); | |
| cosineData.push(Math.cos(radians)); | |
| tangentData.push(Math.tan(radians)); | |
| } | |
| trigChart.data.datasets[0].data = sineData; | |
| trigChart.data.datasets[1].data = cosineData; | |
| trigChart.data.datasets[2].data = tangentData; | |
| trigChart.update(); | |
| } | |
| // Update unit circle visualization | |
| function updateUnitCircle(angle) { | |
| const radians = angle * Math.PI / 180; | |
| const radius = 120; | |
| const centerX = 150; | |
| const centerY = 150; | |
| // Update radius line | |
| radiusLine.style.transform = `rotate(${angle}deg)`; | |
| // Calculate endpoints | |
| const endX = centerX + radius * Math.cos(radians); | |
| const endY = centerY - radius * Math.sin(radians); | |
| // Position triangles | |
| const sinHeight = Math.abs(radius * Math.sin(radians)); | |
| const cosWidth = Math.abs(radius * Math.cos(radians)); | |
| if (angle < 180) { | |
| sineTriangle.style.left = `${centerX}px`; | |
| sineTriangle.style.top = `${centerY - sinHeight}px`; | |
| sineTriangle.style.width = `${cosWidth}px`; | |
| sineTriangle.style.height = `${sinHeight}px`; | |
| sineTriangle.style.borderRight = '1px dashed #8b5cf6'; | |
| } else { | |
| sineTriangle.style.left = `${centerX + cosWidth}px`; | |
| sineTriangle.style.top = `${centerY}px`; | |
| sineTriangle.style.width = `${Math.abs(radius * Math.cos(radians + Math.PI))}px`; | |
| sineTriangle.style.height = `${sinHeight}px`; | |
| sineTriangle.style.borderLeft = '1px dashed #8b5cf6'; | |
| } | |
| if (angle < 90 || angle > 270) { | |
| cosineTriangle.style.left = `${centerX}px`; | |
| cosineTriangle.style.top = `${centerY}px`; | |
| cosineTriangle.style.width = `${cosWidth}px`; | |
| cosineTriangle.style.height = `${sinHeight}px`; | |
| cosineTriangle.style.borderBottom = '1px dashed #8b5cf6'; | |
| } else { | |
| cosineTriangle.style.left = `${centerX}px`; | |
| cosineTriangle.style.top = `${centerY - sinHeight}px`; | |
| cosineTriangle.style.width = `${cosWidth}px`; | |
| cosineTriangle.style.height = `${sinHeight}px`; | |
| cosineTriangle.style.borderTop = '1px dashed #8b5cf6'; | |
| } | |
| // Update displayed values | |
| angleValue.textContent = angle; | |
| sinValue.textContent = Math.sin(radians).toFixed(3); | |
| cosValue.textContent = Math.cos(radians).toFixed(3); | |
| const tanVal = Math.tan(radians); | |
| if (Math.abs(tanVal) > 10) { | |
| tanValue.textContent = tanVal > 0 ? "∞" : "-∞"; | |
| } else { | |
| tanValue.textContent = tanVal.toFixed(3); | |
| } | |
| // Highlight current position on chart | |
| trigChart.options.scales.x.afterDraw = function(chart) { | |
| const ctx = chart.ctx; | |
| const xAxis = chart.scales.x; | |
| const yAxis = chart.scales.y; | |
| const xPos = xAxis.getPixelForValue(angle); | |
| ctx.save(); | |
| ctx.beginPath(); | |
| ctx.moveTo(xPos, yAxis.top); | |
| ctx.lineTo(xPos, yAxis.bottom); | |
| ctx.strokeStyle = 'rgba(0, 0, 0, 0.1)'; | |
| ctx.lineWidth = 1; | |
| ctx.stroke(); | |
| // Highlight point on sine curve | |
| const sinPoint = yAxis.getPixelForValue(Math.sin(radians)); | |
| ctx.beginPath(); | |
| ctx.arc(xPos, sinPoint, 4, 0, 2 * Math.PI); | |
| ctx.fillStyle = '#3b82f6'; | |
| ctx.fill(); | |
| // Highlight point on cosine curve | |
| const cosPoint = yAxis.getPixelForValue(Math.cos(radians)); | |
| ctx.beginPath(); | |
| ctx.arc(xPos, cosPoint, 4, 0, 2 * Math.PI); | |
| ctx.fillStyle = '#10b981'; | |
| ctx.fill(); | |
| // Highlight point on tangent curve (if visible) | |
| if (Math.abs(tanVal) <= 2) { | |
| const tanPoint = yAxis.getPixelForValue(tanVal); | |
| ctx.beginPath(); | |
| ctx.arc(xPos, tanPoint, 4, 0, 2 * Math.PI); | |
| ctx.fillStyle = '#8b5cf6'; | |
| ctx.fill(); | |
| } | |
| ctx.restore(); | |
| }; | |
| trigChart.update(); | |
| } | |
| // Event listeners | |
| increaseAngle.addEventListener('click', function() { | |
| currentAngle = (currentAngle + 5) % 360; | |
| angleSlider.value = currentAngle; | |
| updateUnitCircle(currentAngle); | |
| }); | |
| decreaseAngle.addEventListener('click', function() { | |
| currentAngle = (currentAngle - 5 + 360) % 360; | |
| angleSlider.value = currentAngle; | |
| updateUnitCircle(currentAngle); | |
| }); | |
| angleSlider.addEventListener('input', function() { | |
| currentAngle = parseInt(this.value); | |
| updateUnitCircle(currentAngle); | |
| }); | |
| // Highlight function explanations | |
| sinBtn.addEventListener('click', function() { | |
| this.classList.add('highlight'); | |
| setTimeout(() => this.classList.remove('highlight'), 1000); | |
| // Add visual explanation for sine | |
| const oldLeft = cosineTriangle.style.left; | |
| const oldTop = cosineTriangle.style.top; | |
| if (currentAngle > 180) { | |
| sineTriangle.style.left = `${150 - 120 * Math.abs(Math.cos(currentAngle * Math.PI / 180))}px`; | |
| } | |
| sineTriangle.style.top = `${150 - 120 * Math.sin(currentAngle * Math.PI / 180)}px`; | |
| setTimeout(() => { | |
| sineTriangle.style.left = oldLeft; | |
| sineTriangle.style.top = oldTop; | |
| }, 1000); | |
| }); | |
| cosBtn.addEventListener('click', function() { | |
| this.classList.add('highlight'); | |
| setTimeout(() => this.classList.remove('highlight'), 1000); | |
| // Add visual explanation for cosine | |
| const oldLeft = cosineTriangle.style.left; | |
| const oldTop = cosineTriangle.style.top; | |
| cosineTriangle.style.left = `${150 + 120 * Math.cos(currentAngle * Math.PI / 180)}px`; | |
| cosineTriangle.style.top = `${150 - 120 * Math.sin(currentAngle * Math.PI / 180)}px`; | |
| setTimeout(() => { | |
| cosineTriangle.style.left = oldLeft; | |
| cosineTriangle.style.top = oldTop; | |
| }, 1000); | |
| }); | |
| tanBtn.addEventListener('click', function() { | |
| this.classList.add('highlight'); | |
| setTimeout(() => this.classList.remove('highlight'), 1000); | |
| // Add visual explanation for tangent | |
| const oldBorder = sineTriangle.style.borderBottom; | |
| sineTriangle.style.borderBottom = '2px solid #8b5cf6'; | |
| setTimeout(() => { | |
| sineTriangle.style.borderBottom = oldBorder; | |
| }, 1000); | |
| }); | |
| // Initialize | |
| document.addEventListener('DOMContentLoaded', function() { | |
| initializeChart(); | |
| updateUnitCircle(currentAngle); | |
| }); | |
| </script> | |
| <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=onlyoneritz/visual-trigonometry" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> | |
| </html> |