crazytoucan / math2d Goto Github PK
View Code? Open in Web Editor NEWTwo-dimensional vector math library for JavaScript.
License: MIT License
Two-dimensional vector math library for JavaScript.
License: MIT License
Apologies for no fiddle/pen on this, I couldn't find math2d on a CDN nor a packaged version for use with unpkg
Consider the following code:
import { polygonIntersectRay, rayLookAt } from "math2d";
const getBoundingPolygon = ({ width, height }) => {
const topLeft = [0, 0];
const topRight = [width, 0]
const bottomLeft = [0, height];
const bottomRight = [width, height];
return [
...topLeft,
...topRight,
...bottomRight,
...bottomLeft
];
};
const unitSquarePolygon = getBoundingPolygon({ width: 1, height: 1 });
const centreVec = { x: 0.5, y: 0.5 };
const rayFromCentrePositiveXDirection = rayLookAt(centreVec, { x: 0.6, y: 0.5 });
const rayFromCenterNegativeXDirection = rayLookAt(centreVec, { x: 0.4, y: 0.5 });
The former ray is deemed to have intersected correctly:
polygonIntersectRay(unitSquarePolygon, rayFromCentrePositiveXDirection);
PointIntersectionResult
exists: true
t0: 1.5
t1: 0.5
x: 1
y: 0.5
...whereas the latter is not deemed to have intersected:
polygonIntersectRay(unitSquarePolygon, rayFromCenterNegativeXDirection);
[]
Is there something obvious I'm doing wrong?
Not setting the value of winner
properly:
I'd like a function similar to polylineGetPointAt
that takes a t
value on [0..1] and calculates point relative to the complete polyline distance.
Does Math2d supports finding the centroid of a polygon?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.