Results 1 to 18 of 18

Thread: Intersect

  1. #1
    Join Date
    Oct 2006
    Location
    C:\Program Files\SCAR 2.03
    Posts
    1,194
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Intersect

    Finds where LineA and LineB intersect. I'm keeping them as TBoxs since there isn't anything called TLine... at least not that I know of. Maybe TPoints would be better but this served it purpose so I thought I'd share it with the community.

    SCAR Code:
    program New;
    var
      Pt: TPoint;

    function Intersect(LineA, LineB: TBox): TPoint;
    var
      A, B, C: array [0..1] of Integer;
      Det: Integer;
    begin
      A[0]:= LineA.y2 - LineA.y1;
      B[0]:= LineA.x1 - LineA.x2;
      C[0]:= (A[0] * LineA.x1) + (B[0] * LineA.y1);
     
      A[1]:= LineB.y2 - LineB.y1;
      B[1]:= LineB.x1 - LineB.x2;
      C[1]:= (A[1] * LineB.x1) + (B[1] * LineB.y1);
     
      Det:= (A[0] * B[1]) - (A[1] * B[0]);
      if(Det <> 0)then
        begin
          Result.x:= ((B[1] * C[0]) - (B[0] * C[1])) div Det;
          Result.y:= ((A[0] * C[1]) - (A[1] * C[0])) div Det;
        end else
          begin
            Result.x:= -1;
            Result.y:= -1;
          end;
    end;


    begin
    Pt:= Intersect(IntToBox(0, 0, 4, 4), IntToBox(4, 0, 0, 4));
    Writeln('x:= ' + inttostr(Pt.x));
    Writeln('y:= ' + inttostr(Pt.y));
    end.
    [FONT="Garamond"][SIZE="3"]
    Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like. My crime is that of outsmarting you, something that you will never forgive me for.
    [/SIZE][/FONT][URL="http://www.villavu.com/forum/forumdisplay.php?f=125"][IMG]http://i40.tinypic.com/r1lzdv.jpg[/IMG][/URL]

  2. #2
    Join Date
    May 2007
    Location
    Some where fun.
    Posts
    2,891
    Mentioned
    1 Post(s)
    Quoted
    5 Post(s)
    Quote Originally Posted by Special Ed View Post
    Finds where LineA and LineB intersect. I'm keeping them as TBoxs since there isn't anything called TLine... at least not that I know of. Maybe TPoints would be better but this served it purpose so I thought I'd share it with the community.

    SCAR Code:
    program New;
    var
      Pt: TPoint;

    function Intersect(LineA, LineB: TBox): TPoint;
    var
      A, B, C: array [0..1] of Integer;
      Det: Integer;
    begin
      A[0]:= LineA.y2 - LineA.y1;
      B[0]:= LineA.x1 - LineA.x2;
      C[0]:= (A[0] * LineA.x1) + (B[0] * LineA.y1);
     
      A[1]:= LineB.y2 - LineB.y1;
      B[1]:= LineB.x1 - LineB.x2;
      C[1]:= (A[1] * LineB.x1) + (B[1] * LineB.y1);
     
      Det:= (A[0] * B[1]) - (A[1] * B[0]);
      if(Det <> 0)then
        begin
          Result.x:= ((B[1] * C[0]) - (B[0] * C[1])) div Det;
          Result.y:= ((A[0] * C[1]) - (A[1] * C[0])) div Det;
        end else
          begin
            Result.x:= -1;
            Result.y:= -1;
          end;
    end;


    begin
    Pt:= Intersect(IntToBox(0, 0, 4, 4), IntToBox(4, 0, 0, 4));
    Writeln('x:= ' + inttostr(Pt.x));
    Writeln('y:= ' + inttostr(Pt.y));
    end.
    Wow, never thought of that idea

  3. #3
    Join Date
    Jan 2007
    Location
    Kansas
    Posts
    3,760
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    Did the site I post help?


  4. #4
    Join Date
    Oct 2006
    Location
    C:\Program Files\SCAR 2.03
    Posts
    1,194
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Bobarkinator View Post
    Did the site I post help?
    Yes, Yes it did... except they did it in C++ and had some stuff missing out. I had an idea of how to do it but this just helped me execute it.
    [FONT="Garamond"][SIZE="3"]
    Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like. My crime is that of outsmarting you, something that you will never forgive me for.
    [/SIZE][/FONT][URL="http://www.villavu.com/forum/forumdisplay.php?f=125"][IMG]http://i40.tinypic.com/r1lzdv.jpg[/IMG][/URL]

  5. #5
    Join Date
    Jan 2007
    Location
    Kansas
    Posts
    3,760
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    Ah, just wondering. Looks like you did a find job though.


  6. #6
    Join Date
    Oct 2006
    Location
    C:\Program Files\SCAR 2.03
    Posts
    1,194
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Bobarkinator View Post
    Ah, just wondering. Looks like you did a find job though.
    Thank you! I wonder if anyone other than me and bullzeye will actually use it though?
    [FONT="Garamond"][SIZE="3"]
    Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like. My crime is that of outsmarting you, something that you will never forgive me for.
    [/SIZE][/FONT][URL="http://www.villavu.com/forum/forumdisplay.php?f=125"][IMG]http://i40.tinypic.com/r1lzdv.jpg[/IMG][/URL]

  7. #7
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by Special Ed View Post
    Thank you! I wonder if anyone other than me and bullzeye will actually use it though?
    It's always good to have lying around

  8. #8
    Join Date
    Jul 2007
    Location
    Right now? Chair.
    Posts
    8,488
    Mentioned
    3 Post(s)
    Quoted
    12 Post(s)

    Default

    what were you thinking of using it for when you made it? just cuious.

    ~RM

    I & I know Zion. It is in the spirit, body and mind of every one of us
    RMouse(obj: TMSIObject): boolean;

  9. #9
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    what does it do?

    I feel left behind

  10. #10
    Join Date
    Jan 2007
    Location
    Kansas
    Posts
    3,760
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    Quote Originally Posted by Zytex! View Post
    what does it do?

    I feel left behind

    Finds the point where 2 lines intersect.


  11. #11
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    *dictionary-time* Aha! thanks

    kinda cool... :P

  12. #12
    Join Date
    Mar 2007
    Posts
    3,116
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    why do I think this is for msi...

  13. #13
    Join Date
    Oct 2006
    Location
    C:\Program Files\SCAR 2.03
    Posts
    1,194
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Mylesmadness View Post
    why do I think this is for msi...
    Because I'm to un-motivated (Better word for lazy) to do any work that isn't for MSI right now

    @Rasta - Me and bullzeye are using it for a walking system he thought of. This is needed to find the center of the road.
    [FONT="Garamond"][SIZE="3"]
    Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like. My crime is that of outsmarting you, something that you will never forgive me for.
    [/SIZE][/FONT][URL="http://www.villavu.com/forum/forumdisplay.php?f=125"][IMG]http://i40.tinypic.com/r1lzdv.jpg[/IMG][/URL]

  14. #14
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    No difference but the name'll just suit better -

    SCAR Code:
    Type
      TLine = Record
        x1, y1, x2, y2: Integer;
      end;

  15. #15
    Join Date
    Jan 2007
    Location
    Tennessee
    Posts
    642
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Here's the one i made for my 3DModel drawer thingy-
    SCAR Code:
    function Intersection(x1, y1, x2, y2, x3, y3, x4, y4: integer): TPoint;
    var
      Denom: integer;
    begin
      Denom:= ((y2 - y1) * (x3 - x4) - (y4 - y3) * (x1 - x2));
      if Denom = 0 then
      begin
        Result.x:= 0;
        Result.y:= 0;
        Exit;
      end;
      Result.x:=((x1 - x2) * (x4 * y3 - x3 * y4) - (x3 - x4) * (x2 * y1 - x1 * y2)) / Denom;
      Result.y:=((y4 - y3) * (x2 * y1 - x1 * y2) - (y2 - y1) * (x4 * y3 - x3 * y4)) / Denom;
    end;

  16. #16
    Join Date
    Oct 2006
    Location
    C:\Program Files\SCAR 2.03
    Posts
    1,194
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Heh... nice almost. That's literally the exact same thing just without the in-betweens I had.

    Oh well, I'll use your instead if you don't mind
    [FONT="Garamond"][SIZE="3"]
    Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like. My crime is that of outsmarting you, something that you will never forgive me for.
    [/SIZE][/FONT][URL="http://www.villavu.com/forum/forumdisplay.php?f=125"][IMG]http://i40.tinypic.com/r1lzdv.jpg[/IMG][/URL]

  17. #17
    Join Date
    Jan 2007
    Location
    Tennessee
    Posts
    642
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

  18. #18
    Join Date
    Apr 2007
    Location
    Australia
    Posts
    4,163
    Mentioned
    9 Post(s)
    Quoted
    19 Post(s)

    Default

    I could of used this in my Maths Methods SAC today apart from the fact i can do it by hand, lol

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •