parseFloat(document.getElementById("wing_span").value); root_chord = parseFloat(document.getElementById("root_chord").value); tip_chord = parseFloat(document.getElementById("tip_chord").value); sweep_type = document.getElementById("sweep_type").selectedIndex; if (sweep_type == 0) { sweep_dist = parseFloat(document.getElementById("sweep").value); sweep_ang = sweep_to_degrees(sweep_dist); } else { sweep_ang = parseFloat(document.getElementById("sweep").value); sweep_dist = sweep_to_distance(sweep_ang); } if (document.getElementById("cg_preset_15").checked) cg_pos = 15; else if (document.getElementById("cg_preset_20").checked) cg_pos = 20; else if (document.getElementById("cg_preset_25").checked) cg_pos = 25; else cg_pos = parseFloat(document.getElementById("cg_pos").value); show_mac_lines = document.getElementById("show_mac_lines").checked; var err_str = ""; if (wing_span.toString() == "NaN") err_str += "\tWing span is invalid\n"; if (root_chord.toString() == "NaN") err_str += "\tRoot chord is invalid\n"; if (tip_chord.toString() == "NaN") err_str += "\tTip chord is invalid\n"; if (sweep_dist.toString() == "NaN" || sweep_dist < 0 || sweep_ang.toString() == "NaN" || sweep_ang > 89) err_str += "\tSweep is invalid\n"; if (cg_pos.toString() == "NaN") err_str += "\tCG position is invalid\n"; if (err_str != "") err_str = "Error reading input values:\n" + err_str + "\nPlease correct and re-calculate."; return err_str;}function sweep_type_changed(){ sweep_type = document.getElementById("sweep_type").selectedIndex; if (sweep_type == 0) { var sweep = parseFloat(document.getElementById("sweep").value); if (sweep.toString() != "NaN") document.getElementById("sweep").value = Math.round(sweep_to_distance(sweep) * 100) / 100; } else { var sweep = parseFloat(document.getElementById("sweep").value); if (sweep.toString() != "NaN") document.getElementById("sweep").value = Math.round(sweep_to_degrees(sweep) * 100) / 100; }}function compute(){ // Compute wing area wing_area = (root_chord + tip_chord) * wing_span * 0.5; // Find LE and TE line formula var le_b = 0; var le_a = (sweep_dist - le_b) / (wing_span * 0.5); var te_b = root_chord; var te_a = ((sweep_dist + tip_chord) - te_b) / (wing_span * 0.5); // Find helper line formula var mac_b0 = -tip_chord; var mac_a0 = ((sweep_dist + tip_chord + root_chord) - mac_b0) / (wing_span * 0.5); var mac_b1 = root_chord + tip_chord; var mac_a1 = ((sweep_dist - root_chord) - mac_b1) / (wing_span * 0.5); // Determine MAC using intersection of helper lines mac_x = (mac_b1 - mac_b0) / (mac_a0 - mac_a1); // Compute MAC intersection with LE and TE le_mac_y = le_a * mac_x + le_b; te_mac_y = te_a * mac_x + te_b; // Compute CG cg_dist = le_mac_y + (te_mac_y - le_mac_y) * cg_pos / 100; // Find canvas dimensions width = wing_span; if (show_mac_lines) height = sweep_dist + tip_chord + root_chord + tip_chord; else height = sweep_dist + tip_chord; if (root_chord > height) height = root_chord; // Compute canvas size and scale if (width > height) { canvas_width = canvas_max_width; zoom = (canvas_width - border_size * 2) / width; canvas_height = Math.round(height * zoom) + border_size * 2; } else { canvas_height = canvas_max_height; zoom = (canvas_height - border_size * 2) / height; canvas_width = Math.round(height * zoom) + border_size * 2; } if (!show_mac_lines) canvas_height += 20;}function canvas_begin(){ canvas.setAttribute("width", canvas_width); canvas.setAttribute("height", canvas_height); context.strokeStyle="#000000"; context.strokeRect(0, 0, canvas_width, canvas_height); context.save(); if (show_mac_lines) context.translate(canvas_width / 2, border_size + zoom * tip_chord); else context.translate(canvas_width / 2, border_size + 20);}function canvas_end(){ context.restore();}function paint_wing_bg(){ context.beginPath(); context.fillStyle="#f0f0f0"; context.moveTo(0, 0); context.lineTo(zoom * wing_span / 2, zoom * sweep_dist); context.lineTo(zoom * wing_span / 2, zoom * (sweep_dist + tip_chord)); context.lineTo(0, zoom * root_chord); context.lineTo(zoom * wing_span / -2, zoom * (sweep_dist + tip_chord)); context.lineTo(zoom * wing_span / -2, zoom * sweep_dist); context.closePath(); context.fill();}function paint_wing_outline(){ context.beginPath(); context.lineWidth = 2.0; context.moveTo(0, 0); context.lineTo(zoom * wing_span / 2, zoom * sweep_dist);