'define the line by the co-ordinates of any 2 points on that line, (x1,y1) and (x2,y2)
'define the circle by the co-ordinates of its centre xc,yc and its radius, r
'now calculate the length of the sides of the triangle formed by the 3 points, call them a,b,c
a=SQR((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2))
b=SQR((x1-xc)*(x1-xc) + (y1-yc)*(y1-yc))
c=SQR((xc-x2)*(xc-x2) + (yc-y2)*(yc-y2))
'using Heron's formula for the area
s=0.5*(a+b+c)
AreaOfTriangle = SQR(s*(s-a)*(s-b)*(s-c))
'use area of triangle = half base times height to get the height, that gives circle centre distance from line. Subtract radius to get answer.
DistanceFromLineToCircle = 2*AreaOfTriangle/a - r
IF DistanceFromLineToCircle >0 THEN 'not touching
IF DistanceFromLineToCircle =0 THEN 'just touching
IF DistanceFromLineToCircle <0 THEN 'line cuts through circle
as I understand it, it's about a collision of two simple 2D objects, a line and a circle.
this condition should be met if ANY of the points building the line is less than radius distant to the center of the circle.
superadnims seems to talk about some more complex raycasting problems...
Oh really? you just repeated what has been described on that actual link... Call it a line or a ray, the math is the same and he needs a vector class/lib if he wants to get anywhere near success on the right foot.
Putting a few lines of code together just to make it work doesn't seem to be a good solution in my opinion. Although it's good to know how 'vector math' works, having it abstracted makes it so much easier for the coder's life.
I recommend he reads that article anyway since it's not advanced at all. Sometimes I regret not paying attention at school ... I think it's the teacher's fault though, they never put a cool example to begin with... they just go through the book enumerating it all, needless to say it's very boring for a kid's mind!
> you just repeated what has been described on that actual link...
I didn't bother clicking that link...
I don't need some tutorials to know what such a collision is and what the base for the algorithms is.
you may need such collisions for simple 2D games, and you don't need to overkill such little problems with a vector lib.
sure, it's vector maths, but such little things you can code directly.
and remember, he asked for a "circle line collision" and not "to find out whether the ray is intersecting against one or more sphere / circles".
when you say "he needs a vector class/lib if he wants to get anywhere near success" you say "he is too dumb to code some simple vector collisins on his own"... :roll:
Well I don't know what 'collisins' are but I know that it would benefit him if he wrote such a library to begin with.
I don't need some tutorials to know what such a collision is and what the base for the algorithms is.
Amazing, you were born knowing this. I'd love to tap into your brain, see what makes it tick.
While you were busy getting me wrong, I was just saying that it'll be good for this guy to just read this paper and write his own vector library. Why? because if he knew about vector math and all of this basic algos he wouldn't be asking in the first place.
And since this isn't helping anyone I'll take the most convenient action and part ways from this pointless discussion.
Sounds like you only chimed in in the first place to blow your own trumpet
superadnim wrote:Sometimes I regret not paying attention at school ... I think it's the teacher's fault though
:roll:
Not surprisingly, taking responsibility for ones own actions is the trait of a mature adult.
I think your attitude to Kaeru's reply was, as usual, unnecessarily snide and has once again reduced a question post to an arguement. Your posting intention seems always to be to display your knowledge rather than help which would explain why your get so touchy at the slightest hint that someone disagrees.
I realise the forums are for all ages but please try to grow up a little.
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein