cleaned up code; added some more comments
This commit is contained in:
3 files changed
+12
-31
No files matched your search
+10
-16
@@ -8,25 +8,23 @@ let rsInput = document.getElementById("rs");
|
|||||||
let npInput = document.getElementById("np");
|
let npInput = document.getElementById("np");
|
||||||
let outputdiv = document.getElementById("output");
|
let outputdiv = document.getElementById("output");
|
||||||
let stepInput = document.getElementById("steps");
|
let stepInput = document.getElementById("steps");
|
||||||
let lenOutput = document.getElementById("len");
|
|
||||||
let paperInput = document.getElementById("p");
|
let paperInput = document.getElementById("p");
|
||||||
|
|
||||||
|
// parameters
|
||||||
let height = 0;
|
let height = 0;
|
||||||
let radius = 0;
|
let radius = 0;
|
||||||
let spillRadius = 0;
|
let spillRadius = 0;
|
||||||
let numberOfPanels = 0;
|
let numberOfPanels = 0;
|
||||||
|
|
||||||
let multiplier = 1;
|
|
||||||
|
|
||||||
let 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;
|
||||||
|
|
||||||
|
// temporary data
|
||||||
let pointsP = [];
|
let pointsP = [];
|
||||||
let pointsQ = [];
|
let pointsQ = [];
|
||||||
let distances = [];
|
let distances = [];
|
||||||
|
|
||||||
let panelPoints = [];
|
let panelPoints = [];
|
||||||
|
|
||||||
|
// print data
|
||||||
let panelPaths = [];
|
let panelPaths = [];
|
||||||
let svgSize = { width: 0, height: 0 };
|
let svgSize = { width: 0, height: 0 };
|
||||||
let scaleFactor = 1;
|
let scaleFactor = 1;
|
||||||
@@ -34,7 +32,6 @@ let paperSize = "a3";
|
|||||||
|
|
||||||
let n = 0;
|
let n = 0;
|
||||||
let unit = "px";
|
let unit = "px";
|
||||||
let strokeWidth = 1;
|
|
||||||
|
|
||||||
// logic
|
// logic
|
||||||
function getValues() {
|
function getValues() {
|
||||||
@@ -42,22 +39,22 @@ function getValues() {
|
|||||||
pointsQ = [];
|
pointsQ = [];
|
||||||
distances = [];
|
distances = [];
|
||||||
panelPoints = [];
|
panelPoints = [];
|
||||||
height = /* /* Math.floor */(parseFloat(hInput.value) * multiplier);
|
height = (parseFloat(hInput.value) * multiplier);
|
||||||
radius = /* Math.floor */(parseFloat(rInput.value) * multiplier);
|
radius = (parseFloat(rInput.value) * multiplier);
|
||||||
spillRadius = /* Math.floor */(parseFloat(rsInput.value) * multiplier);
|
spillRadius = (parseFloat(rsInput.value) * multiplier);
|
||||||
numberOfPanels = /* Math.floor */(parseFloat(npInput.value) * multiplier);
|
numberOfPanels = (parseFloat(npInput.value) * multiplier);
|
||||||
step = radius / parseInt(stepInput.value);
|
step = radius / parseInt(stepInput.value);
|
||||||
paperSize = paperInput.value;
|
paperSize = paperInput.value;
|
||||||
if (isNaN(spillRadius)) {
|
if (isNaN(spillRadius)) {
|
||||||
spillRadius = /* Math.floor */(0.05 * radius);
|
spillRadius = (0.05 * radius);
|
||||||
rsInput.value = 0.05 * radius / multiplier;
|
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() {
|
function getPoints() {
|
||||||
for (let x = spillRadius; x < radius; x += step - offset) {
|
for (let x = spillRadius; x < radius; x += step - offset) {
|
||||||
|
// round x to reduce oppourtunity for a NaN to occur from accuracy
|
||||||
x = maths.approx(x);
|
x = maths.approx(x);
|
||||||
pointsP.push({
|
pointsP.push({
|
||||||
x: x,
|
x: x,
|
||||||
@@ -68,7 +65,6 @@ function getPoints() {
|
|||||||
|
|
||||||
function getPointsOfTangentIntersection() {
|
function getPointsOfTangentIntersection() {
|
||||||
for (let i = 0; i < n; i++) {
|
for (let i = 0; i < n; i++) {
|
||||||
console.log(`${i}, ${pointsP[i].x} ${pointsP[i].y}, ${pointsP[i + 1].x} ${pointsP[i+1].y}`);
|
|
||||||
pointsQ.push({
|
pointsQ.push({
|
||||||
x: maths.j(pointsP[i], pointsP[i + 1], height, radius),
|
x: maths.j(pointsP[i], pointsP[i + 1], height, radius),
|
||||||
y: maths.g(maths.j(pointsP[i], pointsP[i + 1], height, radius), pointsP[i + 1], height, radius)
|
y: maths.g(maths.j(pointsP[i], pointsP[i + 1], height, radius), pointsP[i + 1], height, radius)
|
||||||
@@ -108,7 +104,6 @@ function createPerimeterPath(maxY) {
|
|||||||
path +=`${maths.approx(point.x)},${maths.approx((point.y + maxY))} `;
|
path +=`${maths.approx(point.x)},${maths.approx((point.y + maxY))} `;
|
||||||
}
|
}
|
||||||
path += `${maths.approx(panelPoints[0].x)},${maths.approx((maxY) - panelPoints[0].y)}`;
|
path += `${maths.approx(panelPoints[0].x)},${maths.approx((maxY) - panelPoints[0].y)}`;
|
||||||
console.log(path);
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,7 +153,6 @@ function plotSVG() {
|
|||||||
/>
|
/>
|
||||||
</g>
|
</g>
|
||||||
</svg>`;
|
</svg>`;
|
||||||
lenOutput.innerText = `Recommended length: ${maths.approx(maxX - minX)} ${unit}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function calculateScaleFactor(unit) {
|
function calculateScaleFactor(unit) {
|
||||||
|
|||||||
+2
-6
@@ -1,6 +1,7 @@
|
|||||||
import { sanitiseArguments } from "./utils";
|
import { sanitiseArguments } from "./utils";
|
||||||
|
|
||||||
let accuracy = import.meta.env.VITE_ACCURACY;
|
// decimal places
|
||||||
|
let accuracy = 8;
|
||||||
|
|
||||||
export function approx(n) {
|
export function approx(n) {
|
||||||
return Math.round(n * (10 ** accuracy)) / (10 ** accuracy);
|
return Math.round(n * (10 ** accuracy)) / (10 ** accuracy);
|
||||||
@@ -13,7 +14,6 @@ export function approx(n) {
|
|||||||
export function f(x, h, r) {
|
export function f(x, h, r) {
|
||||||
sanitiseArguments(x,h,r)
|
sanitiseArguments(x,h,r)
|
||||||
let res = approx(h * Math.sqrt((1 - (Math.pow(x, 2) / Math.pow(r, 2)))));
|
let res = approx(h * Math.sqrt((1 - (Math.pow(x, 2) / Math.pow(r, 2)))));
|
||||||
console.log(`f(${x} ${h} ${r}) ${res}`);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,7 +24,6 @@ export function f(x, h, r) {
|
|||||||
export function fprime(x, h, r) {
|
export function fprime(x, h, r) {
|
||||||
sanitiseArguments(x,h,r)
|
sanitiseArguments(x,h,r)
|
||||||
let res = approx(-1 * ((Math.pow(h, 2) * x) / (Math.pow(r, 2) * f(x, h, r))));
|
let res = approx(-1 * ((Math.pow(h, 2) * x) / (Math.pow(r, 2) * f(x, h, r))));
|
||||||
console.log(`fprime (${x} ${h} ${r}) ${res}`);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +35,6 @@ export function fprime(x, h, r) {
|
|||||||
export function g(x, P, h, r) {
|
export function g(x, P, h, r) {
|
||||||
sanitiseArguments(x,P.x, P.y,h,r)
|
sanitiseArguments(x,P.x, P.y,h,r)
|
||||||
let res = approx(fprime(x, h, r) * (x - P.x) + P.y);
|
let res = approx(fprime(x, h, r) * (x - P.x) + P.y);
|
||||||
console.log(`g (${x} {${P.x} ${P.y}} ${h} ${r}) ${res}`);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,7 +46,6 @@ export function g(x, P, h, r) {
|
|||||||
export function j(A, B, h, r) {
|
export function j(A, B, h, r) {
|
||||||
sanitiseArguments(A.x, A.y, B.x, B.y, h,r)
|
sanitiseArguments(A.x, A.y, B.x, B.y, h,r)
|
||||||
let res = approx(A.x * fprime(A.x, h, r) - B.x * fprime(B.x, h, r) - A.y + B.y) / (fprime(A.x, h, r) - fprime(B.x, h, r));
|
let res = approx(A.x * fprime(A.x, h, r) - B.x * fprime(B.x, h, r) - A.y + B.y) / (fprime(A.x, h, r) - fprime(B.x, h, r));
|
||||||
console.log(`j ({${A.x} ${A.y}} {${B.x} ${B.y}} ${h} ${r}) ${res}`);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,6 +55,5 @@ export function j(A, B, h, r) {
|
|||||||
export function d(A, B) {
|
export function d(A, B) {
|
||||||
sanitiseArguments(A.x, A.y, B.x, B.y)
|
sanitiseArguments(A.x, A.y, B.x, B.y)
|
||||||
let res = approx(Math.sqrt(Math.pow(A.x - B.x, 2) + Math.pow(A.y - B.y, 2)));
|
let 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;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -6,8 +6,6 @@ export async function createPdf(paths, svgSize, scaleFactor, paperSize) {
|
|||||||
// calculate number of pages needed
|
// calculate number of pages needed
|
||||||
|
|
||||||
const margins = { x: 15, y: 15 };
|
const margins = { x: 15, y: 15 };
|
||||||
console.log(svgSize);
|
|
||||||
console.log(`Scale factor ${scaleFactor}`);
|
|
||||||
|
|
||||||
// paper sizes in pt
|
// paper sizes in pt
|
||||||
let sizes = {
|
let sizes = {
|
||||||
@@ -22,7 +20,6 @@ export async function createPdf(paths, svgSize, scaleFactor, paperSize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let nPages = Math.ceil((svgSize.width *scaleFactor) / sizes[paperSize].y);
|
let nPages = Math.ceil((svgSize.width *scaleFactor) / sizes[paperSize].y);
|
||||||
console.log(`${svgSize.width} * ${scaleFactor} / ${sizes[paperSize].y} = ${((svgSize.width *scaleFactor) / sizes[paperSize].y)}`);
|
|
||||||
let needsMarkers = false;
|
let needsMarkers = false;
|
||||||
if (1 < nPages) {
|
if (1 < nPages) {
|
||||||
needsMarkers = true;
|
needsMarkers = true;
|
||||||
@@ -48,12 +45,6 @@ export async function createPdf(paths, svgSize, scaleFactor, paperSize) {
|
|||||||
scale: scaleFactor
|
scale: scaleFactor
|
||||||
};
|
};
|
||||||
|
|
||||||
// centre line
|
|
||||||
// page.drawLine({
|
|
||||||
// start: { x: width/2, y: height },
|
|
||||||
// end: { x: width/2, y: 0 },
|
|
||||||
// });
|
|
||||||
|
|
||||||
page.moveTo(5, height - 5);
|
page.moveTo(5, height - 5);
|
||||||
// panel
|
// panel
|
||||||
page.drawSvgPath(paths[0], svgSettings);
|
page.drawSvgPath(paths[0], svgSettings);
|
||||||
|
|||||||
Reference in new issue
Block a user