Page 1 of 2 12 LastLast
Results 1 to 25 of 28

Thread: Compass Math

  1. #1
    Join Date
    Feb 2006
    Location
    Belgium
    Posts
    3,137
    Mentioned
    3 Post(s)
    Quoted
    5 Post(s)

    Default Compass Math

    Well, I'm going to kick the compass and minimap angle functions out of SCAR soon because I feel that it's more convenient for the scripters to make them themselves so they can also be fast and easily updated. And I'm confident that they will do a great job for it, so I'm releasing the math algorithm for my compass function. (Not saying it's better than what people are currently using, but it might offer some insight...

    SCAR Code:
    dX1 := mx - tx;
    dY1 := my - ty;
    dX2 := mx - pp.x;
    dY2 := my - pp.y;
    tmp := ((dX1 * dX2) + (dY1 * dY2)) / (Sqrt(Sqr(dX1) + Sqr(dY1)) * Sqrt(Sqr(dX2) + Sqr(dY2)));
    Result := Abs(ArcCos(tmp) - Pi);
    if pp.x > mx then Result := 2 * Pi - Result;

    mx and my are the coordinates of the center point of the compass.
    tx and ty are the coordinates of the middle, top point of the compass. (The highest point on the compass, at the same x coordinate as the center)
    pp is the point at which the South indicator is located.

    As some might've noticed, my algorithm is based on the law of cosines.

    (Note that this is for calculating the radians)
    (You might also have noticed that "dX1 := mx - tx;" will always be 0, but I just made it that way in case I'd ever need to change it)

    if you leave out dX1 you'd get:
    SCAR Code:
    dY1 := my - ty;
    dX2 := mx - pp.x;
    dY2 := my - pp.y;
    tmp := (dY1 * dY2) / (dY1 * Sqrt(Sqr(dX2) + Sqr(dY2)));
    Result := Abs(ArcCos(tmp) - Pi);
    if pp.x > mx then Result := 2 * Pi - Result;

  2. #2
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    Always been wondering how you did. Nice, using cosine laws.



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  3. #3
    Join Date
    Sep 2006
    Posts
    457
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    lol, don't even know what that means. Just guess i'm not smart enough
    Finished my curser ---> it's in mage section.

  4. #4
    Join Date
    Jul 2007
    Location
    St. Louis, Missouri, USA.
    Posts
    575
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by jesus45 View Post
    lol, don't even know what that means. Just guess i'm not smart enough
    I understand it, but hopefully SRL will just take over for all the rs_GetCompassAngle and other functions using this math... It will save me a few headaches.


    ...So we would have to input pp since that changes? Thats the only problem I'm having with trying to fix the MakeCompass() error due to the rs_GetCompassAngle begin 'broken'.
    -You can call me Mick-



  5. #5
    Join Date
    May 2006
    Location
    Amsterdam
    Posts
    3,620
    Mentioned
    5 Post(s)
    Quoted
    0 Post(s)

    Default

    Advanced.
    Verrekte Koekwous

  6. #6
    Join Date
    Jul 2007
    Location
    St. Louis, Missouri, USA.
    Posts
    575
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    ...I figured out a way for it to work but its not 100% accurate. Use a dtm of the N and reflect its coords across the centerpoint to find the South indicator location.
    -You can call me Mick-



  7. #7
    Join Date
    Feb 2006
    Location
    Belgium
    Posts
    3,137
    Mentioned
    3 Post(s)
    Quoted
    5 Post(s)

    Default

    Quote Originally Posted by mickaliscious View Post
    ...I figured out a way for it to work but its not 100% accurate. Use a dtm of the N and reflect its coords across the centerpoint to find the South indicator location.
    I did a similar thing when I first developed the function, but it caused it to mess up in certain situation, it used findcolor rather than a dtm though. In the manual I thank ruler and geno for parts of the compass function, that's actually the part to get that point, it's uses a piece of code converted from ibot, since ibot seemed to use skipboxes which I had written myself once and later implemented in SCAR, so it was easy to modify to use my own skipboxfunctions. But there's many ways to do it really...

  8. #8
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    6,136
    Mentioned
    28 Post(s)
    Quoted
    17 Post(s)

    Default

    Good of you to skip this from SCAR, and thanks for sharing. You are right, it should not be there in the first place. SCAR is so much more versatile...
    SRL is a Library of routines made by the SRL community written for the Program Simba.
    We produce Scripts for the game Runescape.

  9. #9
    Join Date
    Dec 2006
    Location
    Banville
    Posts
    3,914
    Mentioned
    12 Post(s)
    Quoted
    98 Post(s)

    Default

    ...


    My head almost blew up. Back to wikipedia.
    The jealous temper of mankind, ever more disposed to censure than
    to praise the work of others, has constantly made the pursuit of new
    methods and systems no less perilous than the search after unknown
    lands and seas.

  10. #10
    Join Date
    Dec 2007
    Posts
    2,112
    Mentioned
    71 Post(s)
    Quoted
    580 Post(s)

    Default

    wow this is the fist time iv seen freddy post

  11. #11
    Join Date
    Sep 2006
    Location
    include srl/srl.scar ( aussie)
    Posts
    2,875
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    that post was a pure spam post that post had nothing to do with the topic,


    Freddy THis is very interesting, will it be in the next scar.?

  12. #12
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    6,136
    Mentioned
    28 Post(s)
    Quoted
    17 Post(s)

    Default

    Quote Originally Posted by nicbaz View Post
    that post was a pure spam post that post had nothing to do with the topic,


    Freddy THis is very interesting, will it be in the next scar.?

    "Quote of the Day"
    SRL is a Library of routines made by the SRL community written for the Program Simba.
    We produce Scripts for the game Runescape.

  13. #13
    Join Date
    Dec 2006
    Posts
    723
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by WT-Fakawi View Post
    "Quote of the Day"
    Epic.

  14. #14
    Join Date
    Dec 2006
    Location
    Banville
    Posts
    3,914
    Mentioned
    12 Post(s)
    Quoted
    98 Post(s)

    Default

    Fakawi: Epic Win.

    Nicbaz: Epic Fail.

    R0b0t1: Head blown up by super maths, he now goes to wikipedia to make sense of the situation.
    The jealous temper of mankind, ever more disposed to censure than
    to praise the work of others, has constantly made the pursuit of new
    methods and systems no less perilous than the search after unknown
    lands and seas.

  15. #15
    Join Date
    Jul 2007
    Location
    St. Louis, Missouri, USA.
    Posts
    575
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by R0b0t1 View Post
    Fakawi: Epic Win.

    Nicbaz: Epic Fail.

    R0b0t1: Head blown up by super maths, he now goes to wikipedia to make sense of the situation.
    Its just trigonometry dude. Theres no super maths there.
    -You can call me Mick-



  16. #16
    Join Date
    Aug 2007
    Location
    In Your Front Door!
    Posts
    371
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    It will take a while to get used to

    MakeCompass(" ") is like so easy!
    This is for Jagex!

    My Public Scripts
    Simple AutoTalker
    Face Maker

  17. #17
    Join Date
    Dec 2006
    Location
    Banville
    Posts
    3,914
    Mentioned
    12 Post(s)
    Quoted
    98 Post(s)

    Default

    if (Trigonometry.Length >= 10) { cout "Dubya Tee Eff Mate?"; };
    The jealous temper of mankind, ever more disposed to censure than
    to praise the work of others, has constantly made the pursuit of new
    methods and systems no less perilous than the search after unknown
    lands and seas.

  18. #18
    Join Date
    Feb 2007
    Location
    Het ademt zwaar en moedeloos vannacht.
    Posts
    7,211
    Mentioned
    26 Post(s)
    Quoted
    72 Post(s)

    Default

    Quote Originally Posted by WT-Fakawi View Post
    "Quote of the Day"
    Amen

    [/offtopic]

    So, can I use it like this? Get north indicator, use skipboxes for west and east, then find south and calculate.
    I made a new script, check it out!.

  19. #19
    Join Date
    May 2007
    Location
    Ontario
    Posts
    361
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Well I'm trying this now I feel like I'm doing something wrong...

    SCAR Code:
    function GetCompassDegrees: extended;
    var dx1, dx2, dy1, dy2: integer;
        tmp: extended;
        pp: TPoint;
    begin
      pp.x := 557;
      pp.y := 24;
      dX1 := 543 - 543;
      dY1 := 24 - 8;
      dX2 := 543 - pp.x;
      dY2 := 24 - pp.y;
      tmp := ((dX1 * dX2) + (dY1 * dY2)) / (Sqrt(Sqr(dX1) + Sqr(dY1)) * Sqrt(Sqr(dX2) + Sqr(dY2)));
      Result := Abs(ArcCos(tmp) - Pi);
      if pp.x > 544 then Result := 2 * Pi - Result;
    end;

    Now that results in 4.71238898038469 so is there something I have to do after? I was thinking it would be more around 270 degrees.

    What am I doing wrong?

    Edit: Ok after I tried this:

    SCAR Code:
    function GetCompassRadians: extended;
    var dx2, dy1, dy2: integer;
        tmp: extended;
        pp: TPoint;
    begin
      pp.x := 557;
      pp.y := 24;
      dY1 := 24 - 8;
      dX2 := 543 - pp.x;
      dY2 := 24 - pp.y;
      tmp := (dY1 * dY2) / (dY1 * Sqrt(Sqr(dX2) + Sqr(dY2)));
      Result := Abs(ArcCos(tmp) - Pi);
      if pp.x > 543 then Result := 2 * Pi - Result;
    end;

    However guess what? I got 4.71238898038469...

  20. #20
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    Doh. You use nothing but constants.



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  21. #21
    Join Date
    Feb 2006
    Location
    Belgium
    Posts
    3,137
    Mentioned
    3 Post(s)
    Quoted
    5 Post(s)

    Default

    TGWGO, you need to convert it to degrees

    SCAR Code:
    function GetCompassDegrees: Extended;
    begin
      Result := Degrees(GetCompassRadians);
    end;

    It was originally designed to work with degrees, but I changed it to radians


    Quote Originally Posted by mickaliscious View Post
    Its just trigonometry dude. Theres no super maths there.
    I have to agree with that

  22. #22
    Join Date
    May 2007
    Location
    Ontario
    Posts
    361
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Freddy1990 View Post
    TGWGO, you need to convert it to degrees

    SCAR Code:
    function GetCompassDegrees: Extended;
    begin
      Result := Degrees(GetCompassRadians);
    end;

    It was originally designed to work with degrees, but I changed it to radians



    I have to agree with that
    Thanks so I'm doing nothing wrong? Awesome...

    @Wizzup?: I think only the TPoints need to be changed so I didn't make them constants.

    FTW works now...Now to make it find the south indicator...Not 100% sure of how to go about this...

  23. #23
    Join Date
    Dec 2006
    Location
    utah
    Posts
    1,427
    Mentioned
    2 Post(s)
    Quoted
    7 Post(s)

    Default

    I just did

    SCAR Code:
    {-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
      function GetCompassAngleDegrees: extended;
      By: SKy Scripter
      Description: Gets The Mini Map Degrees Ranging From 0 - 360
      Note: I Do Know That In ArcTan2, I Have The X Where The Y Should be.
    =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-}

    function GetCompassAngleDegrees: extended;
    var
       mx, my: Integer;
       P: TPointArray;
    begin
       FindColorsTolerance(P, 1911089, 520, 5, 560, 45, 0);
       TPAAverage(P, mx, my);
       if (Mx <> 0) then
        Result := FixD( -Degrees(ArcTan2(543 - mx, 24 - my)) );
    end;
    Co Founder of https://www.tagcandy.com

  24. #24
    Join Date
    Sep 2007
    Posts
    41
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Urgh, my head is spinning, but i think a few more hours and I'll be able to understand this thing ( trigonometry is something that would have been taught next year, but i switched back from the USA to Germany, and here all we are learning are quadratic equations {not sure how to spell it in english}, so trigonometry is still an unkown area for me {I'm only a 9th grader atm}). But still, thanks a lot, will be a nice challenge.
    http://www.fenjer.com/adnan/SRL/23/1...%20Chopper.png
    Well, it is finished, but it is too unsecure and it doesn't always work properly (1 out of 3 attempts fail), So I will stop scripting for a while, focusing on learning new functions and procedures to make this safer.

  25. #25
    Join Date
    Feb 2006
    Location
    Belgium
    Posts
    3,137
    Mentioned
    3 Post(s)
    Quoted
    5 Post(s)

    Default

    Quote Originally Posted by SKy Scripter View Post
    I just did

    SCAR Code:
    {-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
      function GetCompassAngleDegrees: extended;
      By: SKy Scripter
      Description: Gets The Mini Map Degrees Ranging From 0 - 360
      Note: I Do Know That In ArcTan2, I Have The X Where The Y Should be.
    =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-}

    function GetCompassAngleDegrees: extended;
    var
       mx, my: Integer;
       P: TPointArray;
    begin
       FindColorsTolerance(P, 1911089, 520, 5, 560, 45, 0);
       TPAAverage(P, mx, my);
       if (Mx <> 0) then
        Result := FixD( -Degrees(ArcTan2(543 - mx, 24 - my)) );
    end;
    that's another way to do it

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Compass
    By nemolorn in forum OSR Help
    Replies: 6
    Last Post: 07-23-2008, 03:32 AM
  2. New Compass
    By insanomano in forum News and General
    Replies: 2
    Last Post: 01-20-2008, 05:47 PM
  3. Compass
    By Jackrawl in forum OSR Help
    Replies: 6
    Last Post: 10-18-2007, 11:33 PM

Posting Permissions

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