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

Thread: Need a way to calculate the angle and distance:

  1. #1
    Join Date
    Feb 2007
    Location
    PA, USA
    Posts
    5,240
    Mentioned
    36 Post(s)
    Quoted
    496 Post(s)

    Lightbulb Need a way to calculate the angle and distance:

    Hey, i need a way to calculate the Angle and the distance between point A and point B...


    I am going to use this to find an object on the mainscreeen by using a sick math

    i just don't know srls/scars function to get the distance and angle

    also EXPLAIN the angle if u know

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

    Default

    function Distance(x1, y1, x2, y2: Integer): Integer;
    Returns Distance between Points.

    for the angle things get more complicated.

    I'd suggest you get a third point, draw a triangle and then use cosine to get the angle.

    point 1: TP1
    point 2: TP2
    point 3: TP3 ; TP3.x := TP1.x ; TP3.y := TP2.y;

    Cos A = Distance(TP1, TP3) / Distance(TP1, TP2);
    Angle := ArcCos(Cos A);

    ~RM

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

  3. #3
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    i tried to do this with minimap :-\ i phailed...
    distance is distance(x1, y1, x2, y2): integer;

  4. #4
    Join Date
    Feb 2007
    Location
    PA, USA
    Posts
    5,240
    Mentioned
    36 Post(s)
    Quoted
    496 Post(s)

    Default

    Thanks RM!!!
    and marpis... erm thanks s'pose

    just took geometry so i think i follow...
    but the triangle has to be a a right triangle no?????????????????? <?>

    this is a pic of my idea so far... coment>>>

  5. #5
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    no, it doesnt need to be a right angle.

    You just need to know that all the angles will add up to 180 degrees, then do what RM said.

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

    Default

    PointA = a, PointB = b.

    Angle = Tangent ^ -1 * (Opposite / Adjacent);
    Angle = Tangent ^ -1 * ((b.y - a.y) / (b.x - a.x));

    Then just change over to Scar functions for it.
    It's just how you would do it without creating an extra TPoint. As it's a right angle, you just draw straight down from point B and straight across from point A. When they meet it creates the right angled triangle - the opposite side is equal to point B's y co-ordinate minus point A's y co-ordinate and similar situation for adjacent side.
    You may want to look at Scar's help file for additional trigonometry related functions - I believe there is one that takes in the opposite and adjacent distance to return the angle, which would handle it if the triangle has no width ie point A.x = point B.x, which would otherwise result in a divide by zero error. Likewise, Depending on which function you use you'll be returned the angle in radians or degrees, so you need to make sure you're using the appropriate one for that.
    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.

  7. #7
    Join Date
    Feb 2007
    Location
    PA, USA
    Posts
    5,240
    Mentioned
    36 Post(s)
    Quoted
    496 Post(s)

    Default

    lol, that won't give me the angle, i need the angle... that'd give me the legs or hypot yes... but i don't want them...

  8. #8
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    Exactly which angle are you looking for?

  9. #9
    Join Date
    Feb 2007
    Location
    PA, USA
    Posts
    5,240
    Mentioned
    36 Post(s)
    Quoted
    496 Post(s)

    Default

    the angle between mmcx and a point about sw of it
    the angle will change though but it should always be sw of the center(mmcx)

  10. #10
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    If there is anything that marks the spot on the Mini-Map it seems like a RadialWalk would work, right?

    Or is that not what your trying to do?

  11. #11
    Join Date
    Feb 2007
    Location
    PA, USA
    Posts
    5,240
    Mentioned
    36 Post(s)
    Quoted
    496 Post(s)

    Default

    i got stuck in the logic:

    angle := pow(Tan((hy-mmcy)/(hx-mmcx)), -1);
    Writeln(FloatToStr(angle));

    is that close???

    maybe i want the slope ill look into that more....


    @NCDS i am trying to find a spot on mm then convert that to the EXACT spot on ms
    im REALLY close now

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

    Default

    Tangent ^ -1 would be ArcTan and its variants in Scar - like I said, my post was just an extension of RM's post
    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.

  13. #13
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    oh boy, I haven't done Slope in forever. Atleast 3-5 years lol.

    In that code you have above, what does 'h' represent?

  14. #14
    Join Date
    Feb 2007
    Location
    PA, USA
    Posts
    5,240
    Mentioned
    36 Post(s)
    Quoted
    496 Post(s)

    Default

    hy and hx are the points of the point on mm im going after

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

    Default

    the 3rd point is not supposed to be random....

    TP1 := Point( 5, 10 );
    TP2 := Point( 20, 50);
    TP3 := Point(TP1.x, TP2.y);



    meh, on the picture it's actually TP3 := Point(TP2.x , TP1.y);
    works the same

    IT DOES HAVE TO BE A RIGHT TRIANGLE

    ~RM

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

  16. #16
    Join Date
    Feb 2007
    Location
    PA, USA
    Posts
    5,240
    Mentioned
    36 Post(s)
    Quoted
    496 Post(s)

    Default

    SCAR Code:
    procedure CalcAngle(hx, hy: integer);
    var
      angle: extended;
      lm, ln, im: integer;

    begin
      angle := ArcTan((hy - mmcy) / (hx - mmcx));
      Writeln(FloatToStr(degrees(angle)));
    end;


    would that work RM? it seems to give me the angle ;)
    i need to use the angle and distance to calculate the point on the ms now... :(
    i soooo should have done this the easy way.. ;) but now i started i aint STOPPIN!!! ;)

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

    Default

    SCAR Code:
    function GetAngle(x, y, x2, y2: integer): Extended;
    begin
      Result:= (ArcTan2(y2 - y, x2 - x) * (180 / Pi)) + 90;
      if Result < 0.0 then  Result:= Result + 360.0;
    end;

    This reminds me of something I made that I used that formula in.
    It would use the minimap to find something on the mainscreen.
    I posted it somewhere around here... Probably like a year ago though.

  18. #18
    Join Date
    Feb 2007
    Location
    PA, USA
    Posts
    5,240
    Mentioned
    36 Post(s)
    Quoted
    496 Post(s)

    Default

    something is still not working....
    if anyone could help that'd be great... thanks so far RM!!! you t3h shiz
    SCAR Code:
    program New;
    {.include srl/srl.scar}
    var
      I, x, y, z :integer;
    function GetAngle(xc, yc, x2, y2: integer): Extended;
    begin
      Result:= (ArcTan2(y2 - yc, x2 - xc) * (180 / Pi)) + 90;
      if Result < 0.0 then
        Result:= Result + 360.0;
    end;
    procedure CalcAngle(hx, hy: integer);
    var
      angle: extended;
      lm, ln, im: integer;
      pnt: tpoint;
    begin
      angle := Radians(GetAngle(hx, hy, mscx, mscy));
      pnt := IntToPoint(hx, hy);
      pnt := RotatePoint(pnt, angle, mmcx, mmcy);
      MoveMouse(pnt.x, pnt.y);
      Writeln(IntToStr(pnt.x)+' '+ inttostr(pnt.y));
      Writeln(FloatToStr(degrees(angle)));
    end;
    begin
      setupSRL;
      x := mmcx;
      y := mmcy;
      FindColorSpiral(x, y, FindLadderColor, mmx1, mmy1, mmx2, mmy2);
      CalcAngle(x, y);
      //writeln(inttostr(x)+' '+ Inttostr(y));
      //Writeln(InttoStr(distance(x, y, mmcx, mmcy)));
    end.
    it moves the mouse to the mm point lol... it moves the mouse to hx, hy

  19. #19
    Join Date
    Jan 2008
    Location
    NC, USA.
    Posts
    4,429
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    Slope is

    (y2 - y)/(x2 - x)

    Lol, just did that in my shit math class last month
    Quote Originally Posted by irc
    [00:55:29] < Guest3097> I lol at how BenLand100 has become noidea
    [01:07:40] <@BenLand100> i'm not noidea i'm
    [01:07:44] -!- BenLand100 is now known as BenLand42-
    [01:07:46] <@BenLand42-> shit
    [01:07:49] -!- BenLand42- is now known as BenLand420
    [01:07:50] <@BenLand420> YEA

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

    Default

    Quote Originally Posted by NCDS View Post
    no, it doesnt need to be a right angle.

    You just need to know that all the angles will add up to 180 degrees, then do what RM said.
    lol at this post (no offense NCDS, I hope you still love me?)
    It does have to be a right angle, and all the angles in a triangle does ALWAYS add up to 180

    footballjds:
    if Point1.x > Point2.x then u have to make the triangle a right angle, instead of a left angle as RM's picture shows.

    Angle := ArcTan2(d - b, c - a)
    (I think that is correct, I haven't tested it yet)

  21. #21
    Join Date
    Oct 2006
    Location
    Ontario,Canada
    Posts
    1,718
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    It doesnt have to be a right triangle if you use cosine or sin law...

  22. #22
    Join Date
    Feb 2007
    Location
    PA, USA
    Posts
    5,240
    Mentioned
    36 Post(s)
    Quoted
    496 Post(s)

    Default

    i need somone to basically get it working for me im way to
    lol

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

    Default

    Quote Originally Posted by XcanadamanX View Post
    It doesnt have to be a right triangle if you use cosine or sin law...
    o rly?
    grrrmf... gotta do homework now...

  24. #24
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    Quote Originally Posted by Zyt3x View Post
    lol at this post (no offense NCDS, I hope you still love me?)
    Ofcourse I do!

    Quote Originally Posted by Zyt3x View Post
    It does have to be a right angle,
    Quote Originally Posted by XcanadamanX View Post
    It doesnt have to be a right triangle if you use cosine or sin law...
    +1!

    Quote Originally Posted by Zyt3x View Post
    and all the angles in a triangle does ALWAYS add up to 180
    Thats what I said!

  25. #25
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by XcanadamanX View Post
    It doesnt have to be a right triangle if you use cosine or sin law...
    don't make it too complicated

    besides sin law cannot be used here because it might give you wrong answer is the angle is >90 if i remember right. there are anyways some cases where sin law gives 2 values, so the only one left is cosine law which is bit too complicated to use here (it doesnt give you the wrong answer but why make it the hard way?)

    edit: fixed typo
    Last edited by marpis; 05-07-2009 at 07:24 PM.

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)

Posting Permissions

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