Problems finding the interception point of two lines

Hi there,
I've written a class "Linie", which extends the Line2D.Float class, and added a method to determine the interception point of two lines.
One of the two lines can be anything except horizontal and vertical, the other one (which is the one that is passed to the method) can only be horizontal or vertical (I hoped this would make it easier).
public Point schneidet(Linie l){
          Point schnitt = new Point();
          float m = (y1-y2)/(x1-x2);
          int n = Math.round(y1-(x1*m));
          if (l.y1==l.y2){               // Is line l horizontal?
               int poX = Math.round((l.y1-n)/m);
               schnitt.setLocation(poX,(int)l.y1);
          else if (l.x1==l.x2){               // Is line l vertical?
               int poY = Math.round((m*l.x1)+n);
               schnitt.setLocation((int)l.x1,poY);
          return schnitt;
     }The equation of a line is
y = m*x + n.
Because the line l can only be horizontal or vertical, one coordinate of the interception point is always clear from the beginning, the other one is supposed to be calculated and stored in poX or poY.
But this is where the method doesn't do what it's supposed to. There must be some mistake inside the calculation with the slope (m) and n. Any ideas?

Why so complicated? Are the lines real lines (straight connections between 2 points) or curves? If they are lines, you just need to inspect the coordinates of all 4 points (2 * 2 end points) and show if the points are "within" the other points ...
Intersection point of two lines
Line Intersection and its Applications
SIMPLE ALGORITHMS I - INTERSECTION OF LINES

Similar Messages

  • The intersection point of two lines in 3D

    How to calculate the intersection point of two lines in 3D?
    source code!

    this is actually a rather easy operation. lets look at some basic properties of lines / vectors in 3D space:
    1. If two lines intersect at a single point, then there must be exactly one plane in which the two lines are co-planar. This is pretty trivial to prove, but I won't bother here, because you can google to find out that two vectors that extend from a common point define a single plane.
    2. If you take the cross-product of two vectors, the resulting vector is guaranteed to be perpendicular to both lines (this is a basic property of a cross-product). If the two lines intersect, then this cross-product will be the normal vector to the plane in which both lines lie.
    3. Now transform (rotate) yours space such that your z-axis becomes parallel to the normal vector of that plane.
    Now, the parametric equation for a line in 3D space is this:
    (x, y, z) = (xo, yo, zo) + k(xd, yd, zd)
    After you have transformed your space, you will notice that the equation of each line will now be
    (x, y, z) = (xo, yo, zo) + k(xd, yd, 0)
    If zo is equal for both lines, then the two lines intersect. Otherwise, the two lines do not intersect.
    if the intersection exists, then to solve for it, you ignore the z coordinate, and treat it like a two dimensional system:
    (x, y) = (xo, yo) + k(xd, yd)
    you can use the basic 2D formula y - yo = m(x - xo), or y = m(x - xo) + yo
    you can calculate m = yd / xd.
    which simplifies to y = mx -mxo + yo, or 0 = mx - y + (yo - mxo)
    you now have two equations of the form Ax + By + C = 0.
    From there, you can use Cramer's rule to find the intersection of the two lines.
    It sounds kind of complicated when you read it as I have presented it, but it's actually extremely easy to write a program for, because each step is simple mathematic operation with basically no decisions involved (hence no if-structures, except at the one point where you actually need to determine if the lines intersect).
    So to reiterate, the steps required are:
    1. Check if lines are parallel. If yes, check if they are the same line, and then stop.
    2. If not parallel, cross-multiply the direction vectors of each line.
    3. Rotate your space such that z is parallel with cross-product of lines
    i. dot-product of z axis (0, 0, 1) with cross-product of lines gives angle*
    ii. cross-product of z axis (0, 0, 1) with cross-product of lines gives axis of rotation.
    iii. rotate your lines (i.e. point and direction vector) about that axis by negative of ange determined in (i).
    4. if z value of points from both lines is the different, no solution. stop.
    5. otherwise, apply Cramer's rule.
    6. done.
    * obtaining the angle of rotation with the dot product relies on the angle being less than 90 degrees, so check if z value of normal vector is + or -, and then perform dot product and cross-product on appropriate + or - z vector.
    - Adam

  • Is there a function to output the crossing point of two plotted lines

    I got some data plotted on a graph, I need to find the crossing point  of the plotted lines on the graph (The plotted data curves are not linear lines) and detect it by an indicator. I could compare the to data arrays plotted and output the two closest data numbers, but the really crossing pionts is sertainly an intercept of two Interpolated values made by the graph, wich are not in my data buffers. any suggestions will be full Stared   
    Zamzam
    HFZ

    I only did a cursory look and didn't find any built-in function that jumped up screaming "I'm it! I'm it!", but that doesn't mean something doesn't exist given the large number of functions available with LabVIEW. An alternate solution is to use linear interpolation between successive points. If the points are close together then you can assume a straight line between the points and break this down to the simple case of finding the intersection of two lines, which is trivial. Not sure how computationally intensive of an algorithm this would be, and there would clearly be some error involved, and you will need to determine if the error is tolerable for you.

  • Dialog box says-"Bridge encountered a problem and is unable to read the cache. ... purge central cache" For one, I can't find the central cache and two, I've purged the cache in bridge. Shouldn't that help.

    Our Bridge has been acting very strange. It keeps giving a dialog box of "Bridge encountered a problem and is unable to read the cache. ... purge central cache" For one, I can't find the central cache and two, I've purged the cache in bridge. Shouldn't that help? There's just all kinds of weird stuff going on. I suppose it does have something to do with the central cache, so maybe someone can tell me where to find it.
    When I use the burn/dodge tool sometimes it drags and staggers and takes forever to complete whatever I'm burning/dodging. When I try to delete an image from the dock, it won't disappear but it won't display either.
    Any help would be appreciated.

    The Central Cache is the Bridge Cache.
    It's referred as the Central Cache to differentiate it from the individual folder's cache or even the individual image cache.

  • [How-to] Find the middle point between sides of two distant objects.

    [In reference to my attachment]
    I would like to find the middle point between object A's right-most segment (in green) and object B's left-most segment (in blue), quickly, effectively and reliably.
    Ideally, there's a function i'm not familiar with that exists . I would rather not resort to having to create more objects to "figure out" the middle point manually, so-to speak.

    Dandreu,
    In a more general case than assumed in the first post, if you wish to have an actual key point, you may:
    1) Direct Select each of the path segments in question and Ctrl/Cmd+C+F+X+F,
    2) Select either and rotate it by 180 degrees,
    3) Object>Blend>Blend Options, with 1 Step, then Object>Blend>Make, then Object>Blend>Expand,
    4) Select the line in the middle and Object>Path>Add Anchor Point.
    You may also do a similar way where you add an Anchor Point at the middle of the segments and ClickDrag with the Line Segment Tool between them, but that is a bit destructive.

  • Help me in finding the entry points in the source code of java.....

    hi...
    I want to design a compilation server and apply some of the optimization technique's like inlining, SSA and others.
    So i require to find the entry points in source code from where i can include my code and check the performance of the program at level it is performing .
    Please help in this problem....
    and i also like to know what are hot methods in java context?

    BigDaddyLoveHandles wrote:
    Do you even know Java? Why not just let the HotSpot optimization do its thing?Good point, I would try either of two things.
    If you have a good understanding of Java internals and are confident you could optimise code better, I suggest you contribute to the OpenJDK and we can all benefit.
    Otherwise I suggest you try using the optimisation built into the compiler and the JVM.
    Note: the JVM optimises the code dramatically in ways most normal people won't have thought possible.
    The compiler doesn't optimise the code so much as it leaves this job to the JVM.
    Two examples;
    - say you call a small method often. The JVM can inline this method for you. (the same way a compiler would) However say this method can be over-ridden and later your program calls a different implementation, it can inline both methods even if the new method in a new class didn't exist when the first method was inlined.
    - In a 32-bit JVM, 32-bit registers and references are used. In a 64-bit JVM 64-bit registers and references are used without needing to recompile the code. However there is a third option of using 32-bit references in a 64-bit JVM. In this case, it assumes the bottom 3 bits are always 000 so it shifts the reference down 3 bits allowing you to access 32 GB using 32-bit references. Again, you can use this with libraries which were compiled before 64-bit JVMs were available.

  • How to find a second point on a line given a point and distance

    Hi All,
    My requirement is: Given a point on a line and distance, I have to find the second point. All geometries are in LRS.
    I tried using SDO_LRS.LOCATE_PT, it is returning the second point from the start of the segment but I want to locate the point from the given start point. Kindly suggest in how to solve this.
    SQL Used:
    SELECT SDO_LRS.LOCATE_PT(a.shape, m.diminfo, 9, 0)
    FROM lrs_access_fiber a, user_sdo_geom_metadata m
    WHERE m.table_name = 'LRS_ACCESS_FIBER' AND m.column_name = 'SHAPE' AND a.unique_id = 1996;
    Regards
    Venkat

    Hi Luc,
    Thanks for the information. I have implemented this in a slightly different way like:
    1. Firstly, found the distance (Distance_a of the point selected from the start point of the segment using:
    SELECT SDO_LRS.GET_MEASURE(SDO_LRS.PROJECT_PT(a.shape, m.diminfo,MDSYS.SDO_GEOMETRY(2301, 8307, NULL, MDSYS.SDO_ELEM_INFO_ARRAY(1, 1, 1), MDSYS.SDO_ORDINATE_ARRAY(xa,ya, NULL)) ), m.diminfo ) into Distance_a FROM LRS_ACCESS_FIBER a, user_sdo_geom_metadata m WHERE m.table_name = 'LRS_ACCESS_FIBER' AND m.column_name = 'SHAPE' AND a.unique_id = Input_Fiber_Id;
    2. Then added the given distance (b) to this computed distance (Distance_a ) to get the distance of the second point (Distance_b).
    Distance_b := abs (Distance_a + b);
    3. Then used SDO_LRS.LOCATE_PT with offset=0 and distance=Distance_b to get the second point.
    select SDO_LRS.LOCATE_PT(a.shape, distance_pt, 0) into point_geometry from LRS_ACCESS_FIBER a where a.unique_id = input_fiber_id;
    Please give your inputs and feedback.
    Regards
    Venkat

  • Drawing object on the intersections point of 2 lines.

    hi guys, im very new in actionscrip , please give me some guidance.
    i'm doing this project , about 2 lines intersecting each other(the 2 lines are not always on the same position) . i try to find the intersections point using collision detection method but how do i place an object on the intersections point?
    if(line1.hitTestObject(line2)) //  so this is how we find the intersection point but we do not know how to draw/place an object on the  intersection point.

    then it's easier to calculate the intersection algebraically:
    function intersectionF(x1:Number,y1:Number,x2:Number,y2:Number,x3:Number,y3:Number,x4:Number,y4:Number):Array {
         if (x1==x2) {
              if (x3==x4) {
                   if (x1==x3) {
                        return ["line1"];
                   } else {
                        return [null];
              } else {
                   // line 1 vert, line 2 not
                   var m2:Number = (y3-y4)/(x3-x4);
                   var b2:Number = y3-m2*x3;
                   return [x1,m2*x1+b2];
         } else {
              // line 1 not vert
              if(x3==x4){
                   // line 2 vert
                   var m1:Number = (y1-y2)/(x1-x2);
                   var b1:Number = y1-m1*x1;
                   return [x3,m1*x3+b1];
              } else {
                   // line 2 not vert
                   m1 = (y1-y2)/(x1-x2);
                   b1 = y1-m1*x1;
                   m2 = (y3-y4)/(x3-x4);
                   b2 = y3-m2*x3;
                   var x:Number = (b2-b1)/(m1-m2);
                   return [x,m1*x+b1];

  • LGBD390 blu-ray cannot find the access point of WRT160N/3.

    I have been trying to set up the wireless connection to be able to view streamed movies from netflix through my LGBD390 blu-ray player.  I have successfully connected the wireless router to my Embarq router.  When I check status, it says it is enabled and connection is o.k.  I have been on the phone with Linksys (and was charged $9.99 which did not solve my problem).  I also have chatted and so far that has not worked either.  I have downloaded the upgrade for the firmware.  No matter what I do, the blu-ray cannot find the access point of the router.
    Can you help?

    thank you for your responsse Wizzard, but there are things I need to change that I don't know how to do.  I have no idea  how to assign static ip, subnet and gateway on the blu-ray.  When I went to the link , it was actually for  adifferent router than mine.  I have a WRT160N/v3.  I also did not know what to put in the protocol.  and if I should just put the number in the beg. and ending.   I also don't think I have an ethernet adapter.  Maybe you could give me more information.  Thanks in advance.

  • TS2972 used to be able to pick out which songs in iTunes in my computer were not on a 2nd computer on homeshare in iTunes 10.  Now with V11, cant find the button that compares two libraries and finds the songs that are different.  Anyone know how to do th

    Used to be able to pick out which songs in iTunes in my computer were not on a 2nd computer on homeshare in iTunes 10.  Now with V11, cant find the button that compares two libraries and finds the songs that are different.  Anyone know how to do this now?

    Jneklason wrote:
    ~snip~
    I know this email is confusing and really hard to understand...perhaps now you will know how i've been feeling--lost and confused with all the mis-information, with a hit and miss phone, and out of time with all the 1 1/2 hr to 2 hrs EACH wasted on this issue.
    On top of all this, I can't even find out how to file a complaint with anyone higher up than Customer Service.
    I hate to tell you this, but you didn't write an email. You wrote a discussion post on the Verizon Wireless Community forum which is a public peer to peer forum. Unfortunately since you didn't mark your post as a question, the VZW reps that roam this community won't ever see your post. Before you re-post it, don't. Duplicate posts get removed from the community.
    I see there were several missteps both by the reps and yourself in your post. First you should have insisted on returning the phone within the 14 day return policy period. Second which Samsung Galaxy mini model did you purchase? The S3 mini or the S4 mini? Did you do any research prior to deciding on this device. The reps at that time deflected the easiest course of action, by trying to get you to replace the phone under insurance instead of returning the phone. The Early Edge payment option requires the current phone on the line using the early Edge must be returned to Verizon Wireless. Did you once considered going to a third party site like Swappa to purchase a gently used device for your daughter?

  • SAP Script : to display the material description in two lines

    Hi All,
    I'm working on scripts.
    the material description field is been passed from my driver program ..into the script..
    Ex: &gs_final-maktx& ..
    There r a number of other fields to be displayed ...after this field ....
    Is there any option to split the 'Material description into two lines'?
    Ex: at present it is :
    This is material description
    Requirement is:
    This is material
    description
    I mean that there a number of field berfore and after this field......in the same line
    I need to jst split the materia description ...& make it to appear in two lines.....!!
    Expecting your suggestions....
    Edited by: vidya vidya on Nov 11, 2008 3:17 PM
    Edited by: vidya vidya on Nov 11, 2008 3:20 PM

    FM TEXT_SPLIT ?
    ..but i handled this by code.
    DATA:      zzboldsx(18) TYPE c,
          zzboldsx2(18) TYPE c,
          zzboldsx3(18) TYPE c,
          zzboldsx4(18) TYPE c.
    DATA: i_lines TYPE STANDARD TABLE OF tline WITH HEADER LINE ,
            r_lines TYPE tline,
            v_cnt LIKE sy-tabix.
    CALL FUNCTION 'READ_TEXT'
        EXPORTING
          client                  = sy-mandt
          id                      = stxh-tdid
          language                = stxh-tdspras
          name                    = name
          object                  = stxh-tdobject
        TABLES
          lines                   = i_lines[]
        EXCEPTIONS
          id                      = 1
          language                = 2
          name                    = 3
          not_found               = 4
          object                  = 5
          reference_check         = 6
          wrong_access_to_archive = 7
          OTHERS                  = 8.
      IF sy-subrc = 0.
    * Only 4 lines of Header text supported. Can add if needed
        LOOP AT i_lines INTO r_lines.
          CONDENSE r_lines-tdline NO-GAPS.
          v_cnt = v_cnt + 1.
          CASE v_cnt.
            WHEN 1.
              zzboldsx = r_lines-tdline.
            WHEN 2.
              zzboldsx2 = r_lines-tdline.
            WHEN 3.
              zzboldsx3 = r_lines-tdline.
            WHEN 4.
              zzboldsx4 = r_lines-tdline.
            WHEN OTHERS.
              EXIT.
          ENDCASE.
    *   zzbolDSX =  i_lines-tdline .
        ENDLOOP.

  • I just update itunes for latest version. Now I can't open it on win 7- 64 bits. I get an erro: Cant find the entry point of the procudere sqlite_wal_checkpoint.. Windows error 127.. help!!!

    I just update itunes for latest version. Now I can't open it on windows 7- 64 bits. I get an erro: Cant find the entry point of the procudere sqlite_wal_checkpoint.. Windows error 127. What can I do...???

    How did you fix this?

  • How to find the structural difference between two tables

    Hi all,
    How to find the structural difference between two tables .
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
    PL/SQL Release 11.1.0.7.0 - Production
    CORE 11.1.0.7.0 Production
    TNS for 32-bit Windows: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - Production
    Thanks,
    P Prakash

    you could try something similar to this, for each table pair that you want to compare:
    SELECT 'TABLE_A has these columns that are not in TABLE_B', DIFF.*
      FROM (
            SELECT  COLUMN_NAME, DATA_TYPE, DATA_LENGTH
              FROM all_tab_columns
             WHERE table_name = 'TABLE_A'
             MINUS
            SELECT COLUMN_NAME, DATA_TYPE, DATA_LENGTH
              FROM all_tab_columns
             WHERE table_name = 'TABLE_B'
          ) DIFF
    UNION
    SELECT 'TABLE_B has these columns that are not in TABLE_A', DIFF.*
      FROM (
            SELECT COLUMN_NAME, DATA_TYPE, DATA_LENGTH
              FROM all_tab_columns
             WHERE table_name = 'TABLE_B'
             MINUS
            SELECT COLUMN_NAME, DATA_TYPE, DATA_LENGTH
              FROM all_tab_columns
             WHERE table_name = 'TABLE_A'
          ) DIFF;that's assuming, column_name, data_type and data_length are all you want to compare on.

  • Finding the number of Non-Blank Line in a File

    Does anyone know the command or how to find the number of non-blank lines in a text file? I have the program already reading characters, words, and total lines.
              BufferedReader FileIn = new BufferedReader( new FileReader( selectedFile ) );
                   Scanner scanWords = new Scanner (selectedFile);
                             String thisToken = "";
                             int numWords = 0;
                             while (scanWords.hasNext())
                             thisToken = scanWords.next();
                             numWords++;
         System.out.println("Total number of words: " + numWords);
         Scanner scanLines = new Scanner (selectedFile).useDelimiter("\n");
                             String thisToken2 = "";
                             int numLines = 0;
                             while (scanLines.hasNext())
                             thisToken2 = scanLines.next();
                             numLines++;
         System.out.println("Total number of lines: " + numLines);
         Scanner scanChars = new Scanner (selectedFile).useDelimiter("");
                             String thisToken3 = "";
                             int numChars = 0;
                             while (scanChars.hasNext())
                             thisToken2 = scanChars.next();
                             numChars++;
         System.out.println("Total number of characters: " + numChars);
                   FileIn.close();
              }

    Use BufferedReader#readLine() instead. Read the file once and process each line once.

  • Need help to find the "leading point size"

    Hi,
    I need help to find the "leading point size".
    Any para style leading is more than 2 points of my font size, I need the alert message "Its more than 2 points for your font size". For instance my para font size is 10 here my leading should be 12 points rather than its 14 points, I need the alert message.
    Is this possible by script?
    by
    hasvi

    Hi Hasvi,
    Try this.
    var doc = app.activeDocument;
    var texts = doc.stories.everyItem().textStyleRanges.everyItem().getElements();
    var pstyle = "Following paragraph styles have more leadings:\r\r";
    for(var i=0;i<texts.length;i++)
        var ps = texts[i].pointSize;
        if(texts[i].leading > ps + 2)
            pstyle += texts[i].appliedParagraphStyle.name;
    alert(pstyle)
    If it is correct than mark the answer as correct and don't mark your question as correct answer.
    Regards,
    Chinna

Maybe you are looking for

  • Video and audio (in one direction only) deteriorate after about 90 seconds

    I begin a two-way video chat as normal, both parties can see and hear clearly. After about one and a half minutes of normal video chat, the person on the other end suddenly starts getting a highly pixelated image of me, and they start to lose chunks

  • How to: Create a folder directly under the KM content 'Root' directory

    I need to create a new folder directly under the 'root' directory of the KM content... If I go to the KM root directory and click on any of the folders in it, I can create new folders. For example: clicking on the 'documents' folder. Opening it, I ca

  • Weblogic server problem

    HI i am accessing ejb bean from java client. in that i am using local host for accessing ejb in intialcontext factory for jndi loop at that time it is giving following error javax.naming.CommunicationException [Root e xception is java.net.ConnectExce

  • HT4623 ios 6.1.3 problem restart

    ios 6.1.3 yukledim telefonum siyal gelince kapanior bazen tlf acılıo biri arayınca kapanior bana acilen yardım edin numaram 0533 885 08 09

  • Please give answers for this. This is urgent

    1)can u create internal table dynamically ?how? 2)what is the model dialogbox? 3)can u create more than one selectionscreen 4)in which event we will be writing authorization object.