Click here to Skip to main content
15,886,724 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: internationalisation Pin
Abhi Lahare13-Jun-11 6:49
Abhi Lahare13-Jun-11 6:49 
GeneralRe: internationalisation Pin
Kyudos14-Jun-11 10:50
Kyudos14-Jun-11 10:50 
GeneralRe: internationalisation Pin
Abhi Lahare14-Jun-11 11:29
Abhi Lahare14-Jun-11 11:29 
QuestionWant to find Rightmost top point from the CPoint List Pin
Abhijit_Satpute9-Jun-11 8:27
Abhijit_Satpute9-Jun-11 8:27 
AnswerRe: Want to find Rightmost top point from the CPoint List Pin
MicroVirus9-Jun-11 10:03
MicroVirus9-Jun-11 10:03 
AnswerRe: Want to find Rightmost top point from the CPoint List Pin
Richard MacCutchan9-Jun-11 10:32
mveRichard MacCutchan9-Jun-11 10:32 
AnswerRe: Want to find Rightmost top point from the CPoint List Pin
CPallini9-Jun-11 22:09
mveCPallini9-Jun-11 22:09 
AnswerRe: Want to find Rightmost top point from the CPoint List Pin
Stefan_Lang15-Jun-11 2:46
Stefan_Lang15-Jun-11 2:46 
If I understand you correctly, you want to find the point that is the farthest ina a particular direction. By the way you ask I assume you are not looking for the rightmost or topmost point, but a point that is 'closest to the top right corner', or something like that.

I am thinking what you need is to define the direction you are looking at as a vector (in a geometrical sense), and then use vector algebra to determine which of the points is farthest in the direction denoted by that vector. To do this, you use that direction to define a line, and project all points onto that line, then determine its distance to the lines origin. It doesn't really matter where that origin lies as long as you differentiate which side of the origin your projected point comes to lie by using a signed distance value; for sake of simplicity just use (0,0) as origin.

A line through (0,0) in the direction of D can be defined by L(t)=t*D. Calculating the projection Q of a point P on this line can be done like this: Q = (P*D / |D|) * D / |D| = (P*D)*D / (D*D). Basically this formula defines the parameter t for the peojected point Q to be t(Q)=(P*D)/(D*D). For the purpose of looking for the point 'farthest' in the direction of D, you can just compare the values of t(Q). And since the denominator (D*D) is a constant, you can just ignore it. Instead just calculate P*D for each point P and determine the point with the largest result:
struct point2 {
   int x;
   int y;
}
int operator*(const point2& p1, const point2& p2) {
   return p1.x*p2.x + p1.y*p2.y;
}
void test() {
   
   std::list<point2> pointlist;
   point2 P;
   P.x = 1258;
   P.y = 263;
   pointlist.push_back(P);
   P.x = 1263;
   P.y = 260;
   pointlist.push_back(P);

   point2 D;
   D.x = 1;
   D.y = 1;

   std::list<point2>::iterator it = pointlist.begin()
   double farthest_value = (*it) * D;
   std::list<point2>::iterator farthest_point = it;
   while (++it != pointlist.end()) {
      double value = (*it) * D;
      if (value > farthest_value) {
          farthest_value = value;
          farthest_point = it;
      }
   }

   std::cout << "farthest point is (" << farthest_point.x << "," << farthest_point.y << ")" << std::endl;
}

QuestionUsing C# in C++ Pin
Chris_Green8-Jun-11 23:54
Chris_Green8-Jun-11 23:54 
AnswerRe: Using C# in C++ Pin
CPallini9-Jun-11 0:24
mveCPallini9-Jun-11 0:24 
GeneralRe: Using C# in C++ Pin
Chris_Green9-Jun-11 0:54
Chris_Green9-Jun-11 0:54 
GeneralRe: Using C# in C++ Pin
Rolf Kristensen9-Jun-11 8:43
Rolf Kristensen9-Jun-11 8:43 
GeneralRe: Using C# in C++ Pin
CPallini9-Jun-11 22:03
mveCPallini9-Jun-11 22:03 
AnswerRe: Using C# in C++ Pin
ThatsAlok13-Jun-11 21:14
ThatsAlok13-Jun-11 21:14 
AnswerRe: Using C# in C++ Pin
ThatsAlok13-Jun-11 21:16
ThatsAlok13-Jun-11 21:16 
QuestionFont Size Problem in Edit Control [SOLVED] Pin
vishalgpt8-Jun-11 19:37
vishalgpt8-Jun-11 19:37 
AnswerRe: Font Size Problem in Edit Control Pin
Richard MacCutchan8-Jun-11 21:42
mveRichard MacCutchan8-Jun-11 21:42 
GeneralRe: Font Size Problem in Edit Control Pin
vishalgpt8-Jun-11 22:16
vishalgpt8-Jun-11 22:16 
GeneralRe: Font Size Problem in Edit Control Pin
Richard MacCutchan9-Jun-11 4:07
mveRichard MacCutchan9-Jun-11 4:07 
GeneralRe: Font Size Problem in Edit Control Pin
vishalgpt9-Jun-11 7:04
vishalgpt9-Jun-11 7:04 
GeneralRe: Font Size Problem in Edit Control Pin
Richard MacCutchan9-Jun-11 7:23
mveRichard MacCutchan9-Jun-11 7:23 
GeneralRe: Font Size Problem in Edit Control Pin
vishalgpt9-Jun-11 7:32
vishalgpt9-Jun-11 7:32 
GeneralRe: Font Size Problem in Edit Control Pin
Iain Clarke, Warrior Programmer9-Jun-11 8:03
Iain Clarke, Warrior Programmer9-Jun-11 8:03 
GeneralRe: Font Size Problem in Edit Control Pin
vishalgpt10-Jun-11 17:28
vishalgpt10-Jun-11 17:28 
Questionhow to get the code of OnLButtonDown and OnMouseMove etc in OnDraw method ? Pin
iampradeepsharma8-Jun-11 17:13
iampradeepsharma8-Jun-11 17:13 

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.