WIP
This commit is contained in:
parent
0faf17dd6b
commit
1da546701a
@ -1,4 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings" defaultProject="true" />
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
26
main.ts
26
main.ts
@ -1,9 +1,8 @@
|
||||
// @deno-types="npm:@types/express"
|
||||
import express, { Request, Response } from 'express';
|
||||
import cors from 'cors';
|
||||
import {getCollisionPoints, ggvp, linearInterpolation, parabalInterpolatePoints} from "./physics.ts";
|
||||
import {firstPoint, getCollisionPoints, interpolation} from "./physics.ts";
|
||||
import {changeBasis} from "./math.ts";
|
||||
import IPoint from "./IPoint.ts";
|
||||
|
||||
const app = express();
|
||||
const PORT = 3000;
|
||||
@ -15,10 +14,9 @@ app.get('/api/points', (req: Request, res: Response) => {
|
||||
if (g === undefined || h === undefined || l === undefined || alpha === undefined) {
|
||||
res.status(401).send("Параметры должны быть заданы");
|
||||
}
|
||||
res.json(changeBasis(
|
||||
getCollisionPoints({ g: Number(g), h: Number(h), l: Number(l), alpha: Number(alpha) }),
|
||||
-Number(alpha)
|
||||
));
|
||||
res.json(
|
||||
getCollisionPoints({ g: Number(g), h: Number(h), l: Number(l), alpha: Number(alpha) })
|
||||
);
|
||||
});
|
||||
|
||||
app.get('/api/interpolation', (req: Request, res: Response) => {
|
||||
@ -26,19 +24,11 @@ app.get('/api/interpolation', (req: Request, res: Response) => {
|
||||
if (g === undefined || h === undefined || l === undefined || alpha === undefined || count === undefined) {
|
||||
res.status(401).send("Параметры должны быть заданы");
|
||||
}
|
||||
// const collisionPoints = changeBasis(getCollisionPoints({ g: Number(g), h: Number(h), l: Number(l), alpha: Number(alpha) }), -Number(alpha));
|
||||
// const points: IPoint[] = [];
|
||||
//
|
||||
// collisionPoints.forEach((point, i, array) => {
|
||||
// if (i === 0) {
|
||||
// points.push(...linearInterpolation(point, array[i+1], Number(count)));
|
||||
// return;
|
||||
// }
|
||||
// if (i >= array.length - 2) return;
|
||||
// points.push(...ggvp({ g: Number(g), h: Number(h), l: Number(l), alpha: Number(alpha) }, Number(count)));
|
||||
// });
|
||||
|
||||
res.json(changeBasis(ggvp({ g: Number(g), h: Number(h), l: Number(l), alpha: Number(alpha) }, Number(count)), -Number(alpha)).map(p => ({...p, y: p.y - Number(h)})));
|
||||
const params = { g: Number(g), h: Number(h), l: Number(l), alpha: Number(alpha) };
|
||||
const fp = firstPoint(params);
|
||||
|
||||
res.json([...fp, ...changeBasis(interpolation(params), -Number(alpha)).map(p => ({...p, y: p.y - Number(h), time: p.time + fp[fp.length - 1].time}))]);
|
||||
});
|
||||
|
||||
app.listen(PORT, () => {
|
||||
|
||||
124
physics.ts
124
physics.ts
@ -1,115 +1,75 @@
|
||||
import IParams from "./IParams.ts";
|
||||
import IVector from "./IVector.ts";
|
||||
import IPoint from "./IPoint.ts";
|
||||
|
||||
function getV0(params: IParams) {
|
||||
return Math.sqrt(2 * params.g * params.h);
|
||||
}
|
||||
|
||||
function getCollisionPoint(params: IParams, n: number) {
|
||||
return 4 * n * getV0(params) * Math.sin(params.alpha) / params.g;
|
||||
}
|
||||
function getCollisionPoints(params: IParams): IPoint[] {
|
||||
const interpolationPoints = interpolation(params);
|
||||
const points: IPoint[] = [];
|
||||
|
||||
function getVelocity(params: IParams, n: number): IVector {
|
||||
return {
|
||||
x: (2*n + 1) * getV0(params) * Math.sin(params.alpha),
|
||||
y: getV0(params) * Math.cos(params.alpha)
|
||||
}
|
||||
}
|
||||
|
||||
function getAngle(params: IParams, n: number) {
|
||||
const velocity = getVelocity(params, n);
|
||||
return velocity.y / velocity.x;
|
||||
}
|
||||
|
||||
function getCollisionPoints(params: IParams) {
|
||||
const points: IPoint[] = [
|
||||
{
|
||||
x: 0,
|
||||
y: 0,
|
||||
velocity: getV0(params),
|
||||
time: 0,
|
||||
angle: -Math.PI / 2 + params.alpha,
|
||||
for (let i = 0; i < interpolationPoints.length - 1; i++) {
|
||||
if (interpolationPoints[i].angle - interpolationPoints[i+1].angle < 0) {
|
||||
points.push(interpolationPoints[i]);
|
||||
}
|
||||
];
|
||||
|
||||
let n = 0;
|
||||
while (points[points.length - 1].x < params.l) {
|
||||
n++;
|
||||
points.push({
|
||||
x: getCollisionPoint(params, n),
|
||||
y: 0,
|
||||
velocity: Math.sqrt(getVelocity(params, n).x*getVelocity(params, n).x + getVelocity(params, n).y*getVelocity(params, n).y),
|
||||
angle: getAngle(params, n),
|
||||
time: 0
|
||||
});
|
||||
}
|
||||
|
||||
return points;
|
||||
return [{x: 0, y: 0, angle: 0, velocity: 0, time: 0}, ...points];
|
||||
}
|
||||
|
||||
function linearInterpolation(p1: IPoint, p2: IPoint, count: number) {
|
||||
const points: IPoint[] = [];
|
||||
|
||||
const deltaX = (p2.x - p1.x) / (count - 1);
|
||||
const deltaY = (p2.y - p1.y) / (count - 1);
|
||||
const deltaV = (p2.velocity - p1.velocity) / (count - 1);
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
const x = p1.x + i * deltaX;
|
||||
const y = p1.y + i * deltaY;
|
||||
const velocity = p1.velocity + i * deltaV;
|
||||
points.push({ x, y, velocity, angle: p1.angle, time: 2 });
|
||||
}
|
||||
|
||||
return points;
|
||||
}
|
||||
|
||||
function parabalInterpolatePoints(params: IParams, p1: IPoint, p2: IPoint, count: number): IPoint[] {
|
||||
const points: IPoint[] = [];
|
||||
|
||||
const a = (Math.tan(Math.PI - p2.angle - 2*params.alpha) - Math.tan(p1.angle))/(2*(p2.x-p1.x));
|
||||
const b = Math.tan(p1.angle) - 2*a*p1.x;
|
||||
const c = p1.y - a*p1.x*p1.x - b*p1.x;
|
||||
const y = (x: number) => a*x*x + b*x + c;
|
||||
|
||||
const step = (p2.x-p1.x)/(count + 1);
|
||||
|
||||
for (let i = 1; i <= count; i++) {
|
||||
const x = step*i + p1.x;
|
||||
points.push({
|
||||
x: x,
|
||||
y: y(x),
|
||||
angle: 2*a*x + b,
|
||||
time: 1,
|
||||
velocity: 0
|
||||
})
|
||||
}
|
||||
|
||||
return [p1, ...points]
|
||||
}
|
||||
|
||||
function ggvp(params: IParams, count: number): IPoint[] {
|
||||
function interpolation(params: IParams): IPoint[] {
|
||||
const T = (2 * getV0(params)) / params.g;
|
||||
|
||||
const points: IPoint[] = [];
|
||||
let lastX = 0;
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
let i = 0;
|
||||
while (lastX*Math.cos(params.alpha) < params.l) {
|
||||
const t = i / 100;
|
||||
|
||||
const vx = getV0(params)*Math.sin(params.alpha) + params.g*Math.sin(params.alpha)*t;
|
||||
const vy = getV0(params)*Math.cos(params.alpha) - params.g*Math.cos(params.alpha)*(t % T);
|
||||
|
||||
lastX = getV0(params) * Math.sin(params.alpha) * t + (params.g * Math.sin(params.alpha) * t ** 2) / 2;
|
||||
|
||||
points.push({
|
||||
x: getV0(params) * Math.sin(params.alpha) * t + (params.g * Math.sin(params.alpha) * t ** 2) / 2,
|
||||
x: lastX,
|
||||
y: getV0(params) * Math.cos(params.alpha) * (t % T) - (params.g * Math.cos(params.alpha) * (t % T) ** 2) / 2,
|
||||
time: t,
|
||||
velocity: Math.sqrt(vx*vx + vy*vy),
|
||||
angle: Math.atan2(vy, vx)
|
||||
});
|
||||
i++;
|
||||
}
|
||||
|
||||
return points;
|
||||
}
|
||||
|
||||
export { getCollisionPoints, parabalInterpolatePoints, linearInterpolation, ggvp };
|
||||
function firstPoint(params: IParams): IPoint[] {
|
||||
const points: IPoint[] = [
|
||||
{
|
||||
x: 0,
|
||||
y: 0,
|
||||
time: 0,
|
||||
angle: -Math.PI / 2,
|
||||
velocity: 0
|
||||
}
|
||||
];
|
||||
|
||||
let t = 0.01;
|
||||
while(points[points.length - 1].y >= -params.h) {
|
||||
points.push({
|
||||
x: 0,
|
||||
y: -params.g*t**2,
|
||||
time: t,
|
||||
angle: -Math.PI / 2,
|
||||
velocity: -params.g*t
|
||||
})
|
||||
t += 0.01;
|
||||
}
|
||||
|
||||
return points.slice(0, points.length-1);
|
||||
}
|
||||
|
||||
export { getCollisionPoints, interpolation, firstPoint };
|
||||
18
physics2.ts
18
physics2.ts
@ -0,0 +1,18 @@
|
||||
import IPoint from "./IPoint.ts";
|
||||
import IParams from "./IParams.ts";
|
||||
|
||||
function getTime(params: IParams, point: IPoint) {
|
||||
const a = params.g / 2;
|
||||
const b = -point.velocity*Math.sin(point.angle) - Math.abs(Math.tan(params.alpha)) * point.velocity * Math.cos(point.angle);
|
||||
const c = -point.y - Math.abs(Math.tan(params.alpha))*point.x;
|
||||
|
||||
const discriminant = b - 4*a*c;
|
||||
const t1 = (-b - Math.sqrt(discriminant))/2/a;
|
||||
const t2 = (-b + Math.sqrt(discriminant))/2/a;
|
||||
|
||||
return Math.max(t1, t2);
|
||||
}
|
||||
|
||||
function getNextPoint(params: IParams, point: IPoint) {
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user