diff --git a/.gitignore b/.gitignore index f3cb1b8..21a4059 100644 --- a/.gitignore +++ b/.gitignore @@ -21,5 +21,5 @@ _deps bin ignored -maths/*.pdf -maths/*.synctex.gz +maths/**/*.pdf +maths/**/*.synctex.gz diff --git a/.husky/scripts/cleanMaths.js b/.husky/scripts/cleanMaths.js index 8d1b4d6..99170a5 100644 --- a/.husky/scripts/cleanMaths.js +++ b/.husky/scripts/cleanMaths.js @@ -27,32 +27,47 @@ const cropBuffer = buffer => .catch(err => reject(err)); }); -fs.readdirSync(mathsDir).forEach(file => { - const [fileName, fileExtension] = file.split('.'); - const filePath = path.join(mathsDir, file); +const crawlDirectory = async dir => { + const dirents = fs.readdirSync(dir, { withFileTypes: true }); - if (file.endsWith('.pdf')) { - pdfToPng(filePath, { - viewportScale: 2 - }).then(async output => { - const pageCount = output.length; + const files = await Promise.all( + dirents.map(dirent => { + const res = path.resolve(dir, dirent.name); + return dirent.isDirectory() ? crawlDirectory(res) : res; + }) + ); - if (pageCount > 1) - output.forEach(async (page, i) => + return files.flat(); +}; + +(async () => { + const files = await crawlDirectory(mathsDir); + + files.forEach(file => { + const [filePath, fileDirectory, fileNameWithExt] = file.match(/(.*)\/((?:.(?!\/))+)$/); + const [fileName, fileExtension] = fileNameWithExt.split('.'); + + if (file.endsWith('.pdf')) { + pdfToPng(filePath).then(async output => { + const pageCount = output.length; + + if (pageCount > 1) + output.forEach(async (page, i) => + fs.writeFileSync( + path.join(fileDirectory, `${fileName}-${i + 1}.png`), + await cropBuffer(page.content) + ) + ); + else fs.writeFileSync( - path.join(mathsDir, `${fileName}-${i + 1}.png`), - await cropBuffer(page.content) - ) - ); - else - fs.writeFileSync( - path.join(mathsDir, `${fileName}.png`), - await cropBuffer(output[0].content) - ); - }); - } + path.join(fileDirectory, `${fileName}.png`), + await cropBuffer(output[0].content) + ); + }); + } - if (fileExtension !== 'tex' && fileExtension !== 'png' && fileExtension !== 'cls') { - fs.rmSync(filePath); - } -}); + if (fileExtension !== 'tex' && fileExtension !== 'png' && fileExtension !== 'cls') { + fs.rmSync(filePath); + } + }); +})(); diff --git a/.vscode/settings.json b/.vscode/settings.json index 5ea83c4..382ccc6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -36,5 +36,5 @@ }, "latex-workshop.latex.autoBuild.run": "onSave", "latex-workshop.latex.autoClean.run": "onBuilt", - "latex-workshop.latex.search.rootFiles.include": ["**/*.tex", "root.tex"] + "latex-workshop.cls" } diff --git a/languages/python/calculators/Trigometric Functions.py b/languages/python/calculators/Trigometric Functions.py index 0432e27..be9c8d8 100644 --- a/languages/python/calculators/Trigometric Functions.py +++ b/languages/python/calculators/Trigometric Functions.py @@ -1,19 +1,50 @@ -from cmath import e, sqrt +from cmath import e, sqrt, log from _helpers import floatInput i = sqrt(-1) compute = lambda numerator, denominator: (numerator / denominator).real +ln = lambda x: log(x, e) + sin = lambda x: compute(pow(e, i * x) - pow(e, -i * x), 2 * i) cos = lambda x: compute(pow(e, i * x) + pow(e, -i * x), 2) tan = lambda x: compute(pow(e, i * x) - pow(e, -i * x), i * (pow(e, i * x) + pow(e, -i * x))) +csc = lambda x: 1 / sin(x) +sec = lambda x: 1 / cos(x) +cot = lambda x: 1 / tan(x) + +arcsin = lambda x: (-i * ln((i * x) + sqrt(1 - pow(x, 2)))).real + +# todo: finish arc functions +arccos = lambda x: None +arctan = lambda x: None +arccsc = lambda x: None +arcsec = lambda x: None +arccot = lambda x: None + radians = floatInput("Please enter an amount of radians: ") print(f""" -sin({radians}) = {sin(radians)}) +Trigometric functions + +sin({radians}) = {sin(radians)} cos({radians}) = {cos(radians)} tan({radians}) = {tan(radians)} -csc({radians}) = {1 / sin(radians)} -sec({radians}) = {1 / cos(radians)} -cot({radians}) = {1 / tan(radians)}""") +Reciprocal trigometric functions + +csc({radians}) = {csc(radians)} +sec({radians}) = {sec(radians)} +cot({radians}) = {cot(radians)} + +Inverse trigometric functions + +arcsin({sin(radians)}) = {arcsin(sin(radians))} +arccos({cos(radians)}) = {arccos(cos(radians))} +arctan({tan(radians)}) = {arctan(tan(radians))} + +Inverse reciprocal trigometric functions + +arccsc({csc(radians)}) = {arccsc(csc(radians))} +arcsec({sec(radians)}) = {arcsec(sec(radians))} +arccot({cot(radians)}) = {arccot(cot(radians))}""") diff --git a/maths/nth root.png b/maths/nth root.png index 0834e5e..20e0269 100644 Binary files a/maths/nth root.png and b/maths/nth root.png differ diff --git a/maths/style.cls b/maths/style.cls index 93f0086..48621a0 100644 --- a/maths/style.cls +++ b/maths/style.cls @@ -1,3 +1,2 @@ -\ProvidesClass{style} \LoadClass[17pt]{extarticle} \pagenumbering{gobble} diff --git a/maths/trigometric functions/sin.png b/maths/trigometric functions/sin.png new file mode 100644 index 0000000..5b55106 Binary files /dev/null and b/maths/trigometric functions/sin.png differ diff --git a/maths/trigometric functions/sin.tex b/maths/trigometric functions/sin.tex new file mode 100644 index 0000000..d361a53 --- /dev/null +++ b/maths/trigometric functions/sin.tex @@ -0,0 +1,31 @@ +\documentclass{../style} +\usepackage{amsmath} +\usepackage{amssymb} +\begin{document} +\begin{gather*} + \text{By Euler's formula:} \\ + e^{i\theta} = cos(\theta) + i\sin(\theta) \\ + e^{-i\theta} = cos(\theta) - i\sin(\theta) +\end{gather*} + +\begin{gather*} + \therefore \sin(\theta) = \frac{e^{i\theta} - e^{-i\theta}}{2i} +\end{gather*} + +\begin{gather*} + \text{let} \quad \sin(\theta) = x \\ + 2ix = e^{i\theta} - e^{-i\theta} \\ + 2ie^{i\theta}x = (e^{i\theta})^2 - 1 \\ + (e^{i\theta})^2 + (-2ix)e^{i\theta} - 1 = 0 +\end{gather*} + +\begin{gather*} + e^{i\theta} = \frac{-(-2ix) \pm \sqrt{(-2ix)^2 - 4(1)(-1)}}{2} = ix \pm \sqrt{1 - x^2} \\ + i\theta = \ln(ix \pm \sqrt{1 - x^2}) \\ + \theta = -i\ln(ix \pm \sqrt{1 - x^2}) +\end{gather*} + +\begin{gather*} + \therefore \arcsin(\theta) = -i\ln(i\theta \pm \sqrt{1 -\theta^2}) +\end{gather*} +\end{document} diff --git a/package.json b/package.json index 11abe50..e974973 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,8 @@ { "name": "the-honk", "scripts": { - "prepare": "husky install" + "prepare": "husky install", + "maths": "node .husky/scripts/cleanMaths.js" }, "devDependencies": { "@types/node": "^17.0.6",