Lost Password?


Go Back   CodeCall Programming Forum > Software Development > General Programming > Programming Theory

Programming Theory Discuss programming theory, algorithm efficiency, logic, and other any other category where math and computer science overlap.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-28-2007, 02:30 PM
Maurice_Z Maurice_Z is offline
Learning Programmer
 
Join Date: Nov 2007
Location: Poland
Posts: 35
Rep Power: 4
Maurice_Z is on a distinguished road
Send a message via ICQ to Maurice_Z Send a message via AIM to Maurice_Z Send a message via MSN to Maurice_Z Send a message via Yahoo to Maurice_Z
Lightbulb Geometry Circle-Line Inters.

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
Doubt it will be helpful anyhow, but might it be you notice some mistake I did not noticed.
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

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


All times are GMT -5. The time now is 08:44 AM.

Contest Stats

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

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads