Hi all,I thought I'd mention a useful class I've put together. Basically it's a class that can find the roots of any polynomial up to 4th degree. You can use this to solve problems such as circle-circle and ellipse-ellipse intersection for collision detection and such.Link here.Enjoy/

It's really useful when doing collision detection to know the points of intersection - especially if you're trying to simulate objects moving across each other.

To be helpful, here's how you get the intersection points for circle-circle intersection. You have two circles, given by the equationsThe second equation is written in terms of the origin of the first. Thus you can get (X,Y) in the second equation by subtracting the origin of the first circle from the second.

Subtract the second equation from the first, expand, and solve for x. Substitute that solution into the first equation, then solve for y. You get a quartic equation with coefficients A, B, C, D, and E given by

The last one looks really complicated, I know. Once you have the coefficients, use the Quartic polynomial class to get the roots. If there are no real roots, then the circles don't intersect. If they are real, you solve the first equation for x and put the roots into y. And there you have it, intersection points of two circles.

Once you have the intersection points, you can get a tangent vector, and project any movement of the circles along it. Or you can use it to compute trajectories post-collision.

That is really cool. I can't wait to wrap my head around this. Your explanation is really helpful.

I hope to eventually interface primitives of arbitrary types, so that the intersection point(s) of, say, an ellipse and a triangle could be calculated. Even a cursory understanding should help in figuring out how to abstract things... I'm just sad that by the time I get that understanding, this topic will already have been archived.

That's is negative thing actually. Placing executable code into header makes it being recompiled every time you recompile a file that use it and it will create it's own object code for every file.

Speaking of C++ part. Vector2D class doesn't need to be a class. Essentially it's simply a struct, it doesn't have anything that makes it reasonable to use classes. That's one of the thing that's wrong with modern OOP languages: they teach programmers to use classes for everything. Like there's no other approach exists. Java and C# are especially guilty for that. While what modern OOP languages offer is not even real OOP as it defined, just a bunch of syntax sugar on top of plain imperative programming. And as for C++, it's not even good at making the sugar sweet.

C++ may not be the worst programming language ever created, but without a doubt it's the worst ever to be taken seriously.

Also it uses #pramga once for some reason, even though including the file into code file couldn't case multiple inclusions, while including it from different files doesn't save from being included in all of them, which makes include guarding meaningless as every file would need the whole header, not just one of them. It would only make sense if you include this file in both header and code file, which doesn't make sense in the first place. There is reasons why function definitions don't go to header files. Luckily, all it takes to fix it is cut-pasting function definitions to the code file.

I see lack of meaningful comments. Most of them are Captain Obvious-style descriptions, few others are branching roadsigns. Saves that the whole thing doesn't need any comments anyway, so that's not really negative thing.

Well, I use C, so I'd had to rewrite entire thing if I wanted to use it.

Well, he did this in his free time and I guess it was allot of work. He gives it to others for free. And he can use the language that he wants.Nobody forces you to use this. If you want to use it with a language that his work isn't compatible with you have to rewrite it yourself.Your post sounds like he put a burden on you because he didn't code in the language of your choosing. You don't have to use it. Write your own useful class.

And just because you don't like C++ and you found people on the internet that don't like it as well does not mean that nobody is allowed to use it.

It comes across very impolite and not constructive. More so because it sounds like you don't even want to use it. You just complain that you couldn't.

I don't see how blaming OOP for obvious crimes a little is impolite. It may be not constructive though, but it comes as a spot-on for the case. Still, there were no reason to make a stress on it that much.

You also sounded like one of those C++ fanboys who sincerely can't see any flaws in their language of worshipping and treat any pointing out of such as a personal insult. Even though I didn't even pointed at anything, just made a statement in a general direction on a narrow topic.

I do sound like a C++ fanboy? I don't even use C++. And I didn't say one positive thing about C++ and I didn't even mention OOP (and btw: I can see flaws in OOP but that's content for another thread ).

The only thing I mentioned is that the OP can use whatever language he likes and that the way you present your opinion sounds impolite.

How you still were able to read C++ Fanboism into my post eludes me.

I didn't even relate to your C++/OOP statements but just to the part I quoted.The part I quoted did sound like just because you want to use C everyone has to use C. Because otherwise you would have to do work when you want to use stuff that other people do in their free time.

If I misunderstood you then I apologize.As said it wasn't related to you c++/oop statement in the rest of the post.

By pretending the classes are structs? He just wouldn't have to go through the hassle of setting up all the "function pointers" himself, and the syntax for calling them will be nicer too since he won't need to pass in the "struct" or any members. As for the use of templates, just pretend they aren't there and only use the typedefs in the header?

That is a perfectly fine question and I don't get what the other two are talking about. Surely they are not suggesting to compile C as C++, which doesn't work in general.

You cannot use C++ libraries (like the one in OP) with C without writing a C API wrapper for it, period. You won't need to rewrite the whole thing, but you will need to wrap the C++ API with a C one. Although, glancing at the code your time will be better spent rewriting it in C anyway.

I glanced at the code itself and I take issue with the way operator() is implemented. It really should use Horner's method. Also, I don't see the point of the Vector2D class. There is already std::complex which you should have used. N.B. if somebody does want it in C, you'd use _Complex from C99.

EDIT: Also... GPL'd header-only library? Surely you must be joking . I'd suggest using template specialization to make it a header + cpp file (and switch to LGPL maybe) so you can at least use it without needing to relicense the whole project as GPL... not that there's anything wrong with that .

I tend to use C++, though I certainly understand the differences between the two styles and find myself programming C-style modules in C++ more often than not.

Last night, though, I realized I had made an entire module in C++ using absolutely no C++ specific features. I decided to change it to C--and lo and behold, the compiler blows my mind: Apparently, C doesn't have the bool type. I could have sworn bools were backported at some point (ala C++ style comments).

Well, (with x86) the smallest possible data size a program can fetch without using bithacks is 8 bit, a char, so in ANSI C you #define bool char #define true 1 #define false 0 if you need booleans that much. Or you typedefenumbool{false, true} which makes more sense. Otherwise you simply use char and 0 for false with anything else for true.

...with typedef you can also typedefenumbool{false, true, uncertain }... yeah...