Thrust Power
// Function to calculate the power needed to push a boat function calculatePower(speed) { var beam = 3.358; // beam in meters var displacement = 5000; // displacement in kg var lwl = 8.84; // length of waterline in meters var rho = 1025; // density of seawater in kg/m^3 var C_D = 0.007; // drag coefficient var A = Math.pow(beam, 2) * lwl / 2; // cross-sectional area in m^2 return 0.5 * rho * Math.pow(speed, 2) * A * C_D; }
// Function to create the graph function createGraph() { var speedData = []; // array to store data for each speed var powerData = []; // array to store data for power
// Calculate the power for speeds from 0 to 4 m/s for (var i = 0; i <= 4; i += 0.1) { speedData.push(i); powerData.push(calculatePower(i)); } // Plot the graph using Plotly.js var trace = { x: speedData, y: powerData, type: 'scatter', mode: 'lines', line: { color: 'blue', width: 2 }, name: 'Power (kW)' }; var layout = { xaxis: { title: 'Speed (m/s)' }, yaxis: { title: 'Power (kW)' }, title: 'Power Needed to Push a Sailboat' }; Plotly.newPlot('graph', [trace], layout); } // Call the createGraph function when the page is loaded window.onload = createGraph;