feat: inverse sin calculator in python
This commit is contained in:
parent
12a1679f36
commit
e7a5f21477
9 changed files with 112 additions and 35 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -21,5 +21,5 @@ _deps
|
||||||
bin
|
bin
|
||||||
ignored
|
ignored
|
||||||
|
|
||||||
maths/*.pdf
|
maths/**/*.pdf
|
||||||
maths/*.synctex.gz
|
maths/**/*.synctex.gz
|
||||||
|
|
|
@ -27,32 +27,47 @@ const cropBuffer = buffer =>
|
||||||
.catch(err => reject(err));
|
.catch(err => reject(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
fs.readdirSync(mathsDir).forEach(file => {
|
const crawlDirectory = async dir => {
|
||||||
const [fileName, fileExtension] = file.split('.');
|
const dirents = fs.readdirSync(dir, { withFileTypes: true });
|
||||||
const filePath = path.join(mathsDir, file);
|
|
||||||
|
|
||||||
if (file.endsWith('.pdf')) {
|
const files = await Promise.all(
|
||||||
pdfToPng(filePath, {
|
dirents.map(dirent => {
|
||||||
viewportScale: 2
|
const res = path.resolve(dir, dirent.name);
|
||||||
}).then(async output => {
|
return dirent.isDirectory() ? crawlDirectory(res) : res;
|
||||||
const pageCount = output.length;
|
})
|
||||||
|
);
|
||||||
|
|
||||||
if (pageCount > 1)
|
return files.flat();
|
||||||
output.forEach(async (page, i) =>
|
};
|
||||||
|
|
||||||
|
(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(
|
fs.writeFileSync(
|
||||||
path.join(mathsDir, `${fileName}-${i + 1}.png`),
|
path.join(fileDirectory, `${fileName}.png`),
|
||||||
await cropBuffer(page.content)
|
await cropBuffer(output[0].content)
|
||||||
)
|
);
|
||||||
);
|
});
|
||||||
else
|
}
|
||||||
fs.writeFileSync(
|
|
||||||
path.join(mathsDir, `${fileName}.png`),
|
|
||||||
await cropBuffer(output[0].content)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fileExtension !== 'tex' && fileExtension !== 'png' && fileExtension !== 'cls') {
|
if (fileExtension !== 'tex' && fileExtension !== 'png' && fileExtension !== 'cls') {
|
||||||
fs.rmSync(filePath);
|
fs.rmSync(filePath);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
})();
|
||||||
|
|
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
|
@ -36,5 +36,5 @@
|
||||||
},
|
},
|
||||||
"latex-workshop.latex.autoBuild.run": "onSave",
|
"latex-workshop.latex.autoBuild.run": "onSave",
|
||||||
"latex-workshop.latex.autoClean.run": "onBuilt",
|
"latex-workshop.latex.autoClean.run": "onBuilt",
|
||||||
"latex-workshop.latex.search.rootFiles.include": ["**/*.tex", "root.tex"]
|
"latex-workshop.cls"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,50 @@
|
||||||
from cmath import e, sqrt
|
from cmath import e, sqrt, log
|
||||||
from _helpers import floatInput
|
from _helpers import floatInput
|
||||||
|
|
||||||
i = sqrt(-1)
|
i = sqrt(-1)
|
||||||
|
|
||||||
compute = lambda numerator, denominator: (numerator / denominator).real
|
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)
|
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)
|
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)))
|
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: ")
|
radians = floatInput("Please enter an amount of radians: ")
|
||||||
|
|
||||||
print(f"""
|
print(f"""
|
||||||
sin({radians}) = {sin(radians)})
|
Trigometric functions
|
||||||
|
|
||||||
|
sin({radians}) = {sin(radians)}
|
||||||
cos({radians}) = {cos(radians)}
|
cos({radians}) = {cos(radians)}
|
||||||
tan({radians}) = {tan(radians)}
|
tan({radians}) = {tan(radians)}
|
||||||
|
|
||||||
csc({radians}) = {1 / sin(radians)}
|
Reciprocal trigometric functions
|
||||||
sec({radians}) = {1 / cos(radians)}
|
|
||||||
cot({radians}) = {1 / tan(radians)}""")
|
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 |
|
@ -1,3 +1,2 @@
|
||||||
\ProvidesClass{style}
|
|
||||||
\LoadClass[17pt]{extarticle}
|
\LoadClass[17pt]{extarticle}
|
||||||
\pagenumbering{gobble}
|
\pagenumbering{gobble}
|
||||||
|
|
BIN
maths/trigometric functions/sin.png
Normal file
BIN
maths/trigometric functions/sin.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 40 KiB |
31
maths/trigometric functions/sin.tex
Normal file
31
maths/trigometric functions/sin.tex
Normal 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}
|
|
@ -1,7 +1,8 @@
|
||||||
{
|
{
|
||||||
"name": "the-honk",
|
"name": "the-honk",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepare": "husky install"
|
"prepare": "husky install",
|
||||||
|
"maths": "node .husky/scripts/cleanMaths.js"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^17.0.6",
|
"@types/node": "^17.0.6",
|
||||||
|
|
Loading…
Reference in a new issue