diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..30cf57e --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/Parachute-SVG-Generator.iml b/.idea/Parachute-SVG-Generator.iml new file mode 100644 index 0000000..c956989 --- /dev/null +++ b/.idea/Parachute-SVG-Generator.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..792a9e2 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/index.html b/index.html index 11b885a..651a966 100644 --- a/index.html +++ b/index.html @@ -7,15 +7,25 @@

Parachute Panel Generator

Generate the SVG outline of a parachute panel for an elliptical parachute. Find out more here.


+ +


- +

+ +
+

diff --git a/index.js b/index.js index 59496df..c0105f2 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,11 @@ +let uInput = document.getElementById("u"); let hInput = document.getElementById("h"); let rInput = document.getElementById("r"); let rsInput = document.getElementById("rs"); let npInput = document.getElementById("np"); let outputdiv = document.getElementById("output"); +let stepInput = document.getElementById("steps"); +let lenOutput = document.getElementById("len"); let height = 0; let radius = 0; @@ -12,9 +15,9 @@ let numberOfPanels = 0; let multiplier = 1; let accuracy = 8; -const step = 0.001 * multiplier; +let step = 0.001 * multiplier; // const offset = 3*10**-15 * multiplier; -const offset = 4*10**-5 * multiplier; +const offset = 4 * 10 ** -5 * multiplier; let pointsP = []; let pointsQ = []; @@ -23,38 +26,40 @@ let distances = []; let panelPoints = []; let n = 0; +let unit = "px"; +let strokeWidth = 1; // maths -function approx(x) { - return Math.round(x*(10**accuracy))/(10**accuracy); +function approx(n) { + return Math.round(n * (10 ** accuracy)) / (10 ** accuracy); } function f(x) { - res = approx(height * Math.sqrt((1-(Math.pow(x,2)/Math.pow(radius,2))))); + res = approx(height * Math.sqrt((1 - (Math.pow(x, 2) / Math.pow(radius, 2))))); console.log(`f ${x} ${res}`); return res; } function fprime(x) { - res = approx(-1*((Math.pow(height,2)*x)/(Math.pow(radius,2)*f(x)))); + res = approx(-1 * ((Math.pow(height, 2) * x) / (Math.pow(radius, 2) * f(x)))); console.log(`fprime ${x} ${res}`); return res; } function g(x, P) { - res = approx(fprime(x)*(x-P.x)+P.y); + res = approx(fprime(x) * (x - P.x) + P.y); console.log(`g ${x} ${P.x} ${P.y} ${res}`); return res; } function j(A, B) { - res = approx(A.x*fprime(A.x)-B.x*fprime(B.x)-A.y+B.y)/(fprime(A.x)-fprime(B.x)); + res = approx(A.x * fprime(A.x) - B.x * fprime(B.x) - A.y + B.y) / (fprime(A.x) - fprime(B.x)); console.log(`j ${A.x} ${A.y} ${B.x} ${B.y} ${res}`); return res; } function d(A, B) { - res = approx(Math.sqrt(Math.pow(A.x-B.x,2)+Math.pow(A.y-B.y,2))); + res = approx(Math.sqrt(Math.pow(A.x - B.x, 2) + Math.pow(A.y - B.y, 2))); console.log(`d ${A.x} ${A.y} ${B.x} ${B.y} ${res}`); return res; } @@ -65,23 +70,24 @@ function getValues() { pointsQ = []; distances = []; panelPoints = []; - height = /* /* Math.floor */(parseFloat(hInput.value) *multiplier); - radius = /* Math.floor */(parseFloat(rInput.value) *multiplier); - spillRadius = /* Math.floor */(parseFloat(rsInput.value) *multiplier); - numberOfPanels = /* Math.floor */(parseFloat(npInput.value) *multiplier); + height = /* /* Math.floor */(parseFloat(hInput.value) * multiplier); + radius = /* Math.floor */(parseFloat(rInput.value) * multiplier); + spillRadius = /* Math.floor */(parseFloat(rsInput.value) * multiplier); + numberOfPanels = /* Math.floor */(parseFloat(npInput.value) * multiplier); + step = radius / parseInt(stepInput.value); if (isNaN(spillRadius)) { - spillRadius = /* Math.floor */(0.05*radius); - rsInput.value = 0.05*radius /multiplier; + spillRadius = /* Math.floor */(0.05 * radius); + rsInput.value = 0.05 * radius / multiplier; } - n = ((radius-spillRadius)/(step-offset))-1; + n = ((radius - spillRadius) / (step - offset)) - 1; console.log(`${height}, ${radius}, ${spillRadius}, ${step}, ${offset}`); } function getPoints() { - for (let x = spillRadius; x < radius; x+=step-offset) { - x=approx(x); + for (let x = spillRadius; x < radius; x += step - offset) { + x = approx(x); pointsP.push({ - x: x, + x: x, y: f(x) }); } @@ -89,25 +95,25 @@ function getPoints() { function getPointsOfTangentIntersection() { for (let i = 0; i < n; i++) { - console.log(`${i}, ${pointsP[i]}, ${pointsP[i+1]}`); + console.log(`${i}, ${pointsP[i]}, ${pointsP[i + 1]}`); pointsQ.push({ - x: j(pointsP[i], pointsP[i+1]), - y: g(j(pointsP[i], pointsP[i+1]), pointsP[i+1]) + x: j(pointsP[i], pointsP[i + 1]), + y: g(j(pointsP[i], pointsP[i + 1]), pointsP[i + 1]) }); } } function getDistancesBetweenIntersections() { - for (let i = 0; i < n-1; i++) { - distances.push(d(pointsQ[i], pointsQ[i+1])); + for (let i = 0; i < n - 1; i++) { + distances.push(d(pointsQ[i], pointsQ[i + 1])); } } function generateCoordinates() { let Xi = 0; - for (let i = 0; i < n-2; i++) { - Xi+=distances[i]; - Yi=(Math.PI*pointsQ[i].x)/numberOfPanels; + for (let i = 0; i < n - 2; i++) { + Xi += distances[i]; + Yi = (Math.PI * pointsQ[i].x) / numberOfPanels; panelPoints.push({ x: Xi, y: Yi @@ -117,32 +123,80 @@ function generateCoordinates() { function plotSVG() { let maxY = 0; + let maxX = 0; + let minX = 1000; panelPoints.forEach((point) => { if (maxY < point.y) { - maxY=point.y + maxY = point.y; + } + if (minX > point.x) { + minX = point.x; + } + if (maxX < point.x) { + maxX = point.x; } }) - let pointsA = []; - let pointsB = []; - for(let i = 0; i < panelPoints.length; i++) { + let pointsA = ""; + let pointsB = ""; + for (let i = 0; i < panelPoints.length; i++) { let point = panelPoints[i]; - pointsA.push(`${approx(point.x*10)},${(maxY*10)-approx(point.y*10)}`) - pointsB.push(`${approx(point.x*10)},${approx((point.y+maxY)*10)}`); + pointsA += `${approx(point.x)},${(maxY) - approx(point.y)} `; + pointsB +=`${approx(point.x)},${approx((point.y + maxY))} `; } outputdiv.innerHTML = ` - - - - - - + + + + + + + + - ` + `; + lenOutput.innerText = `Recommended length: ${approx(maxX - minX)} ${unit}`; } // main func function generatePanel() { + unit=uInput.value; getValues(); getPoints(); getPointsOfTangentIntersection(); diff --git a/package.json b/package.json index 73109e6..1e02a41 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "url": "git@git.emaker.limited:chopster44/Parachute-SVG-Generator.git" }, "license": "SEE LICENSE IN LICENSE", - "author": "chopster44", + "author": "Oscar Giacalone", "type": "commonjs", "main": "index.js", "scripts": {