Compare commits

..
3 Commits
Author SHA1 Message Date
chopster44 da7e9f6a95 found more bugs 2026-10-03 20:27:04 +01:00
chopster44 0b776a631c forgot to fix some things 2026-10-03 20:02:17 +01:00
chopster44 17c91429f4 cleaned up code; added some more comments 2026-10-03 19:59:12 +01:00
6 changed files with 28 additions and 49 deletions

No files matched your search

BIN
View File
Binary file not shown.
+1 -3
View File
@@ -27,9 +27,7 @@
<input type="number" id="rs" /><br>
<label for="np">Number of panels (n<sub>p</sub>): </label>
<input type="number" id="np" min="3" ><br>
<label for="steps">Number of steps: </label>
<input type="number" id="steps" min="10" /><br>
<button id="generate">Generate!</button>
<button id="generate" >Generate!</button>
<p id="len"></p>
<div id="output" style="display: none;"></div>
<iframe id="pdf" style="width:100%;height:1000px"></iframe>
+1 -1
View File
@@ -12,7 +12,7 @@
"main": "index.js",
"scripts": {
"dev": "vite",
"build": "vite build",
"build": "vite build; tar -cavf build.tar.gz dist",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
+16 -22
View File
@@ -8,25 +8,23 @@ 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 paperInput = document.getElementById("p");
// parameters
let height = 0;
let radius = 0;
let spillRadius = 0;
let numberOfPanels = 0;
let step = 0.001;
const offset = 4 * 10 ** -5;
let multiplier = 1;
let step = 0.001 * multiplier;
// const offset = 3*10**-15 * multiplier;
const offset = 4 * 10 ** -5 * multiplier;
// temporary data
let pointsP = [];
let pointsQ = [];
let distances = [];
let panelPoints = [];
// print data
let panelPaths = [];
let svgSize = { width: 0, height: 0 };
let scaleFactor = 1;
@@ -34,7 +32,6 @@ let paperSize = "a3";
let n = 0;
let unit = "px";
let strokeWidth = 1;
// logic
function getValues() {
@@ -42,22 +39,22 @@ 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);
step = radius / parseInt(stepInput.value);
height = (parseFloat(hInput.value) * 1);
radius = (parseFloat(rInput.value) * 1);
spillRadius = (parseFloat(rsInput.value) * 1);
numberOfPanels = (parseFloat(npInput.value) * 1);
step = radius / 1000;
paperSize = paperInput.value;
if (isNaN(spillRadius)) {
spillRadius = /* Math.floor */(0.05 * radius);
rsInput.value = 0.05 * radius / multiplier;
spillRadius = (0.05 * radius);
rsInput.value = 0.05 * radius ;
}
n = ((radius - spillRadius) / (step - offset)) - 1;
console.log(`${height}, ${radius}, ${spillRadius}, ${step}, ${offset}`);
}
function getPoints() {
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);
pointsP.push({
x: x,
@@ -68,7 +65,6 @@ function getPoints() {
function getPointsOfTangentIntersection() {
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({
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)
@@ -108,7 +104,6 @@ function createPerimeterPath(maxY) {
path +=`${maths.approx(point.x)},${maths.approx((point.y + maxY))} `;
}
path += `${maths.approx(panelPoints[0].x)},${maths.approx((maxY) - panelPoints[0].y)}`;
console.log(path);
return path;
}
@@ -148,17 +143,16 @@ function plotSVG() {
d="${panelPaths[0]}"
fill="none"
stroke="black"
stroke-width="${strokeWidth}"
stroke-width="1"
/>
<path
d="${panelPaths[1]}"
fill="none"
stroke="black"
stroke-width="${strokeWidth}"
stroke-width="1"
/>
</g>
</svg>`;
lenOutput.innerText = `Recommended length: ${maths.approx(maxX - minX)} ${unit}`;
}
function calculateScaleFactor(unit) {
+2 -6
View File
@@ -1,6 +1,7 @@
import { sanitiseArguments } from "./utils";
let accuracy = import.meta.env.VITE_ACCURACY;
// decimal places
let accuracy = 8;
export function approx(n) {
return Math.round(n * (10 ** accuracy)) / (10 ** accuracy);
@@ -13,7 +14,6 @@ export function approx(n) {
export function f(x, h, r) {
sanitiseArguments(x,h,r)
let res = approx(h * Math.sqrt((1 - (Math.pow(x, 2) / Math.pow(r, 2)))));
console.log(`f(${x} ${h} ${r}) ${res}`);
return res;
}
@@ -24,7 +24,6 @@ export function f(x, h, r) {
export function fprime(x, h, r) {
sanitiseArguments(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;
}
@@ -36,7 +35,6 @@ export function fprime(x, h, r) {
export function g(x, P, h, r) {
sanitiseArguments(x,P.x, P.y,h,r)
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;
}
@@ -48,7 +46,6 @@ export function g(x, P, h, r) {
export function j(A, B, 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));
console.log(`j ({${A.x} ${A.y}} {${B.x} ${B.y}} ${h} ${r}) ${res}`);
return res;
}
@@ -58,6 +55,5 @@ export function j(A, B, h, r) {
export function d(A, B) {
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)));
console.log(`d ({${A.x} ${A.y}} {${B.x} ${B.y}}) ${res}`);
return res;
}
+8 -17
View File
@@ -6,8 +6,6 @@ export async function createPdf(paths, svgSize, scaleFactor, paperSize) {
// calculate number of pages needed
const margins = { x: 15, y: 15 };
console.log(svgSize);
console.log(`Scale factor ${scaleFactor}`);
// paper sizes in pt
let sizes = {
@@ -22,7 +20,6 @@ export async function createPdf(paths, svgSize, scaleFactor, paperSize) {
}
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;
if (1 < nPages) {
needsMarkers = true;
@@ -48,25 +45,11 @@ export async function createPdf(paths, svgSize, scaleFactor, paperSize) {
scale: scaleFactor
};
// centre line
// page.drawLine({
// start: { x: width/2, y: height },
// end: { x: width/2, y: 0 },
// });
page.moveTo(5, height - 5);
// panel
page.drawSvgPath(paths[0], svgSettings);
page.drawSvgPath(paths[1], svgSettings);
// margins
page.drawSvgPath(`M ${margins.x/2},${margins.y/2} ${margins.x/2},${height-margins.y/2} ${width-margins.x/2},${height-margins.y/2} ${width-margins.x/2},${margins.y/2} ${margins.x/2},${margins.y/2} Z`, {
x:0,
y:height,
borderColor: rgb(1,1,1),
borderWidth: margins.x
});
// draw top alignmnet marker
if (i != 0 && needsMarkers) {
page.drawLine({
@@ -82,6 +65,14 @@ export async function createPdf(paths, svgSize, scaleFactor, paperSize) {
end: { x: width, y: 2 * margins.y },
});
}
// margins
page.drawSvgPath(`M ${margins.x/2},${margins.y/2} ${margins.x/2},${height-margins.y/2} ${width-margins.x/2},${height-margins.y/2} ${width-margins.x/2},${margins.y/2} ${margins.x/2},${margins.y/2} Z`, {
x:0,
y:height,
borderColor: rgb(1,1,1),
borderWidth: margins.x
});
}
const pdfDataUri = await pdfDocument.saveAsBase64({ dataUri: true });