geometria-analitica
Version:
Pacote com cálculos de Geometria Analítica
40 lines (39 loc) • 2.01 kB
JavaScript
export class GA {
static produtoVetorial(vetorA, vetorB, head) {
const [detAI, detAJ, detAK] = vetorA;
const [detBI, detBJ, detBK] = vetorB;
const hasHead = Boolean(head);
const positivos = [(detAJ * detBK), (detAK * detBI), (detAI * detBJ)].map((value, index) => hasHead ? value * head[index] : value);
const negativos = [(detAK * detBJ), (detAI * detBK), (detAJ * detBI)].map((value, index) => hasHead ? value * head[index] : value).map(element => element * -1);
return [(positivos[0] + negativos[0]), (positivos[1] + negativos[1]), (positivos[2] + negativos[2])];
}
static produtoEscalar(vetorA, vetorB) {
return vetorA.map((value, index) => value * vetorB[index]).reduce((acc, val) => acc + val);
}
static moduloVetor(vetor) {
return Math.sqrt(vetor.map(element => element ** 2).reduce((acc, val) => acc + val));
}
static calcularVetor(vetorA, vetorB) {
return vetorB.map((value, index) => value - vetorA[index]);
}
static equacaoParametrica(ponto, vetorDiretor) {
return ponto.map((value, index) => `${value} + (${vetorDiretor[index]}).t`);
}
static equacaoGeralDoPlano(vetor, ponto) {
const d = vetor.map((value, index) => value * ponto[index]).reduce((acc, val) => acc + val) * -1;
return `${vetor[0]}x + ${vetor[1]}y + ${vetor[2]}z + ${d} = 0`;
}
static anguloEntreVetores(vetorA, vetorB) {
const produtoEscalarResultado = GA.produtoEscalar(vetorA, vetorB);
const moduloVetorA = GA.moduloVetor(vetorA);
const moduloVetorB = GA.moduloVetor(vetorB);
return produtoEscalarResultado / (moduloVetorA * moduloVetorB);
}
static produtoMisto(vetorA, vetorB, vetorC) {
const produtoVetorial = GA.produtoVetorial(vetorB, vetorC);
return GA.produtoEscalar(vetorA, produtoVetorial);
}
static distanciaEntrePontos(vetorA, vetorB) {
return GA.moduloVetor(GA.calcularVetor(vetorA, vetorB));
}
}