|
|
Is it possible to calculate the angle of a line given 2 points (x, y) and how?
|
|
|
|
|
yes TWO POINTS (x1,y1) & (x2,y2)(it is a line,so it should have two cordinate points!).....
consider.....
then slope can be said to be : m =(y2-y1)/(x2-x1)
then find the arctan of the slope 'm' ,u get the angle
try googling....to find more info....try this link :http://www.purplemath.com/modules/slope.htm[^]
cheerz.....
"faith, hope, love remain, these three.....; but the greatest of these is love" -1 Corinthians 13:13
|
|
|
|
|
Gee, thanks!
Does this only work on the Cartesian coordinate plane or this can also work with screen coordinates? I want to find the angle of a line plotted by MoveToEx and LineTo API functions.
|
|
|
|
|
itz a mathematical concept....it will work anywhere.....
if u r using the screen cordinates,then u must first make it like the cartesian type(mind u it is already of cartesian type but a little different)
that is.....
in the cartesian type,the origin is designated as (0,0).
for the screen cordinates it is not so,SO u will have to make it like that by shifting the points accordingly(better known as mapping)
say.....
u have a window
where x,y define the length and width of the window respectively!and (x/2,y/2) happens to be the center of the window
u will have to map it to cartesian type.....
and voila....
u have the cartesian type..
now use the formula to get the angle.....by the way....are u doing vector related graphics?.....
cheerz.....
"faith, hope, love remain, these three.....; but the greatest of these is love" -1 Corinthians 13:13
|
|
|
|
|
Angle of line with respect to what? The point (x,y)
I didnt get ur query..
what are the paramenters of line avaialable?
cheers,
Super
------------------------------------------
Too much of good is bad,mix some evil in it
|
|
|
|
|
I'm trying to get the angle of the line plotted with the MoveToEx and LineTo API functions with the points x1, y1, x2, y2.
|
|
|
|
|
Does anybody know if CGdiObject::CreateStockObject requires a call to CGdiObject::DeleteObject once the object is no longer needed ? (I can't find any answer in MSDN!
|
|
|
|
|
Its always better to delete any object which you create. ITs a gud programming ethics.
cheers,
Super
------------------------------------------
Too much of good is bad,mix some evil in it
|
|
|
|
|
Hello,
Mircosofts Reference says:
"It's not necessary (but it is not harmful) to delete stock objects by calling DeleteObject."
|
|
|
|
|
Hi,
I was just refering to usual programming ethics of creation and deletion of objects. My post was not specific to stock objects
cheers,
Super
------------------------------------------
Too much of good is bad,mix some evil in it
|
|
|
|
|
|
I'm making mpegPlayer.
but I cannot add random mode.
when i check random and play music.
'stack overflow' happen and go debug mode.
and No check on Repeat, Random next button clicked random mode has start
What is missing my program?
this is OnNext() -> when i next button clicked has happen
OnNext()
{
srand((unsigned)time(NULL));
int m_nPlayIndexTemp;
int nCount = theApp.GetMainDlg()->m_pDlg_PlayList->m_PlayList.GetCount();
if( theApp.GetMainDlg()->m_pDlg_PlayList==NULL)
return;
if( m_nPlayIndex > theApp.GetMainDlg()->m_pDlg_PlayList->m_PlayList.GetCount()-1 )
m_nPlayIndex = 0;
if( m_bRandom = true )
{
m_nPlayIndexTemp = rand()%theApp.GetMainDlg()->m_pDlg_PlayList->m_PlayList.GetCount();
if( m_nPlayIndexTemp != m_nPlayIndex )
{
m_nPlayIndex = m_nPlayIndexTemp;
}
else
{
OnNext();
}
}
else if ( (m_bRepeat = true && m_nPlayIndex) == nCount )
{
m_nPlayIndex = 0;
}
else if( ((m_bRepeat = false)&&(m_bRandom = false)) == true )
{
m_nPlayIndex++;
}
OnPlay();
}
----------------Please help me!!---------------------------
When you need all source.
Please reply and write your e-mail
|
|
|
|
|
Stack overflow happens in general when you have an infinite recursion (a function that calls itself that calls itself that....). Here in your code, you are calling OnNext until you get a different number of the song that is currently played (or at least, this is want you are trying to do).
First thing, don't call OnNext but rather but the selection of a new song number in a loop. This is really horrible (I mean by code):
if( m_nPlayIndexTemp != m_nPlayIndex )
{
m_nPlayIndex = m_nPlayIndexTemp;
}
else
{
OnNext();
}
rather replace it by something like that:
while (true)
{
m_nPlayIndexTemp = CalculateRandomNumberHere();
if (m_nPlayIndexTemp != m_nPlayIndex)
break;
}
Second, the way you use for calculate random numbers is false:
rand()%theApp.GetMainDlg()->m_pDlg_PlayList->m_PlayList.GetCount();
The modulo operator (%) will give you the remainder of the division. So for example if you have 1 song in the playlist, and rand() gives you 123456, the result will be 123456. Mhh, a little bit outside the bounds of your playlist no ?
Better use something like that:
rand()*nCount/RAND_MAX;
|
|
|
|
|
The info about the modulo operator is wrong. Modulo will give you the remainder, correct, but the remainder of 123456/1 is, have we guessed it yet, 0!!!
Any integer divided by 1, will leave no remainder. Similarily any integer divided by 2 will leave a remainder of 0 or 1, any integer divided by 3 will leave a remainder or 0, 1, or 2. And so on...
So the ouput of that expression will be inside your bounds if you have 1 element in your array. Also it will be in your array's bounds aslong as the size of the array is equal to (or greater than) the number of items in your playlist.
Be careful to check that if theApp...PlayList.GetCount() returns 0, (i.e. your playlist has no entries), that you don't calculate rand()%theApp..GetCount(), as rand()%0 will cause a 'Divide By Zero exception'.
|
|
|
|
|
one can burn cd disc or dvd disc with dvd-r drive, right?
the problem is that...
then an application can possibly know which media,
cd or dvd disc is inserted?
so that an application let users know how much data, 700M or 4.7G they can burn,..
is it possible or not to know in advance
(before burning started) ?
|
|
|
|
|
A CDR/RW has a "pre-burnt" area called ATIP (Absolute Time In Pregroove).
Most burners are able to read that area. (The ATIP isn't readable by a CD/DVD-ROM).
You read it by means of a SCSI-command to the burner.
That area givs you the recording time (for this disc) in minutes, seconds and frames.
As far as I can remember, a DVD has a similar area, but I can't remeber it's name right now.
But as usual, Google is your best friend...
|
|
|
|
|
While building a COM exe which is created using ATL COM App wizard, I got an link error "uuid.lib(comcat.obj) : fatal error LNK1103: debugging information corrupt; recompile module" .
What is the problem here and what will be the solution?
Thanx in advance..
|
|
|
|
|
I'd be starting with a clean and rebuild all. That appears to be what the system is telling you to do.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I had tried that also....
Another point is I had do nothing in the code that ATL COM App wizard created for me.
|
|
|
|
|
|
Ya, that is the scenario.
I could build it after removing SDK includes and libraries from
tools --->Option.
|
|
|
|
|
Hi
I am developing a Windows application which interacts with a add-on hardware device on a laptop. The device is connected to the laptop via., a USB cable. I am creating a thread to read from a flat file and write the contents to the USB. The thread runs normally if the Windows session is not disturbed. But if I try to minimise a window, maximise, open another application, or even turn off my monitor the thread is disturbed and the data is corrupted. Any solution to this? One of my friends in CodeProject suggested to raise the priority of the thread to a real time level so that it is not interrupted even by kernel threads. I tried doing this by setting a flag in AfxBeginThread and starting the thread. I hope the thread is created with real time priority, but still the problem exists.
Is there any other way to increase the priority of the user thread?
Please help...
Sreekanth Muralidharan,
Corporate Systems Consultant [Embedded Systems],
INDIA
|
|
|
|
|
Sreekanth Muralidharan wrote:
I hope the thread is created with real time priority
I Believe, Real time Priority Thread is not good solution to you problem!. AFAIK, you are developin gyou application using worker thread, my suggesstion will be create UserInterface thread and handle different POWER EVENT and Windows Event within UI thread!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
hi,
i am developing a folder watching application. i want to use the fuction FindFirstChangeNotification and ReadDirectoryChangeW.
The problem here is when i create a MFC project using Dialog approach
i inlcude the sample code MSDN provide in a button handler function, and if i run it, the application will hung and i have to use task manager to close it.
the same thing happen if i use ReadDirectoryChangeW.
however if i put the same code in a win32 application project( using MFC shared .dll ), it can works well.
Pls help, thanks, the msdn sample code is below:
DWORD dwWaitStatus;
HANDLE dwChangeHandles[2];
// Watch the C:\WINDOWS directory for file creation and
// deletion.
dwChangeHandles[0] = FindFirstChangeNotification(
"C:\\WINDOWS", // directory to watch
FALSE, // do not watch the subtree
FILE_NOTIFY_CHANGE_FILE_NAME); // watch file name changes
if (dwChangeHandles[0] == INVALID_HANDLE_VALUE)
ExitProcess(GetLastError());
// Watch the C:\ subtree for directory creation and
// deletion.
dwChangeHandles[1] = FindFirstChangeNotification(
"C:\\", // directory to watch
TRUE, // watch the subtree
FILE_NOTIFY_CHANGE_DIR_NAME); // watch dir. name changes
if (dwChangeHandles[1] == INVALID_HANDLE_VALUE)
ExitProcess(GetLastError());
// Change notification is set. Now wait on both notification
// handles and refresh accordingly.
while (TRUE)
{
// Wait for notification.
dwWaitStatus = WaitForMultipleObjects(2, dwChangeHandles,
FALSE, INFINITE);
switch (dwWaitStatus)
{
case WAIT_OBJECT_0:
// A file was created or deleted in C:\WINDOWS.
// Refresh this directory and restart the
// change notification. RefreshDirectory is an
// application-defined function.
RefreshDirectory("C:\\WINDOWS")
if ( FindNextChangeNotification(
dwChangeHandles[0]) == FALSE )
ExitProcess(GetLastError());
break;
case WAIT_OBJECT_0 + 1:
// A directory was created or deleted in C:\.
// Refresh the directory tree and restart the
// change notification. RefreshTree is an
// application-defined function.
RefreshTree("C:\\");
if (FindNextChangeNotification(
dwChangeHandles[1]) == FALSE)
ExitProcess(GetLastError());
break;
default:
ExitProcess(GetLastError());
}
}
|
|
|
|