|
||||||
| Programming Theory Discuss programming theory, algorithm efficiency, logic, and other any other category where math and computer science overlap. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Just as the title says, intersection between line and circle.
The only, at least a bit comprehensible explanation I managed to find, with almost ready scripts is Intersection of a Line and a Sphere (or circle). Although I can't figure out how exactly I have to use them ^^;. I mean I tried, but the results are incredibly strange,if you want you can see the code: Code:
Local x1:Float=100.0
Local y1:Float=100.0
Local x2:Float=500.0
Local y2:Float=200.0
Local x3:Float=400.0
Local y3:Float=400.0
Local rad:Float=25
Local a:Float=(x2-x1)^2+(y2-y1)^2
Local b:Float=2*((x2-x1)*(x1-x3)+(y2-y1)*(y1-y3))
Local c:Float=x3^2+y3^2+x1^2+y1^2-2*(x3*x1+y3*y1)-rad^2
Local delta:Float=b^2-4*a*c
Local ix:Float=0.0
Local iy:Float=0.0
Local jx:Float=0.0
Local jy:Float=0.0
Local u1:Float=0.0
Local u2:Float=0.0
If delta>0
u1=(-b-Sqr(delta))/(2*a)
u2=(-b+Sqr(delta))/(2*a)
ix=x1+u1*(x2-x1)
iy=y1+u1*(y2-y1)
jx=x1+u2*(x2-x1)
jy=y1+u2*(y2-y1)
EndIf
The numbers I get are extraordinarily large. I compare what I have with what is written there. I noticed, that the first and only thing I can calculate is A,B and C. When I have those I can get to calculating Delta, and then get the two points of intersection with help of the almost first err... Code? The "P = P1 + u (P2 - P1)". And when it comes to the fact, that I only want to check if the Circle intersects the line in between these two points, the stuff explained there gets completely incomprehensible -_-. So, some little, or better, a lot of help would be nice to have .Thanks in Advance. EDIT:Gaah, I just noticed what is wrong -_-. Wehan calculation U1 and U2 I forgot to put /2*a in parenthesis /(2*a) and now it works. Still, this leaves me with no understanding to the second part indicating how to test if the intersection happens with the line segment... EDIT2:The classical understandment after asking questions - I got it. I don't believe it myself, but I understood the problem, and fought it bravely! ^_^. Sorry for posting this thread, but when I posted this, the info there was like an understandable nonsense, though after some break it became more understandable ^^;. Anyhow, sorry for this. Last edited by Maurice_Z; 11-28-2007 at 04:31 PM. Reason: Found the solution |
| Sponsored Links |
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| VB6.0:Tutorial, Command Line | TcM | VB Tutorials | 9 | 08-25-2008 01:19 PM |
| Can anyone suggest to me a simple but clean script that creates line graphs? | Patrick | PHP Forum | 1 | 10-08-2007 03:46 PM |
| HTML Basic Formatting | clookid | Tutorials | 14 | 03-06-2007 04:10 PM |
| Next Line and line lengths | zee | Java Help | 3 | 02-25-2007 02:31 AM |
| PHP command Line | dirkfirst | PHP Forum | 1 | 10-26-2006 11:31 AM |
| WingedPanther | ........ | 2753.6 |
| Xav | ........ | 2704 |
| Brandon W | ........ | 1702.32 |
| John | ........ | 1207.73 |
| marwex89 | ........ | 1175.24 |
| morefood2001 | ........ | 966.05 |
| dcs | ........ | 655.75 |
| Steve.L | ........ | 475.59 |
| orjan | ........ | 418.58 |
| Aereshaa | ........ | 383.54 |