Click here to Skip to main content
15,912,072 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Doese GDI+ provide the functions such as SetROP2 in GDI? Pin
G.Richard25-Feb-02 14:23
G.Richard25-Feb-02 14:23 
GeneralRe: Doese GDI+ provide the functions such as SetROP2 in GDI? Pin
Christian Graus27-Mar-02 0:25
protectorChristian Graus27-Mar-02 0:25 
AnswerRe: Doese GDI+ provide the functions such as SetROP2 in GDI? Pin
Swinefeaster27-Mar-02 0:27
Swinefeaster27-Mar-02 0:27 
Generalsystem debug symbols Pin
Gabriel.P.G23-Feb-02 11:56
Gabriel.P.G23-Feb-02 11:56 
GeneralQuestion about CPoint objects... Pin
CDuddley23-Feb-02 10:41
CDuddley23-Feb-02 10:41 
GeneralRe: Question about CPoint objects... Pin
Christian Graus23-Feb-02 10:43
protectorChristian Graus23-Feb-02 10:43 
GeneralRe: Question about CPoint objects... Pin
CDuddley23-Feb-02 10:49
CDuddley23-Feb-02 10:49 
GeneralRe: Question about CPoint objects... Pin
Peter Godec23-Feb-02 11:58
Peter Godec23-Feb-02 11:58 
CDuddley wrote:
to find the closest point

If i understand correctly, you need to define a measure of distance between CPoints to do that. Most probably that would be euclidean distance , i.e.

d = sqrt((x1 - x2)^2 + (y1 - y2)^2)

So define a function that calculates the euclidean distance between two CPoints, maybe something like this:

#include <math.h> // or <cmath> and std:: if your compiler/library isn't broken

double distance(const CPoint& p1, const CPoint& p2)
{
	return sqrt((p1.x - p2.x)*(p1.x - p2.x) + (p1.y - p2.y)*(p1.y - p2.y));
}

a nicer variant (performance?) of this would be
double distance(const CPoint& p1, const CPoint& p2)
{
	CSize diff = p1 - p2;
	return sqrt(diff.x * diff.x + diff.y * diff.y);
}

(of course, for your purpose, you don't need to calculate the sqrt, but now i'm blabbering)

Now all you's gotta do is iterate over the array of CPoints, calculating the distance between your given test point and each point in the array and keeping track of the array index of the point that is the closest to the test point (now read this paragraph again).

that-exercise-is-left-to-the-OP-ly y'rs --pg Smile | :)
GeneralRe: Question about CPoint objects... Pin
CDuddley23-Feb-02 12:16
CDuddley23-Feb-02 12:16 
GeneralRe: Question about CPoint objects... Pin
CDuddley23-Feb-02 13:23
CDuddley23-Feb-02 13:23 
GeneralCommon Dialog Boxes Pin
gordingin23-Feb-02 10:13
gordingin23-Feb-02 10:13 
GeneralRe: Common Dialog Boxes Pin
Paul M Watt23-Feb-02 10:22
mentorPaul M Watt23-Feb-02 10:22 
GeneralGroup policies Pin
Brian van der Beek23-Feb-02 10:00
Brian van der Beek23-Feb-02 10:00 
QuestionDowncasting CButton...?? Pin
alex.barylski23-Feb-02 9:22
alex.barylski23-Feb-02 9:22 
AnswerRe: Downcasting CButton...?? Pin
Joaquín M López Muñoz23-Feb-02 9:40
Joaquín M López Muñoz23-Feb-02 9:40 
GeneralRe: Downcasting CButton...?? Pin
alex.barylski23-Feb-02 10:06
alex.barylski23-Feb-02 10:06 
Generalchange coordination rule Pin
Mazdak23-Feb-02 8:40
Mazdak23-Feb-02 8:40 
GeneralRe: change coordination rule Pin
Simon Walton23-Feb-02 9:02
Simon Walton23-Feb-02 9:02 
GeneralPbs with Internet Explorer Rebars in MFC Pin
23-Feb-02 8:35
suss23-Feb-02 8:35 
GeneralRe: Pbs with Internet Explorer Rebars in MFC Pin
Shog923-Feb-02 13:47
sitebuilderShog923-Feb-02 13:47 
QuestionSplitter window...??? Pin
alex.barylski23-Feb-02 6:43
alex.barylski23-Feb-02 6:43 
AnswerRe: Splitter window...??? Pin
Mazdak23-Feb-02 7:31
Mazdak23-Feb-02 7:31 
GeneralRe: Splitter window...??? Pin
alex.barylski23-Feb-02 8:29
alex.barylski23-Feb-02 8:29 
GeneralRe: Splitter window...??? Pin
Simon Walton23-Feb-02 9:04
Simon Walton23-Feb-02 9:04 
GeneralRe: Splitter window...??? Pin
alex.barylski23-Feb-02 9:09
alex.barylski23-Feb-02 9:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.