Click here to Skip to main content
15,501,351 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: internationalisation Pin
Abhi Lahare13-Jun-11 7:49
MemberAbhi Lahare13-Jun-11 7:49 
GeneralRe: internationalisation Pin
Kyudos14-Jun-11 11:50
MemberKyudos14-Jun-11 11:50 
GeneralRe: internationalisation Pin
Abhi Lahare14-Jun-11 12:29
MemberAbhi Lahare14-Jun-11 12:29 
QuestionWant to find Rightmost top point from the CPoint List Pin
Abhijit_Satpute9-Jun-11 9:27
MemberAbhijit_Satpute9-Jun-11 9:27 
AnswerRe: Want to find Rightmost top point from the CPoint List Pin
MicroVirus9-Jun-11 11:03
MemberMicroVirus9-Jun-11 11:03 
AnswerRe: Want to find Rightmost top point from the CPoint List Pin
Richard MacCutchan9-Jun-11 11:32
mveRichard MacCutchan9-Jun-11 11:32 
AnswerRe: Want to find Rightmost top point from the CPoint List Pin
CPallini9-Jun-11 23:09
mveCPallini9-Jun-11 23:09 
AnswerRe: Want to find Rightmost top point from the CPoint List Pin
Stefan_Lang15-Jun-11 3:46
mveStefan_Lang15-Jun-11 3: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_Green9-Jun-11 0:54
MemberChris_Green9-Jun-11 0:54 
AnswerRe: Using C# in C++ Pin
CPallini9-Jun-11 1:24
mveCPallini9-Jun-11 1:24 
GeneralRe: Using C# in C++ Pin
Chris_Green9-Jun-11 1:54
MemberChris_Green9-Jun-11 1:54 
GeneralRe: Using C# in C++ Pin
Rolf Kristensen9-Jun-11 9:43
MemberRolf Kristensen9-Jun-11 9:43 
GeneralRe: Using C# in C++ Pin
CPallini9-Jun-11 23:03
mveCPallini9-Jun-11 23:03 
AnswerRe: Using C# in C++ Pin
ThatsAlok13-Jun-11 22:14
MemberThatsAlok13-Jun-11 22:14 
AnswerRe: Using C# in C++ Pin
ThatsAlok13-Jun-11 22:16
MemberThatsAlok13-Jun-11 22:16 
QuestionFont Size Problem in Edit Control [SOLVED] Pin
vishalgpt8-Jun-11 20:37
Membervishalgpt8-Jun-11 20:37 
AnswerRe: Font Size Problem in Edit Control Pin
Richard MacCutchan8-Jun-11 22:42
mveRichard MacCutchan8-Jun-11 22:42 
GeneralRe: Font Size Problem in Edit Control Pin
vishalgpt8-Jun-11 23:16
Membervishalgpt8-Jun-11 23:16 
GeneralRe: Font Size Problem in Edit Control Pin
Richard MacCutchan9-Jun-11 5:07
mveRichard MacCutchan9-Jun-11 5:07 
GeneralRe: Font Size Problem in Edit Control Pin
vishalgpt9-Jun-11 8:04
Membervishalgpt9-Jun-11 8:04 
GeneralRe: Font Size Problem in Edit Control Pin
Richard MacCutchan9-Jun-11 8:23
mveRichard MacCutchan9-Jun-11 8:23 
GeneralRe: Font Size Problem in Edit Control Pin
vishalgpt9-Jun-11 8:32
Membervishalgpt9-Jun-11 8:32 
GeneralRe: Font Size Problem in Edit Control Pin
Iain Clarke, Warrior Programmer9-Jun-11 9:03
MemberIain Clarke, Warrior Programmer9-Jun-11 9:03 
GeneralRe: Font Size Problem in Edit Control Pin
vishalgpt10-Jun-11 18:28
Membervishalgpt10-Jun-11 18:28 
Questionhow to get the code of OnLButtonDown and OnMouseMove etc in OnDraw method ? Pin
iampradeepsharma8-Jun-11 18:13
Memberiampradeepsharma8-Jun-11 18: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.