feat: inverse sin calculator in python

This commit is contained in:
newt 2024-10-09 18:02:46 +01:00
parent 12a1679f36
commit e7a5f21477
9 changed files with 112 additions and 35 deletions

4
.gitignore vendored
View file

@ -21,5 +21,5 @@ _deps
bin
ignored
maths/*.pdf
maths/*.synctex.gz
maths/**/*.pdf
maths/**/*.synctex.gz

View file

@ -27,26 +27,40 @@ 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 });
const files = await Promise.all(
dirents.map(dirent => {
const res = path.resolve(dir, dirent.name);
return dirent.isDirectory() ? crawlDirectory(res) : res;
})
);
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, {
viewportScale: 2
}).then(async output => {
pdfToPng(filePath).then(async output => {
const pageCount = output.length;
if (pageCount > 1)
output.forEach(async (page, i) =>
fs.writeFileSync(
path.join(mathsDir, `${fileName}-${i + 1}.png`),
path.join(fileDirectory, `${fileName}-${i + 1}.png`),
await cropBuffer(page.content)
)
);
else
fs.writeFileSync(
path.join(mathsDir, `${fileName}.png`),
path.join(fileDirectory, `${fileName}.png`),
await cropBuffer(output[0].content)
);
});
@ -55,4 +69,5 @@ fs.readdirSync(mathsDir).forEach(file => {
if (fileExtension !== 'tex' && fileExtension !== 'png' && fileExtension !== 'cls') {
fs.rmSync(filePath);
}
});
});
})();

View file

@ -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"
}

View file

@ -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))}""")

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View file

@ -1,3 +1,2 @@
\ProvidesClass{style}
\LoadClass[17pt]{extarticle}
\pagenumbering{gobble}

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

View file

@ -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}

View file

@ -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",