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 27 additions and 48 deletions

No files matched your search

BIN
View File
Binary file not shown.
-2
View File
@@ -27,8 +27,6 @@
<input type="number" id="rs" /><br> <input type="number" id="rs" /><br>
<label for="np">Number of panels (n<sub>p</sub>): </label> <label for="np">Number of panels (n<sub>p</sub>): </label>
<input type="number" id="np" min="3" ><br> <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> <p id="len"></p>
<div id="output" style="display: none;"></div> <div id="output" style="display: none;"></div>
+1 -1
View File
@@ -12,7 +12,7 @@
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "vite build", "build": "vite build; tar -cavf build.tar.gz dist",
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"dependencies": { "dependencies": {
+16 -22
View File
@@ -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 step = 0.001;
const offset = 4 * 10 ** -5;
let multiplier = 1; // temporary data
let step = 0.001 * multiplier;
// const offset = 3*10**-15 * multiplier;
const offset = 4 * 10 ** -5 * multiplier;
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) * 1);
radius = /* Math.floor */(parseFloat(rInput.value) * multiplier); radius = (parseFloat(rInput.value) * 1);
spillRadius = /* Math.floor */(parseFloat(rsInput.value) * multiplier); spillRadius = (parseFloat(rsInput.value) * 1);
numberOfPanels = /* Math.floor */(parseFloat(npInput.value) * multiplier); numberOfPanels = (parseFloat(npInput.value) * 1);
step = radius / parseInt(stepInput.value); step = radius / 1000;
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 ;
} }
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;
} }
@@ -148,17 +143,16 @@ function plotSVG() {
d="${panelPaths[0]}" d="${panelPaths[0]}"
fill="none" fill="none"
stroke="black" stroke="black"
stroke-width="${strokeWidth}" stroke-width="1"
/> />
<path <path
d="${panelPaths[1]}" d="${panelPaths[1]}"
fill="none" fill="none"
stroke="black" stroke="black"
stroke-width="${strokeWidth}" stroke-width="1"
/> />
</g> </g>
</svg>`; </svg>`;
lenOutput.innerText = `Recommended length: ${maths.approx(maxX - minX)} ${unit}`;
} }
function calculateScaleFactor(unit) { function calculateScaleFactor(unit) {
+2 -6
View File
@@ -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;
} }
+8 -17
View File
@@ -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,25 +45,11 @@ 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);
page.drawSvgPath(paths[1], 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 // draw top alignmnet marker
if (i != 0 && needsMarkers) { if (i != 0 && needsMarkers) {
page.drawLine({ page.drawLine({
@@ -82,6 +65,14 @@ export async function createPdf(paths, svgSize, scaleFactor, paperSize) {
end: { x: width, y: 2 * margins.y }, 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 }); const pdfDataUri = await pdfDocument.saveAsBase64({ dataUri: true });