opiumhautopium1 Posted April 7, 2012 Share Posted April 7, 2012 hi guys i got a question is there a funktion to get a x/y coordinate between the distance function ? function Distance(const x1, y1, x2, y2: Integer): Integer; example x1=0... y1=0..... x2=10...... y2=0....... distance is 10 but now i want to know the (x/y) coordinate by 7 because i want to do a mouseclick betreen this 2 points (x1/y1) and (x2/y2) thx in advance and hope somebody can help me ^^ Quote Link to comment Share on other sites More sharing options...
sjesper Posted April 7, 2012 Share Posted April 7, 2012 Do you mean something like this: [sCAR] function GetMiddleTB(TB: TBox): TPoint; begin Result.X := Round(TB.X1 + (TB.X2 - TB.X1) div 2); Result.Y := Round(TB.Y1 + (TB.Y2 - TB.Y1) div 2); end; [/sCAR] ? Quote Link to comment Share on other sites More sharing options...
opiumhautopium1 Posted April 7, 2012 Author Share Posted April 7, 2012 give this funktion the center of 2 points? then it is not the right thing because i need the coordinates between 2 points but not the center/middle may be the distance between 2 points is 15 .... and i want to know the coordinate by distance step 9 or do i understand someting wrong with your function ? Quote Link to comment Share on other sites More sharing options...
sjesper Posted April 7, 2012 Share Posted April 7, 2012 give this funktion the center of 2 points? then it is not the right thing because i need the coordinates between 2 points but not the center/middle may be the distance between 2 points is 15 .... and i want to know the coordinate by distance step 9 or do i understand someting wrong with your function ? I dont really understand what you mean, but this function return the middle of a box so you can click in the middle of x1y1 and x2y2. Quote Link to comment Share on other sites More sharing options...
opiumhautopium1 Posted April 7, 2012 Author Share Posted April 7, 2012 i dont need the middle.... example green point is x1y1....... red point is x2y2 distance is 12 i want to know the x/y by distance step 7 or 8 sometimes 2 ( between distance 0 and 12) i need a funktion that give me the coordinate x/y at 7 or 8..... and not the middle Quote Link to comment Share on other sites More sharing options...
Bixby Sayz Posted April 7, 2012 Share Posted April 7, 2012 Think I understand but don't know the answer. You have a point P1 and a point P2, x number of pixels apart. He wants to find a point y number a pixels from P1 along the imaginary line drawn between P1 and P2. Quote Link to comment Share on other sites More sharing options...
opiumhautopium1 Posted April 8, 2012 Author Share Posted April 8, 2012 i make paint jpg to show what i mean Quote Link to comment Share on other sites More sharing options...
FHannes Posted April 8, 2012 Share Posted April 8, 2012 You want the coordinates that are intersected by the line between 2 other coordinates? Quote Link to comment Share on other sites More sharing options...
opiumhautopium1 Posted April 8, 2012 Author Share Posted April 8, 2012 yep i want to know if the function distance give me as outout (23 pixels) from redpoint x/y to the greenpoint 2xy at witch coordinate is pixel 7 or 8 or 21 Quote Link to comment Share on other sites More sharing options...
FHannes Posted April 8, 2012 Share Posted April 8, 2012 It's not quite that simple... If the line is diagonal, it will intersect more points than the distance which is returned... Quote Link to comment Share on other sites More sharing options...
Janilabo Posted April 8, 2012 Share Posted April 8, 2012 (edited) Does this help you out (?): [scar]function PointToStr(pt: TPoint): string; begin Result := (IntToStr(pt.X) + ', ' + IntToStr(pt.Y)); end; function DistanceTo(fromPt, toPt: TPoint): Integer; var X, Y: Integer; begin if (fromPt = toPt) then Exit; X := (Max(fromPt.X, toPt.X) - Min(fromPt.X, toPt.X)); Y := (Max(fromPt.Y, toPt.Y) - Min(fromPt.Y, toPt.Y)); Result := Max(X, Y); end; function GetTPALine(fromPt, toPt: TPoint): TPointArray; var i, h: integer; e: Extended; begin h := Max(Round(Abs(fromPt.X - toPt.X)), Round(Abs(fromPt.Y - toPt.Y))); SetLength(Result, h + 1); for i := 0 to h do begin e := (i / h); Result.X := fromPt.X + Round((toPt.X - fromPt.X) * e); Result.Y := fromPt.Y + Round((toPt.Y - fromPt.Y) * e); end; end; function GetPointBetweenPointsByStep(fromPt, toPt: TPoint; step: Integer): TPoint; var i, h: integer; e: Extended; begin if (step > DistanceTo(fromPt, toPt)) or (step < 0) then Exit; h := Max(Round(Abs(fromPt.X - toPt.X)), Round(Abs(fromPt.Y - toPt.Y))); e := (step / h); Result.X := fromPt.X + Round((toPt.X - fromPt.X) * e); Result.Y := fromPt.Y + Round((toPt.Y - fromPt.Y) * e); end; var TPA: TPointArray; h, i: Integer; pt1, pt2: TPoint; begin ClearDebug; pt1 := Point(127, 106); pt2 := Point(39, 34); TPA := GetTPALine(pt1, pt2); h := High(TPA); for i := 0 to h do begin WriteLn('GetPointBetweenPointsByStep: ' + PointToStr(GetPointBetweenPointsByStep(pt1, pt2, i)) + ' (step: ' + IntToStr(i) + ')'); WriteLn('TPA[' + IntToStr(i) + ']: ' + PointToStr(TPA)); end; SetLength(TPA, 0); end.[/scar] A few functions that I wrote. Pretty much does what you are looking for.. (Getting point from line of points, with "STEP" (chosen distance). Edit: You can test it in Paint, with mouse clicking, that it does work correctly. Edit2: Here is also example with your coordinates, that you were looking answer for.. [scar]function PointToStr(pt: TPoint): string; begin Result := (IntToStr(pt.X) + ', ' + IntToStr(pt.Y)); end; function DistanceTo(fromPt, toPt: TPoint): Integer; var X, Y: Integer; begin if (fromPt = toPt) then Exit; X := (Max(fromPt.X, toPt.X) - Min(fromPt.X, toPt.X)); Y := (Max(fromPt.Y, toPt.Y) - Min(fromPt.Y, toPt.Y)); Result := Max(X, Y); end; function GetPointBetweenPointsByStep(fromPt, toPt: TPoint; step: Integer): TPoint; var i, h: integer; e: Extended; begin if (step > DistanceTo(fromPt, toPt)) or (step < 0) then Exit; h := Max(Round(Abs(fromPt.X - toPt.X)), Round(Abs(fromPt.Y - toPt.Y))); e := (step / h); Result.X := fromPt.X + Round((toPt.X - fromPt.X) * e); Result.Y := fromPt.Y + Round((toPt.Y - fromPt.Y) * e); end; var pt1, pt2: TPoint; begin ClearDebug; pt1 := Point(0, 0); pt2 := Point(10, 0); WriteLn(PointToStr(GetPointBetweenPointsByStep(pt1, pt2, 7))); end.[/scar] So thats how it works. Edit3: GetTPABetweenPoints function, you might need this.. [scar]function DistanceTo(fromPt, toPt: TPoint): Integer; var X, Y: Integer; begin if (fromPt = toPt) then Exit; X := (Max(fromPt.X, toPt.X) - Min(fromPt.X, toPt.X)); Y := (Max(fromPt.Y, toPt.Y) - Min(fromPt.Y, toPt.Y)); Result := Max(X, Y); end; function GetTPALineBetweenPoints(fromPt, toPt: TPoint): TPointArray; var i, h: integer; e: Extended; begin if 3 > DistanceTo(fromPt, toPt) then Exit; h := Max(Round(Abs(fromPt.x - toPt.x)), Round(Abs(fromPt.y - toPt.y))); SetLength(Result, (h - 1)); for i := 1 to (h - 1) do begin e := (i / h); Result[(i - 1)].x := fromPt.x + Round((toPt.x - fromPt.x) * e); Result[(i - 1)].y := fromPt.y + Round((toPt.y - fromPt.y) * e); end; end; function GetTPALine(fromPt, toPt: TPoint): TPointArray; var i, h: integer; e: Extended; begin h := Max(Round(Abs(fromPt.X - toPt.X)), Round(Abs(fromPt.Y - toPt.Y))); SetLength(Result, h + 1); for i := 0 to h do begin e := (i / h); Result.X := fromPt.X + Round((toPt.X - fromPt.X) * e); Result.Y := fromPt.Y + Round((toPt.Y - fromPt.Y) * e); end; end; var pt1, pt2: TPoint; TPA: TPointArray; h, i: Integer; begin ClearDebug; pt1 := Point(0, 0); pt2 := Point(10, 0); WriteLn('GetTPALineBetweenPoints:'); TPA := GetTPALineBetweenPoints(pt1, pt2); h := High(TPA); for i := 0 to h do WriteLn('TPA[' + IntToStr(i) + ']: ' + IntToStr(TPA.X) + ', ' + IntToStr(TPA.Y)); SetLength(TPA, 0); WriteLn(''); WriteLn('GetTPALine:'); TPA := GetTPALine(pt1, pt2); h := High(TPA); for i := 0 to h do WriteLn('TPA[' + IntToStr(i) + ']: ' + IntToStr(TPA.X) + ', ' + IntToStr(TPA.Y)); SetLength(TPA, 0); end.[/scar] -Jani Edited April 8, 2012 by Janilabo 1 small fix for DistanceTo function.. Changed PointLine => GetTPALine and added GetTPALineBetweenPoints function. Quote Link to comment Share on other sites More sharing options...
opiumhautopium1 Posted April 9, 2012 Author Share Posted April 9, 2012 (edited) yeap that sounds great i will test it as soon as possible ....... at the moment we have hollyday and family comes 1st ...... but thank you very mutch 1 more reason i like scar is 1 powerful tool 2 for every problem there is a solution and 3 a good comunity with good users may be freddy shout think about to integrate it in scar because it is a powerful minimap funktion . a special thx to janilabo i will integrate this funktion in every scrit i write in future thx a lot ... and happy eastern -------------------------------------------- i made a test..... it works great! good job ^^ Edited April 9, 2012 by opiumhautopium1 Quote Link to comment Share on other sites More sharing options...
Janilabo Posted April 9, 2012 Share Posted April 9, 2012 (edited) Hello opiumhautopium1, Glad to hear it did work for you! Hopefully it did help too. By the way, I made also another method for this, that you could always use.. It works with radius&angle (point "offset").. Here is the alternative method (I made an example script for you): [scar]function PointToStr(pt: TPoint): string; begin Result := (IntToStr(pt.X) + ', ' + IntToStr(pt.Y)); end; function GetAngleBetweenPoints(pt1, pt2: TPoint): Extended; begin Result := Degrees(ArcTan2((pt2.Y - pt1.Y), (pt1.X - pt2.X))); end; procedure GetOffsetFromPoints(pt1, pt2: TPoint; var radius, angle: Extended); var X, Y: Integer; begin X := (pt1.X - pt2.X); Y := (pt2.Y - pt1.Y); radius := Round(Sqrt(Pow(X, 2) + Pow(Y, 2))); angle := ((ArcTan2(Y, X) * 180) / Pi); end; procedure OffsetPoint(var Pt: TPoint; radius, angle: Extended); begin Pt.X := (Pt.X + Round(radius * Sin(Radians(angle - 90.0)))); Pt.Y := (Pt.Y + Round(radius * Cos(Radians(angle - 90.0)))); end; function GetPointWithOffset(startPt: TPoint; radius, angle: Extended): TPoint; begin Result := Point(startPt.X + Round(radius * Sin(Radians(angle - 90.0))), startPt.Y + Round(radius * Cos(Radians(angle - 90.0)))); end; var pt1, pt2: TPoint; r, a: Extended; begin ClearDebug; pt1 := Point(0, 0); pt2 := Point(10, 0); a := GetAngleBetweenPoints(pt1, pt2); r := Distance(pt1.X, pt1.Y, pt2.X, pt2.Y); WriteLn('RADIUS: ' + FloatToStr® + ', ANGLE: ' + FloatToStr(a) + ' [GetAngleBetweenPoints() + Distance()]'); GetOffsetFromPoints(pt1, pt2, r, a); WriteLn('RADIUS: ' + FloatToStr® + ', ANGLE: ' + FloatToStr(a) + ' [GetOffSetFromPoints()]'); WriteLn(PointToStr(GetPointWithOffset(pt1, 7, a))); OffsetPoint(pt1, 7, a); WriteLn(PointToStr(pt1)); end.[/scar] -Jani Edited April 9, 2012 by Janilabo Quote Link to comment Share on other sites More sharing options...
opiumhautopium1 Posted April 9, 2012 Author Share Posted April 9, 2012 (edited) of course i will use it in every script because it is a great minimap waypoint funktion to keep the exact distance and i dont have to loop the procedure to check the distance so it can do other things ^^ happy eastern ^^ all seafight scripst handle 90% what to do over the minimap so it is realy realy realy good to have this function Edited April 9, 2012 by opiumhautopium1 Quote Link to comment Share on other sites More sharing options...
Janilabo Posted April 9, 2012 Share Posted April 9, 2012 Thanks, happy easter to you aswell! Quote Link to comment Share on other sites More sharing options...