Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to define a Ray ? #75

Open
FlashTang opened this issue Nov 24, 2023 · 2 comments
Open

How to define a Ray ? #75

FlashTang opened this issue Nov 24, 2023 · 2 comments

Comments

@FlashTang
Copy link

Hello Sir
How can I define a Ray ?
Like following image:
Screen Shot 2023-11-25 at 05 33 10
I know I can lengthen the segment with a long length
but maybe kld-intersections already has it's way to define easily ?

@thelonious
Copy link
Owner

thelonious commented Nov 24, 2023

Hi FlashTang,

Sorry, there's no "ray" shape in the library. When this was written, it was to be used with SVG shapes. SVG doesn't have rays, so this library doesn't either.

As an aside, any intersection that uses the line-line method could be made to support rays. The current code makes sure that the intersection point lies on both lines. If that check were modified (or even removed), then it would be checking rays instead of line segments. This may not help you, but your example image only uses line-line, so it could help with that case.

@FlashTang
Copy link
Author

Hi FlashTang,

Sorry, there's no "ray" shape in the library. When this was written, it was to be used with SVG shapes. SVG doesn't have rays, so this library doesn't either.

As an aside, any intersection that uses the line-line method could be made to support rays. The current code makes sure that the intersection point lies on both lines. If that check were modified (or even removed), then it would be checking rays instead of line segments. This may not help you, but your example image only uses line-line, so it could help with that case.

@thelonious
Thanks for your reply and suggesting the solution
I need check both line-line and line-shapes, so I go for the solution: "extend the segment"
Just in case, if anyone interested, then here is the code :

Reference: https://stackoverflow.com/questions/7740507/extend-a-line-segment-a-specific-distance

function FakeRay(ax,ay,bx,by){
      var len = 99999;
      var lenAB = Math.sqrt(Math.pow(ax-bx,2),Math.pow(ay-by,2));
      var cx = bx + (bx - ax) / lenAB * len;
      var cy = by + (by - ay) / lenAB * len;
      return [ax,ay,cx,cy]; //return a new super-long segment
}
var ray = FakeRay(100,100,150,120);
var line = ShapeInfo.line([ray[0], ray[1]], [ray[2], ray[3]]);
var intersections = Intersection.intersect(otherShape, line);

Again, thanks for creating this library

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants