Results 1 to 11 of 11

Thread: math error for midpoint formula

  1. #1
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default math error for midpoint formula

    SCAR Code:
    program New;
    {.include SRL/SRL.scar}
    var x, y: integer;


    {*******************************************************************************
    function getsymbolpos(symbol1, symbol2: string);
    By: akwardsaw, idea came from [ethan]
    Description: It finds the coords of 2 symbols, could be edited for more/less
    *******************************************************************************}

    procedure getsymbolpos(symbol1, symbol2: string);
    var
      sp1x, sp2x, sp1y, sp2y, sym1x: integer;
      sym2x, sym1y, sym2y: integer;
    begin
      if Findsymbol(sp1x, sp1y, symbol1) then
      begin
        Sym1x:= sp1x;
        sym1y:= sp1y;
        writeln('the x-coord of ' + symbol1 + ' is ' + inttostr(sym1x));
        writeln('the y-coord of ' + symbol1 + ' is ' + inttostr(sym1y));
      end;
      if Findsymbol(sp2x, sp2y, symbol2) then
      begin
        Sym2x:= sp2x;
        sym2y:= sp2y;
        writeln('the x-coord of ' + symbol2 + ' is ' + inttostr(sym2x));
        writeln('the y-coord of ' + symbol2 + ' is ' + inttostr(sym2y));
      end;
    end;
    {*******************************************************************************
    function Getsymbolmidpoint(var xm, ym: integer; symbol1, symbol2: string): integer;
    By: akwardsaw, idea came from [ethan]
    Description: It finds two symbol coords, and then finds the midpoint. Can be for map
                     walking, or a helper in getting coords for the minimap.
    *******************************************************************************}

    function Getsymbolmidpoint(var xm, ym: integer; symbol1, symbol2: string): integer;
    var
      sp1x, sp2x, sp1y, sp2y, sym1x: integer;
      sym2x, sym1y, sym2y, i: integer;
      xstep1, xstep2, ystep1, ystep2: integer;
      midpoint: array [0..1] of integer;
    begin
      begin
        if Findsymbol(sp1x, sp1y, symbol1) then
        begin
          Sym1x:= sp1x;
          sym1y:= sp1y;
        end;
        if Findsymbol(sp2x, sp2y, symbol2) then
        begin
          Sym2x:= sp2x;
          sym2y:= sp2y;
        end;
        begin
          xstep1:= Sym2x - sym1x
          xstep2:= xstep1 / 2;
          ystep1:= sym2y - sym1y;
          ystep2:= ystep1 / 2;
          midpoint[0]:= sym1x + xstep2;;
          midpoint[1]:= sym1y + ystep2;
          xm:= midpoint[0]
          ym:= midpoint[1]
          writeln('the midpoint of ' + symbol1 + ' and ' + symbol2 + ' is:');
          writeln('(' + inttostr(midpoint[0]) + ',' + inttostr(midpoint[1]) + ')');
          for i:= 0 to 1 do
          result:= midpoint[i];
        end;
      end;
    end;
    begin
      mousespeed:= 10;
      getsymbolmidpoint(x, y, 'quest', 'spin');
      mmouse(x, y, 0, 0);
    end.

    it all compiles, yet no matter what, i always get 0, 0 as midpoint coords
    Last edited by Awkwardsaw; 05-25-2009 at 11:07 PM.
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  2. #2
    Join Date
    Jan 2008
    Location
    California, US
    Posts
    2,765
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    SCAR Code:
    program New;

    var
      xstep1, xstep2, sym2x, sym1x, i, ystep1, ystep2, xmidp, ymidp, xm, ym, sym2y, sym1y, result2 : integer;
      symbol1, symbol2 : string;
      midpoint : array [0..1] of integer;

    begin
      Symbol1 := 'Symbol 1';
      Symbol2 := 'Symbol 2';
      sym2x := 500;
      sym2y := 500;
      sym1y := 500;
      sym1x := 500;
      XStep1:= Sym2X - Sym1X;//it subtracts point 1 from point 2
      XStep2:= XStep1 / 2;// divides that by 2
      YStep1 := Sym2Y - Sym1Y;//same as x
      YStep2 := YStep1 / 2;//same as x
      XMidP := Sym1X + XStep1;//self explanitory
      YMidP := Sym1Y + YStep2;//self explanitory
      MidPoint[0]:= XMidP;//needs to be an array to be set as result later on
      MidPoint[1]:= YMidP;//same
      XM := MidPoint[0];//sets the variable
      YM := MidPoint[1]//sets the variable
      Writeln('the midpoint of ' + Symbol1 + ' and ' + Symbol2 + ' is:'); //can edit these out
      Writeln('(' + IntToStr(MidPoint[0]) + ',' + IntToStr(MidPoint[1]) + ')'); //can edit out
      for i:= 0 to 1 do
        Result2 := MidPoint[i];
    end.

    If I'm not mistaken, you did not set the sym(1/2)x and sym(1/2)y variables.
    Last edited by Da 0wner; 05-25-2009 at 02:29 PM.

  3. #3
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    Quote Originally Posted by Da 0wner View Post

    Also why can't you just use the wizzy plugin function?
    that wouldn't be fun and also, i may have looked over it last time i was looking through the includes

    thanks though

    edit: sorry, i should have posted the whole function, symbol1, 2, sym2x, sym2y have been called earlier, and thats really the only changes i see. my bad. updated first post.
    Last edited by Awkwardsaw; 05-25-2009 at 02:30 PM.
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  4. #4
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    To find the average, you add then divide by 2 - it is the same for working out the midpoint of 2 tpoint's - average of x and average of y.

    Midpoint := Point((sym1.x + sym2.x) div 2, (sym1.y + sym2.y) div 2);

    edit: Just pointing out the obvious as you seem to do a whole lot extra for some unknown reason.
    Last edited by mixster; 05-25-2009 at 09:17 PM.
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  5. #5
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    well, i got a lot(and i mean a lot) of runtime errors when i tried do it all simple like you have it. i guess its because i forgot the point( and other stuff you added.

    i under stand it now
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  6. #6
    Join Date
    Jan 2008
    Location
    California, US
    Posts
    2,765
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Dude your formula works fine it is the exact same as mormonman's. His is just way shorter. Just use his . I tested them both, gave same results.

  7. #7
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    yeah, i was just about to post that. haha.(just trying to be nice )

    maby i should move the getsymbolpos into the getmidpoint one, that way the variables are all changed and saved in one procedure, and not 2 different ones

    edit: yeah, that worked. the only thing is i had to keep it formula spread out, because it had a bug in it

    +rep for both of you
    Last edited by Awkwardsaw; 05-25-2009 at 11:07 PM.
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

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

    Default

    pascal Code:
    Function MidPoint(x1, y1, x2, y2): TPoint;

    Begin
      Result.x := (x1 + x2) shr 1;
      Result.y := (y1 + y2) shr 1;
    End;

    Wat

  9. #9
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    Quote Originally Posted by n3ss3s View Post
    pascal Code:
    Function MidPoint(x1, y1, x2, y2): TPoint;

    Begin
      Result.x := (x1 + x2) shr 1;
      Result.y := (y1 + y2) shr 1;
    End;

    Wat
    like i say all the time, i fail(epicly) at simplicity
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  10. #10
    Join Date
    May 2009
    Location
    Texas
    Posts
    51
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    this was my idea i somewhat helped akw :P

  11. #11
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    haha i guess. it better be put to good use

    also, is this worth posting in either procedures/ functions or svn core/misc? it might be a good command if it gets worked on.
    Last edited by Awkwardsaw; 05-26-2009 at 12:12 AM.
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

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
  •