Giter VIP home page Giter VIP logo

math2d's People

Contributors

cmslewis avatar crazytoucan avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

math2d's Issues

Intersections not found

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.