Published
Edited
Nov 7, 2019
Insert cell
Insert cell
Insert cell
Insert cell
/**
* Rotate a point.
* @param base
* @param point
* @param angle
* @returns {{x: *, y: *}}
**/

wrongRotatePoint = (base, point, angle) => {
const radians = - (Math.PI / 180) * angle;
const cos = Math.sin(radians); // ohoh it seem we made a mistake here using sinus instead of cosinus
const sin = Math.sin(radians);
return {
x:(cos * (point.y - base.y)) - (sin * (point.x - base.x)) + base.x,
y:(cos *(point.x - base.x)) + (sin * (point.y - base.y)) + base.y
};
}
Insert cell
Insert cell
{
expect(wrongRotatePoint({x:10,y:10},{x:20,y:10},90)).toEqual( {"x": 10, "y": 0});
expect(wrongRotatePoint({x:10,y:10},{x:20,y:10},0)).toEqual( {"x": 20, "y": 10});
}
Insert cell
Insert cell
Insert cell
/**
* Rotate a point.
* @param base
* @param point
* @param angle
* @returns {{x: *, y: *}}
**/
rotatePoint = (base, point, angle) => {
const radians = - (Math.PI / 180) * angle;
const cos = Math.cos(radians);
const sin = Math.sin(radians);
return {
x:(cos * (point.x - base.x)) - (sin * (point.y - base.y)) + base.x,
y:(cos *(point.y - base.y)) + (sin * (point.x - base.x)) + base.y
};
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more