# 常用数学公式

+关注继续查看

## 直线两点式转一般式

function getLineGeneralEquationFromTwoPoint(point1, point2) {
let x1 = point1.x;
let y1 = point1.y;
let x2 = point2.x;
let y2 = point2.y;
let a = y2 - y1;
let b = x1 - x2;
let c = x2 * y1 - x1 * y2;
return {
a: a,
b: b,
c: c,
};
}

## 两条直线的交点

function getFocusCoordinatesOfTwoLines(line1, line2) {
var x1 = line1.x1;
var y1 = line1.y1;
var x2 = line1.x2;
var y2 = line1.y2;
var x3 = line2.x1;
var y3 = line2.y1;
var x4 = line2.x2;
var y4 = line2.y2;
var x =
((x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4)) /
((x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4));
var y =
((x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4)) /
((x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4));
return { x: x, y: y };
}

## 线段延长后的坐标计算

function extendEndPoint(startPoint, endPoint, distance) {
var A = [startPoint.x, startPoint.y];
var B = [endPoint.x, endPoint.y];
// 横坐标差, 纵坐标差
var aToB = [B[0] - A[0], B[1] - A[1]];

// A点到B点的线段长度
var aToBDistance = Math.sqrt(aToB[0] * aToB[0] + aToB[1] * aToB[1]);

// 一份有多长
// 横坐标一份有多长
// 纵坐标一份有多长
var atoBNormalization = [aToB[0] / aToBDistance, aToB[1] / aToBDistance];

// 延长 distance 个像素就乘以 distance, 加上终点
var newEndPoint = {
x: atoBNormalization[0] * distance + B[0],
y: atoBNormalization[1] * distance + B[1],
};
return newEndPoint;
}

## 已知三个点, 求夹角

function getAngle(pointA, pointB, pointC) {
var lengthAB = Math.sqrt(Math.pow(pointA.x - pointB.x, 2) + Math.pow(pointA.y - pointB.y, 2)),
lengthAC = Math.sqrt(Math.pow(pointA.x - pointC.x, 2) + Math.pow(pointA.y - pointC.y, 2)),
lengthBC = Math.sqrt(Math.pow(pointB.x - pointC.x, 2) + Math.pow(pointB.y - pointC.y, 2));
var cosA = (Math.pow(lengthAB, 2) + Math.pow(lengthAC, 2) - Math.pow(lengthBC, 2)) / (2 * lengthAB * lengthAC);
var angleA = Math.round((Math.acos(cosA) * 180) / Math.PI);
return angleA;
}

let arr = [
{ x: 1, y: 0 },
{ x: 0.5, y: 1 },
{ x: 0, y: 0 },
];
let r = getAngle(arr[0], arr[1], arr[2]);
console.log(r);

## 已知点和直线, 求对称点坐标

// 求: 点P(x0,y0)关于直线 Ax + By + C = 0 对称的点P'(x,y)

// 计算公式

// d=(Ax0+By0+C)/(A^2+B^2)

function calculateSymmetryPoint(P, A, B, C) {
let d = (A * P.x + B * P.y + C) / (Math.pow(A, 2) + Math.pow(B, 2));
let x = P.x - 2 * A * d;
let y = P.y - 2 * B * d;
return { x: x, y: y };
}

let P = {
x: 1,
y: 3,
};

let A = 2;
let B = 1;
let C = 5;

let r = calculateSymmetryPoint(P, A, B, C);
console.log(r);

## 已知两点, 求直线点斜式公式

let A = {
x: 1,
y: 3,
};
let B = {
x: 2,
y: 4,
};
// 点斜式直线
// 斜率
let k = (B.y - A.y) / (B.x - A.x);
// 偏移量
let b = A.y - k * A.x;

console.log("k = " + k + " b = " + b);


## 两点距离

function getDistance(pointA, pointB) {
return Math.sqrt(Math.pow(pointA.x - pointB.x, 2) + Math.pow(pointA.y - pointB.y, 2));
}

## 已知两点, 求直线角度

function calcAngle(x1, y1, x2, y2) {
var angle = Math.atan2(y1 - y2, x2 - x1); //弧度
var theta = angle * (180 / Math.PI); // 角度
theta < 0 && (theta = 360 + theta);
return theta;
}

let x1 = 0;
let y1 = 0;
let x2 = 1;
let y2 = -1;
log(calcAngle(x1, y1, x2, y2));

--- 牙叔教程

## 声明

1082 0
[Tex学习笔记]数学公式再次测试
\begin{align*}\sum_{n=0}^{\infty}\frac{(n!)^{2}2^{n+1}}{(2n+1)!}&=\sum_{n=0}^{\infty}\int_{0}^{1}t^{n}(1-t)^{n}2^{n+1}dt\\&=2\int_{0}^{1}\sum_{0}^{\in...
707 0
[Tex学习笔记]一个数学公式
\begin{equation*} \begin{aligned} &\quad\int |\nabla(T_1-\overline{T})^+|^2 \rm dx-\int \frac{3m_1}{2}\nabla \psi_1\nabla T_1(T_1-\overline{T})^+ \rm ...
821 0

570 0
+关注
332

0