Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const cube_vertices = getVerticesFromPoints(cube_points, {x: 1, y: 1});
- const rotate = (cx, cy, x, y, angle)=> {
- const radians = (Math.PI / 180) * angle,
- cos = Math.cos(radians),
- sin = Math.sin(radians),
- nx = (cos * (x - cx)) + (sin * (y - cy)) + cx,
- ny = (cos * (y - cy)) - (sin * (x - cx)) + cy;
- return {x: nx, y: ny};
- }
- const getCenterOfPoly = (vertices) => {
- let minX = 50000, minY = 50000
- let maxX = 0, maxY = 0
- for(let i = 0; i < vertices.length; i++) {
- if(vertices[i].x > maxX)
- maxX = vertices[i].x
- if(vertices[i].y > maxY)
- maxY = vertices[i].y
- if(vertices[i].x < minX)
- minX = vertices[i].x
- if(vertices[i].y < minY)
- minY = vertices[i].y
- }
- return { x: minX + (maxX - minX) / 2, y: minY + (maxY - minY) / 2};
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement