Bixby Sayz Posted November 22, 2012 Share Posted November 22, 2012 (edited) Looking for the best way to find point in a TPA that is closest to the center of the TPA. TPACenter and TPAMiddle do not necessarily return a point that actually exists in the TPA. TPADistToPointEx looks like it would do it but it has a zillion params I'm not really interested in. Edit: I wound up doing this: [sCAR]TPASortEx(Tpa, TPAMiddle(Tpa)); Result := Tpa[0];[/sCAR] Edited November 22, 2012 by Bixby Sayz Quote Link to comment Share on other sites More sharing options...
FHannes Posted November 22, 2012 Share Posted November 22, 2012 (edited) Hmm, TPAMiddle and TPACenter look surprisingly similar... I should look into that. Anyway, your best bet is this: [scar]var TPA: TPointArray; P, TP: TPoint; E: Extended; begin TPA := [Point(0, 0), Point(2, 2), Point(1, 2)]; P := TPACenter(TPA); TPADistToPointEx(TPA, P, E, E, P, TP); WriteLn(PointToStr(P)); end.[/scar] EDIT: TPASortEx will do the trick, but it's probably lots slower than TPADistToPointEx. EDIT2: *sees the difference between TPACenter and TPAMiddle* EDIT3: Will rename TPAMiddle to TPAMean EDIT4: By using TPAMiddle, the point you're getting won't be at the center, but closer to the center of the highest density area. EDIT5: Woo, 5 edits! Edited November 22, 2012 by Freddy Quote Link to comment Share on other sites More sharing options...