Jump to content
Bixby Sayz

Find point in TPA closest to center

Recommended Posts

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 by Bixby Sayz
Link to comment
Share on other sites

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 by Freddy
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...