|
- whacks myself on the head -
I was nearly going to try exit(0).
Thanks for your help.
modified on Monday, October 13, 2008 1:27 PM
|
|
|
|
|
Hi All,
I'm currently working on my project (which try to perform degree reduction for a Bezier curve).
I've spent a long time trying to find library or useful class to help me perform matrix inversion.
For a degree reduction in Bezier's curve (let's say from degree 3 to degree 2)
B2: bezier curve for degree of 2 (which is unknown in this case)
B3: bezier curve for degree of 3 (which is a given in this case)
M: A matrix involving bezier curves (I already wrote a function to get this matrix)
The fomula to find B2 is as followed:
B2 = inverse(Mtranspose * M) * M * B3
I wrote function to perform matrices multiplication and matrix transpose. I'm having a great deal of difficulty integrating TNT::JAMA_LU and other classes I've found. I just want to do an inverse of a matrix (dimension NxN)
I've spent too much time trying to figure out how to do matrix inversion and that's not even the main point of my project.
Can anyone provide me with good resources? I really appreciate any help in advance.
|
|
|
|
|
You may have a look at Numerical Recipes in C++ [^]. There's also a free online version of the older Numerical Recipes in C book [^].
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]
|
|
|
|
|
Try doing a code search on krugle, koders or google code search. There is some code floating around.
Kevin
|
|
|
|
|
I think I've got an inverse algorithm i can implement in c++...
I got the code in Java...and converted into c++ and into my program.
However.. i ran into some problem..
Please correct me if i'm wrong:
type double in Java is more precise than those in c++. As i'm doing some comparison for example:
if(a>b){
//a might be 0.666666667890 in java
//b might be 0.666666667590 in java
//a might be 0.666666667890 in c++
//b might be 0.666666667590 in c++
and c++ won't detect that a is greater than b
}
what type is more precise than double? perhaps i should try out long double
** edited **
still not doing the job.
any idea?
|
|
|
|
|
xb211 wrote: type double in Java is more precise than those in c++
I strongly doubt about.
For instance Visual Studio 6 compiler uses a 8-bytes double data type , exactly like Java .
xb211 wrote: As i'm doing some comparison for example:
if(a>b){
//a might be 0.666666667890 in java
//b might be 0.666666667590 in java
//a might be 0.666666667890 in c++
//b might be 0.666666667590 in c++
and c++ won't detect that a is greater than b
}
The same (VC6 ) compiler gives the correct result on such a comparison.
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]
|
|
|
|
|
CPallini wrote: The same (VC6) compiler gives the correct result on such a comparison.
CPallini wrote: xb211 wrote:
As i'm doing some comparison for example:
if(a>b){
//a might be 0.666666667890 in java
//b might be 0.666666667590 in java
//a might be 0.666666667890 in c++
//b might be 0.666666667590 in c++
and c++ won't detect that a is greater than b
}
I meant...
the result I have from c++
a: 0.000000 b: 0.166667
a: 0.166667 b: 0.166667
the result from java
a: 0.0 b: 0.16666641666679166
a: 0.16666658333320838 b: 0.16666641666679166
when comparing a and b...
the 2nd case, c++ will say they are the same whereas in Java, it says they are different.
|
|
|
|
|
I suppose something is lost in traslation.
Check your code.
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]
|
|
|
|
|
I just wrote:
double testing = 0.1242923758275093850928390582;
cout << "testing: " << testing << endl;
printf("testing: %f\n",testing);
output:
testing: 0.124292
testing: 0.124292
*** edited ***
I added:
#include <iomanip>
cout << "testing: " << setprecision(20) << testing << endl;
printf("testing: %f\n",testing);
testing: 0.12429237582750939
testing: 0.124292
But.. how do i set the variable itself to have precision of 20 (for example)?
|
|
|
|
|
Interesting.
Try the following with the good old (euphemism) VC6 compiler:
#include "stdafx.h"
#include <iostream.h>
#include <iomanip.h>
void main()
{
double testing = 0.1242923758275093850928390582;
cout << "testing: " << setprecision(23) << testing << endl;
printf("testing: %25.23f\n",testing);
}
</iomanip.h></iostream.h>
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]
|
|
|
|
|
I did:
double testing = 0.1242923758275093850928390582;
double testing1 = 0.1242923758275093850929390582;
or
long double testing = 0.1242923758275093840928390582;
long double testing1 = 0.1242923758275093940929390582;
if(testing1>testing){
cout << "YAY" << endl;
}
it doesn't print out "YAY"
|
|
|
|
|
And what about the Java behaviour with the same inputs?
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]
|
|
|
|
|
Ehh.. oops.. i need to re-look at my code!
|
|
|
|
|
PROBLEM SOLVED! it was some initialization issue.
in c++... i passed in a fraction ~ 2/3 = 0.66666666666666666666667 (for example)
in java... i passed in 0.6666666667
What was I thinking huh?
Thanks for all the help! Really appreciate it!
|
|
|
|
|
Your welcome.
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]
|
|
|
|
|
Hi,
i have a Sdi with a splitter (4 rows).
When i click on the maximize button the window is maximized and the 1. splitter row changes its height proportionally , but when i try to restore, nothing happens with the Splitter ;(.
Please help me !
Here is my code:
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
int iCurRow_cy = 0, iMin_cy = 0;
static int iOldWnd_cy = 0, iOldWnd_cx = 0;
int iNewCurRow_cy = 0;
static int iZaehler = 0;
static CString a, b, c, d;
iZaehler++;
if (iZaehler == 1)
{
iOldWnd_cy = cy;
a.Format("%02d",iOldWnd_cy);
b.Format("%02d",cy);
c.Format("%02d",iCurRow_cy);
d.Format("%02d",iNewCurRow_cy);
MessageBox("iOldWnd_cy: "+ a + "\ncy: " + b + "\niCurRow_cy: " + c + "\niNewCurRow_cy: " + d,"in: iZaehler == 1 " ,MB_OK);
}
if ((nType == SIZE_MAXIMIZED))
{
m_Splitter_Main.GetRowInfo(0 ,iCurRow_cy, iMin_cy);
iNewCurRow_cy = (int)ResizeSplitter(cx, cy, iOldWnd_cx, iOldWnd_cy, iCurRow_cy, 1);
a.Format("%02d",iOldWnd_cy);
b.Format("%02d",cy);
c.Format("%02d",iCurRow_cy);
d.Format("%02d",iNewCurRow_cy);
MessageBox("iOldWnd_cy: "+ a + "\ncy: " + b + "\niCurRow_cy: " + c + "\niNewCurRow_cy: " + d,"in: SIZE_MAXIMIZED " ,MB_OK);
m_Splitter_Main.SetRowInfo(0, iNewCurRow_cy , 0);
m_Splitter_Main.RecalcLayout();
}
else if((!m_Splitter_Main.m_hWnd && nType == SIZE_RESTORED))
{
m_Splitter_Main.GetRowInfo(0 ,iCurRow_cy, iMin_cy);
iNewCurRow_cy = (int)ResizeSplitter(cx, cy, iOldWnd_cx, iOldWnd_cy, iCurRow_cy, (1));
a.Format("%02d",iOldWnd_cy);
b.Format("%02d",cy);
c.Format("%02d",iCurRow_cy);
d.Format("%02d",iNewCurRow_cy);
MessageBox("iOldWnd_cy: "+ a + "\ncy: " + b + "\niCurRow_cy: " + c + "\niNewCurRow_cy: " + d,"in: SIZE_RESTORED " ,MB_OK);
m_Splitter_Main.SetRowInfo(0, iNewCurRow_cy , 0);
m_Splitter_Main.RecalcLayout();
}
CFrameWnd::OnSize(nType, cx, cy);
}
double CMainFrame::ResizeSplitter(int cx, int cy, int iOldWnd_cx, int iOldWnd_cy, int iCurRow_cy, int iZahl)
{
double iNewCurRow_cy;
double iDiff;
double iFaktor;
CString ccc;
CString ddd;
CString aaa;
CString bbb;
iDiff = cy - iOldWnd_cy;
iFaktor = iDiff / cy;
iNewCurRow_cy = (iCurRow_cy * ((iFaktor)+(iZahl)));
return iNewCurRow_cy;
Many, many thanks !
Best regards !
Croc
|
|
|
|
|
REALLY NOBODY !!!???
Best regards
Croc
|
|
|
|
|
Have you tried handling WM_WINDOWPOSCHANGED?
This is called whenever you minimize, maximize, restore or move. I reckon you'll get away with
making the code in your onSize handler respond to WM_WINDOWPOSCHANGED instead of WM_SIZE.
modified on Sunday, October 12, 2008 8:44 AM
|
|
|
|
|
THX enhzflep,
i'll try it !!!
Best regards
ShadowEater
|
|
|
|
|
Look at the following piece of code:
class IAbstractBase
{
public:
virtual void funca() = 0;
};
class IAbstractDerived : public IAbstractBase
{
public:
virtual void funcb() = 0;
};
class BaseImpl : public IAbstractBase
{
public:
void funca() { }
};
class DerivedImpl : public BaseImpl, public IAbstractDerived
{
public:
void funcb() { }
};
void some_func()
{
DerivedImpl* x = new DerivedImpl();
}
The compiler now tells me that i can't instanciate DerivedImpl, because funca() has no implementation. What i don't understand is that funca() is defined in BaseImpl, which is a base class of DerivedImpl, but the compiler doesn't care about that.
Here is the exact compiler output:
------
.\Test.cpp(33) : error C2259: 'DerivedImpl' : cannot instantiate abstract class
due to following members:
'void IAbstractBase::funca(void)' : is abstract
.\Test.cpp(6) : see declaration of 'IAbstractBase::funca'
------
Any idea for a solution of that problem?
|
|
|
|
|
Why do you use the (slighty modified) diamond inheritance pattern? could you avoid it, couldn't you?
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]
|
|
|
|
|
I don't think that it is really a diamond.
Please look at my answer at: (link)[^]
|
|
|
|
|
Andreas Kilian wrote: What i don't understand
Multiple inheritance diamond problem[^]
Andreas Kilian wrote: Any idea for a solution of that problem?
No because that depends on your requirements which you have not provided. Essentially you need a different design which of course is based on the requirements.
led mike
|
|
|
|
|
The diamond:
IAbstractBase
/ \
/ \
BaseImpl AbstractDerived
\ /
\ /
DerivedImpl
Andreas Kilian wrote: Any idea for a solution of that problem?
You could maybe use virtual inheritance, but be sure
it's what you want (that's why this code throws a warning)...
class IAbstractBase
{
public:
virtual void funca() = 0;
};
class IAbstractDerived : public <code>virtual</code> IAbstractBase
{
public:
virtual void funcb() = 0;
};
class BaseImpl : public <code>virtual</code> IAbstractBase
{
public:
void funca() { }
};
class DerivedImpl : public BaseImpl, public IAbstractDerived
{
public:
void funcb() { }
};
I have a feeling that may not be what you want...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi!
I don't think that it is a classical diamond because IAbstractBase and IAbstractDerived are pure virtual. I think my problem is that i've been programming Java and C# for too long. In those languages the classes IAbstractBase and IAbstractDerived were interfaces. Java code would look like:
interface IAbstractBase {}
interface IAbstractDerived extends IAbstractBase {}
class BaseImpl implements IAbstractBase {}
class DerivedImpl extends BaseImpl implements IAbstractDerived {}
this is totally legal and works fine in Java. I just adopted that design and took "pure virtual classes" in C++ as what is called an "interface" in Java (and C#).
I rewrote the code to:
class IAbstractBase { };
class IAbstractDerived : virtual public IAbstractBase { };
class BaseImpl : virtual public IAbstractBase { };
class DerivedImpl : public BaseImpl, virtual public IAbstractDerived { };
Virtual inheritance solves the compiler error. What i've done is using virtual inheritance for all pure virtual classes. But i still get a warning:
.\Test.cpp(34) : warning C4250: 'DerivedImpl' : inherits 'BaseImpl::BaseImpl::funca' via dominance
.\Test.cpp(24) : see declaration of 'BaseImpl::funca'
I'm sure i can safely ignore this warning because there's only one inheritance path which has function implementations (and data members). All other add just pure virtual functions.
But thanks for you anser! Your hint to virtual inheritance solved my problem.
|
|
|
|