Page 2 of 2 FirstFirst 12
Results 26 to 46 of 46

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

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

    Default

    Quote Originally Posted by marpis View Post
    don't make it too complicated

    besides sin law cannot be used here because it might give you wrong answer is the angle is >180 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?)
    you can have an angle greater than 180 in a triangle? news to me. cosine law is not hard. my code from my smelter:
    SCAR Code:
    dist:=Distance(Points[0].x,Points[0].y,Points[1].x,Points[1].y);
    x2 := floor((dist * Sin(radians(61))) div sin(radians(78)))
    y2 := floor((dist * Sin(radians(41))) div sin(radians(78)))
    x2 := x2 + Points[0].x
    y2 := y2 + Points[1].y

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

    Default

    Since he's finding the angle of a line made up of 2 points, generating a right angled triangle is easier enough to do by creating a 3rd point based on values from each of them.

    Anywho, I *think* Special Ed made a very accurate function like this already, so you can try looking into that (part of MSI I think).

    Otherwise, I think you need to go over and double check everything you have there.
    First of all, you want to find the angle between the minimap centre and your point rather than mainscreen. You then want to change that angle to the mainscreen with a length that relates to the ratio between the mainscreen size and minimap size. If all the values add up right, then it should give a somewhat accurate position.
    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.

  3. #28
    Join Date
    Sep 2006
    Location
    Canada
    Posts
    1,124
    Mentioned
    0 Post(s)
    Quoted
    5 Post(s)

    Default

    Quote Originally Posted by Zyt3x View Post
    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.
    Uhhh, idk what math class you've been to, but that IS a right angle. A right angle triangle is a triangle with one of three of its angles being 90 degrees. You can rotate that triangle any way you want, and it'll still be called a right angle triangle.

    And yeah, you don't have to use a right angle triangle, but since you already have two predetermined points and can create a right angle triangle, you might aswell.

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

    Default

    Quote Originally Posted by Capricorn View Post
    Uhhh, idk what math class you've been to, but that IS a right angle. A right angle triangle is a triangle with one of three of its angles being 90 degrees. You can rotate that triangle any way you want, and it'll still be called a right angle triangle.
    I ment a triangle where the 3rd point is to the right

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

    Default

    ive been trying to get the ratio thing working ...
    not working atm...
    here is the thing, i do NOT need a 3rd point, period.
    you can calculate the slope of a line with only 2 points as rs is only 2d, everything that is on a screen is 2d...
    and now i need the ratio between the MS and MM... if you know of spec Ed's funct then tell me!!!!!!!!!!1

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

    Default

    Did no one see my post?
    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;
    It works 100% accurate.
    And its a bit easier than making triangles and stuff.

    and now i need the ratio between the MS and MM
    I believe when I did my script the way I found it was multiply the distance on the minimap by some decimal number between 1 and 2.
    That gives the distance on the main screen from the center.
    The number to multiply by is hard to get though, because it's not always the same.
    You have to experiment with it a lot and get the best number that works in the most cases.

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

    Default

    lol.... i did see ur post and i tried it

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

    Default

    And it didn't work?

    Also just wondering, are you trying to find something on the main screen using the minimap?
    Like if there is a red dot on the minimap and you use the location of that dot on the minimap to find its coords on the screen.

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

    Default

    yes thats what im trying to do...<-------- NEED HELP
    i dunno if it worked or not i thnk i t did...<--your funct

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

    Default

    Oh ok here is a rundown on what I did.
    Look on the minimap and get the point that you need to find on the main screen.
    Get the distance between the minimap center and that point.
    Multiply that distance by that decimal number I was talking about.
    Get the angle between the center of the minimap and the point.
    The point on the main screen is like this-
    SCAR Code:
    x:= Round(Sin(Angle * Pi / 180) * Distance + MSX);
    y:= Round(Cos(Angle * Pi / 180) * Distance + MSY);

    It comes out very accurate sometimes, but the RuneScape screen shifts all around so sometimes it isn't so accurate.

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

    Default

    and wth is the decimal? and why is it not always the same?
    the ratio to size should be, the size of main screen devided by size of minimap.. and that should always be the same no?

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

    Default

    RAWR!!! Lecture on it's way!

    First, in the virtual world, you can always make a right triangle from 2 points. Remember that and you'll save a lot of effort.

    Second, if you go with tangents instead of cosines, you'll be saved from calculating the hypotenuse.

    Third, now, how to calculate the angle. tan -1 (tan a) = a.

    X = A.x - B.x;
    Y = A.y - B.y;
    tan a = y/x;
    a = tan -1 (tan a).

    In SCAR,

    [highlight=pascal]
    angle := ArcTan2(A.y - B.y, A.x - B.x);
    [/highlight=pasca]

    Will be -180..180, I think, so you have to do if (angle < 0) then angle := angle + 360 to make it 0..360.


    Hold on!

    If you're making something that calculates MM points to MS, http://www.villavu.com/forum/showthread.php?t=8680... FFS... I will give you a cookie if you somewhy manage to make it more accurate than his...
    Last edited by n3ss3s; 05-07-2009 at 10:45 PM.

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

    Default

    i think i determened how to get the angle O.o
    i need to then get that same point on the Main screen

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

    Default

    The number will never be the same because the runescape screen shifts.
    A lot.
    And the minimap rotates itself.
    I got mine as accurate as it's going to be and it still wasn't perfect.

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

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

    Default

    His is different than yours and mine too.
    There is no trig in it.
    So I think you probably could make a more accurate one.

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

    Default

    yeah, maybe we could make one that accounts for mm shift
    nvm the nvm keep this going!! and n3ss3s tell me how to account for mm shift!!!!

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

    Default

    Sythescape.
    Never used it but people have told me that the screen never moves and the minimap is locked.

    Without sythescape I can only think of one thing that you could to to make it more accurate.
    The higher up on the screen your point is, the higher the y coordinate will be off from what it should be.
    This is because even with your camera at the highest angle, you aren't looking straight down at the top of your character's head like you are with the minimap.

    SCAR Code:
    y:= y - (y * n);
    n will be a decimal probably > 0 < 1
    So the higher the y coord is, the more will be taken away from it to even it out.

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

    Default

    Quote Originally Posted by footballjds View Post
    yeah, maybe we could make one that accounts for mm shift
    nvm the nvm keep this going!! and n3ss3s tell me how to account for mm shift!!!!
    If you mean the offset of the compass and the minimap, you could try making something that gets the real angle from walls... Infact it's been made, but you can search for it by yourself...

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

    Default

    theres gotta be a way............................................... ..........
    like use some killer ddtm or something

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

    Default

    Quote Originally Posted by n3ss3s View Post
    If you mean the offset of the compass and the minimap, you could try making something that gets the real angle from walls... Infact it's been made, but you can search for it by yourself...
    i mean the offset of the mm and mainscreen....


    EDIT: woups, sorry about dble post

    EDIT: maybe we should look into this!!!
    SCAR Code:
    function GetMMOffset(X1, Y1, X2, Y2: Integer): Extended;     //Wizzup modded by Zeph
    Var
       L, I, C: Integer;
       ATPA, gATPA: T2DPointArray;
       P, P2: TPoint;
       B: TBox;
       Ps: TPointArray;
    Begin
      FindColorsTolerance(Ps, RGBToColor(255, 255, 255), X1, Y1, X2, Y2, 50);
      Result := -1.0;
      If High(Ps) = -1 Then
        Exit;
      SortTPAFrom(Ps, Point((550 + 703) / 2, 0));  // Sort it from the center.
      ATPA := SplitTPAEx(Ps, 1, 0); //horizontal lines

      SortATPASize(ATPA, True);     // longest 'line'.
      L := High(aTPA);
      If L = -1 Then
        Exit;

      SetLength(gATPA, L + 1);
      C := 1;
      gATPA[0] := aTPA[0];
      P := MiddleTPA(aTPA[0]);        // get middle of the line.

      For I := 1 To L Do
      Begin // this loops adds any points that are in a dist of 10 pixels.
            // if vert, then x, hori then y (A wall isn't straight.)
        If Length(aTPA[I]) < 4 Then
          Continue;
        P2 := MiddleTPA(aTPA[I]);
        If Abs(P.Y - P2.Y) < 10 Then
        Begin
          gATPA[C] := aTPA[I];
          C := C + 1;
        End;
      End;
      SetLength(gATPA, C);
      SetLength(Ps, 0);

      Ps := MergeATPA(gATPA);   //Combine all the points. within 10pix
      B := GetTPABounds(Ps);
      SortTPAFrom(Ps, Point((B.X1 + B.X2) / 2, 0));   // sort from center

      SetLength(ATPA, 0);
      ATPA := SplitTPA(Ps, 3);  // split dist three, the left over walls
                                // were all in Ps, and now we split them again.

      SetLength(Ps, 0);
      SortATPASize(ATPA, True);   // longest wall.

      Ps := ATPA[0];
      L := High(Ps);   //angle getting
      Result := ArcTan2(Ps[L].Y - Ps[0].Y, Ps[L].X - Ps[0].X);
      while (Result > Pi / 2) do
        Result := Result - Pi;
      while (Result < -Pi / 2) do
        Result := Result + Pi;
      {$IFDEF DEBUG} WriteLn('OffsetAngle: ' + FloatToStr(Degrees(Result))); {$ENDIF}
    End;

Page 2 of 2 FirstFirst 12

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
  •