PROGRAM TABELL;
USES CRT;
VAR I, VAL:INTEGER;
STOPP:CHAR; {CHAR BETYDER CHARACTER OCH KAN VARA VILKET TECKEN SOM HELST}
BEGIN
CLRSCR;
TEXTCOLOR (LIGHTBLUE);
WRITELN('MED DETTA PROGRAM KAN DU FÅ EN GÅNGERTABELL UTSKRIVEN');
WRITELN('VILKEN TABELL ÖNSKAS?');
READLN(VAL);
FOR I:=1 TO 12 DO
BEGIN
WRITELN(I:2,' * ',VAL,' = ',I*VAL);
END;
WRITELN('TRYCK TANGENT!');
STOPP:=READKEY;
END.add(v) {
return new Vector(
this.x + v.x,
this.y + v.y);
}
addTo(v) {
this.x += v.x;
this.y += v.y;
}sub(v) {
return new Vector(
this.x - v.x,
this.y - v.y);
}
subFrom(v) {
this.x -= v.x;
this.y -= v.y;
}mult(n) {
return new Vector(
this.x * n,
this.y * n);
}
div(n) {
return new Vector(
this.x / n,
this.y / n);
}getAngle() {
return Math.atan2(
this.y,
this.x);
}
getLength() {
return Math.hypot(
this.x,
this.y);
}class Vector {
constructor(x, y) {
this.x = x;
this.y = y;
}
...
}Trigonometry
Math.atan2(0, -1); // 3.14
Pythagorean theorem
Math.hypot(3, 4); // 5
import { bowyerWatson, Triangle } from 'delaunay.js';
import Vector from 'vectory-lib';
function getRandomPoints() {
let points = [];
let nrOfPoints = 10;
for(let i = 0; i < nrOfPoints; i++) {
points.push(new Vector(
Math.random() * 100,
Math.random() * 100
));
}
return points;
}
let points = getRandomPoints();
let superTriangle = new Triangle(
new Vector(-1000, 1000),
new Vector(1000, 1000),
new Vector(0, -1000)
);
let triangles = bowyerWatson(superTriangle, points);
// Do something fun with the triangles!From a consumer (caller) perspective
Each published a paper of their own in the same number of The Computer Journal, Volume 24, Number 2, May 1981
function BowyerWatson (pointList)
// pointList is a set of coordinates defining the points to be triangulated
triangulation := empty triangle mesh data structure
// must be large enough to completely contain all the points in pointList
add super-triangle to triangulation
// add all the points one at a time to the triangulation
for each point in pointList do
badTriangles := empty set
// first find all the triangles that are no longer valid due to the insertion
for each triangle in triangulation do
if point is inside circumcircle of triangle
add triangle to badTriangles
polygon := empty set
for each triangle in badTriangles do // find the boundary of the polygonal hole
for each edge in triangle do
if edge is not shared by any other triangles in badTriangles
add edge to polygon
for each triangle in badTriangles do // remove them from the data structure
remove triangle from triangulation
for each edge in polygon do // re-triangulate the polygonal hole
newTri := form a triangle from edge to point
add newTri to triangulation
for each triangle in triangulation // done inserting points, now clean up
if triangle contains a vertex from original super-triangle
remove triangle from triangulation
return triangulationmoveTowards(v, length) {
let delta = v.sub(this).setLength(length);
return this.add(delta);
}Georgy Voronoy
edges() {
return [
[this.a, this.b],
[this.b, this.c],
[this.c, this.a]
];
}
hasEdge(edge) {
for(const e of this.edges()) {
if(e[0].equals(edge[0]) && e[1].equals(edge[1]) ||
e[1].equals(edge[0]) && e[0].equals(edge[1])) {
return true;
}
}
return false;
}
sharesAnEdgeWith(triangle) {
for(const edge of triangle.edges()) {
if(this.hasEdge(edge)) {
return true;
}
}
return false;
}equals(v) {
return this.x == v.x && this.y == v.y;
}