|
I have created list of points.
CList<CPoint, CPoint> m_PointList;
m_PointList contains the coordinates from the screen display.
I want to find the Right most top point from the list.
For e.g List contains following points:
1)(1263,643)
2)(1258,276)
3)(1225,266)
4)(1180,257)
5)(990,241)
6)(835,239)
7)(935,705)
8)(1094,691)
9)(1258,655)
Please consider the screen coordinate system. i.e X increases from left to right and Y increase from top to bottom.
With the above input points, the output of the program should be (1258,276).
In the above mentioned points the right most point is 1263 but the corresponding y co-ordinate is 643, which is greater than the 2nd point's y co-ordinate for which the x co-ordinate is 1258.
Hence as per the display, the right most top point is (1258,643).
Please suggest the algorithm to be used.
|
|
|
|
|
Could you explain the logic more clearly? I don't understand what you are trying to do and why the 1263 rightmost point is omitted because of the second entry.
What is the algorithm supposed to do?
|
|
|
|
|
The first thing you need to decide is whether the horizontal or vertical axis has precedence. After that is a simple matter of selecting the largest value in either set.
The best things in life are not things.
|
|
|
|
|
As already noted by Richard, you have to choose the sorting order (first Y-axis or first X-axis?) otherwise the problem is ambiguous. On the other hand, if you instead need to find the 'bounding rectangle' top-right point, then the problem is well-defined but such point doesn't necessary match one of the given set.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
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;
}
|
|
|
|
|
Hi,
I have a sample project where I am using a C# library in a C++ test program. I'm doing this by COM, using the tlb and project reference.
C#
<br />
[ComVisible(true)]<br />
[ClassInterface(ClassInterfaceType.AutoDual)]<br />
public class Math<br />
{<br />
public int Add(int x, int y)<br />
{<br />
return x + y;<br />
}<br />
<br />
public static int Subtract(int x, int y)<br />
{<br />
return x - y;<br />
}<br />
}<br />
C++
<br />
#include "stdafx.h"<br />
#include <iostream><br />
<br />
#import "..\\CSharpUsefulLibrary.tlb" raw_interfaces_only<br />
<br />
int _tmain(int argc, _TCHAR* argv[])<br />
{<br />
CoInitialize(0);<br />
<br />
CSharpUsefulLibrary::_MathPtr math(__uuidof(CSharpUsefulLibrary::Math));<br />
<br />
long value;<br />
math->Add(1, 2, &value);<br />
std::wcout << "The value is " << value;<br />
<br />
CoUninitialize();<br />
return 0;<br />
}<br />
So this works fine, I'm able to call the add method in my C# library from C++. The question is, how do I call the static subtract method?
|
|
|
|
|
I'm afraid you cannot do it: There's no trace of the static Subtract method in the tlh generated file.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Yeah, in VS I did File->Open on the tlb and indeed couldn't find it. Looks like we'll need a wrapper to expose static funcitons. Thanks
|
|
|
|
|
You could create a singleton object in C# project, that could provide access to the static methods.
|
|
|
|
|
There's no need, I suppose, since he already has a class. He has simply to wrap the static method with an instance one.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
newkie wrote: The question is, how do I call the static subtract method?
afaik, and my weak knowledge in COM, i haven't seen STATIC method being exported by COM model
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
|
Hi to all,
I am facing a strange problem, i had asked for help in the forum few days before. But due to certain delays i was unable to show the code. Here is the code. My Problem is with hindi fonts.
When i substitute the the LOGFONT.lfHeight with 0(Zero) then everything works fine, But when i change the size of lfHeight to anything greater or lesser than zero, the Hindi fonts is displayed very small. How to solve this issue.
case WM_INITDIALOG:
LOGFONT lf;
HFONT cFont;
HWND target = GetDlgItem(hwnd,IDC_STATIC1);
HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
GetObject(hFont, sizeof(LOGFONT), &lf);
lf.lfHeight = 0;
cFont = CreateFontIndirect(&lf);
SendMessage(target,WM_SETFONT,(WPARAM)cFont,MAKELPARAM(TRUE,0));
SetWindowText(target,_T("C:\\Program Files\\অভিধান: ইংরেজী\\सरकारी &&"));
break;
sorry for posting twice.
Regards,
Vishal
modified on Thursday, June 9, 2011 1:32 PM
|
|
|
|
|
You need to convert the point height of your font into device units with the following formula:
lFont.lfHeight = MulDiv(nFontHeight, GetDeviceCaps(hDC, LOGPIXELSY), 72);
See the MSDN page for CreateFont()[^] for more information.
The best things in life are not things.
|
|
|
|
|
i am using
-MulDiv(iPointSize,GetDeviceCaps(GetDC(target),LOGPIXELSY),72);
Where iPointSize is the size of font;
But, the results are not up-to mark. If i specify the
lFont.lfHeight = 14
then, the text in english font is ok but the text in hindi font seems like the lfHeight is 8 .
But if i specify the
lFont.lfHeight = 0
Whether hindi or bengali or chinese every font is in same height and looks good, but their sizes are big.
I am using default MS Shell Dlg Font.
Regards,
Vishal
|
|
|
|
|
Try the positive value returned by MulDiv() and/or one of the other fonts, if possible one that was designed for Hindi characters.
The best things in life are not things.
|
|
|
|
|
Yes sir, i had tried. Mangal gives positive result for hindi fonts.
And Trebuchet MS for others.
Sir, i have one small doubt. Do we have to distribute these fonts with application or these are system default fonts available on windows.
and (negative) -MulDiv() gives good result instead of (postive) MulDiv() . Is it OK. Please guide.
Regards,
Vishal
|
|
|
|
|
vishalgpt wrote: Please guide.
I'm afraid I don't have the answer to these questions, you will have to investigate the rest for yourself.
The best things in life are not things.
|
|
|
|
|
thanx.
Regards,
Vishal
|
|
|
|
|
From memory, a negative lfHeight means "points" as opposed to pixels, but you'd have to check the definitions on msdn for LOGFONT.
Iain.
I am one of "those foreigners coming over here and stealing our jobs". Yay me!
|
|
|
|
|
Iain Clarke, Warrior Programmer wrote: From memory, a negative lfHeight means "points" as opposed to pixels
Thanx for the point. I will check the definitions
Regards,
Vishal
|
|
|
|
|
how to get the code of OnLButtonDown and OnMouseMove etc in OnDraw method ?
|
|
|
|
|
What do you mean exactly ?
Could you please give more information about what you are trying to do ?
|
|
|
|
|
iampradeepsharma wrote: how to get the code of OnLButtonDown and OnMouseMove etc
Do you want generate your own OnLButtonDown and OnMouseMove messages or you want to use that methods functionality?
http://www.mono-project.com/Main_Page
|
|
|
|
|
Your questions is not really clear.
You can see the mouse state Using GetKeyState function. You can know the mouse position using GetCursorPos
Check if this helps?[^]
|
|
|
|
|