We are about to switch to a new forum software. Until then we have removed the registration on this forum.
sorry, posted this earlier this week but forum got moved and I cannot access old post. I am trying to basically detect if a line intersects a point and how I could do this with simple math. there is a lot of line to line and line to circle detection but i am not seeing simple line and point.
Comments
Old forum snapshot is forum.processing.org/one/
Although it's about 5 days older than the actual closing time! :-@
Technically, you don't "intersect" a line and a point, you see if a point is on a line...
It depends how you define your line.
You have to get the
y = a * x + b
equation for your line, and see if the coordinates of your point follow this equality. Can be as simple as that...If the line is defined by two points, the a and b parameters can be computed from them: that's a simple dual equation solving (I know the French term, not how it is named in English).
For lines intersection :
@Mushussu I have deleted your first post because it is redundant because you fixed the code formatting in the next post.
As PhiLho pointed out lines don't intersect with points rather you must calculate how close the point is to the line and decide if that is close enough.
The code below demonstrates what I mean and has a neat method for deciding whether a point is close enough to the line. Since this might be true even if the point is not quite on the line the method also calculates you the nearest point on the line.
You can see the sketch in action here
Line vs circle :
I've got an old online "circle - line intersection" example too:
http://studio.processingtogether.com/sp/pad/export/ro.9gGiJpQZIcTte/latest
thanks guys this is awesome! code works well, but are there any places I can read up on the theory behind it? I would hate to implement this without understanding how it works.
thanks for all the great examples!
o, and GoToLoop, that forum link doesn't work (already had found it) it only displays page one of the results of the forums as far as I can tell :(
quark, your code seems to throw an error on line 16
PhiLho, I tried implementing your code into what I already have and I am not sure what it happening, if its that canvas isnt updating fast enough or the math doesn't work. but my line spins like a clock and I need to test it against a shape I am drawing on the canvas, it seems sometimes they pass, other times they do not, and sometimes the opposite part of the line seems to make it pass the test (does this in the example as well)
I would like it to only pass if it is within the radius of the line/circle
here is my code (this is processing.js by the way:
I also have the example up here: http://hellowoo.com/apps/soundlasorz/app.html
if you have any idea what I am doing wrong please let me know. even a link to how to learn to implement this would be great, at the moment I am a bit ignorant to how the math works.
you draw by clicking on the canvas by the way, you can see how it passes and other times it opposite side passes.
I have just copied the code from above into Processing 2 and it worked fine for me!
Perhaps he was talking about using your program in JS mode. You use a variable named line, that might destroys the line() function.
@PhiLho I tried changed the variable
line
tothe_line
still worked in Java mode so I tried it in JS mode - all I got was a blank screen :(It appears that many of the PVector methods are not implemented in JS mode so I kept hacking at the problem and I eventually got it to work in both Java and JS mode. H =D> here is the code.
JS Mode is still pretty much processing 1.5.1! >-)