Plotting lines in C++ [closed] - c++

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have code to solve 2D truss structures implemented in C++ (as a console application).
I would like to add some simple graphics to it in order to visualize the initial structure and the deformed form. Example: http://people.rit.edu/pnveme/VenkatCOMSOL42/COMSOLTruss2D/ExtractingInfoinMATLAB_01.png
But I have no idea of how to add graphics in any way. How can I implement this kind of graphics?
Cross platform (preferred) or windows.

I doubt this is the answer you want, but to be honest, implementing plotting functionality isn't trivial, even if you're not doing it from scratch: you'll have to review a number of libraries, choose one, and get to grips with it.
Unless it's essential that the plotting functionality be integrated with the solver (e.g. for a product), I think you ought to consider simply exporting your results to, say, a simple ASCII matrix format that can be easily imported into a variety of environments with extensive and flexible plotting capabilities, one or more of which you probably already know (e.g. Matlab, R, Octave, etc.)

One option would be to generate a file which can be shown by another program. For example, generating SVG and using the browser to display it sounds like it would be good for your case, you can even easily include it in a report.

Check out SDL: http://www.libsdl.org/ It's cross-platform and has a ton of features. It maybe a bit overwhelming for your task, but I thought it was very easy to grasp when I was a newcomer.
There is a derivative of SDL that lets you draw basic shapes such as lines and points and is incredibly easy to use:
http://sdl-draw.sourceforge.net/

Related

Ubuntu c++: The easiest way to display a 3D mesh and a 2D image together? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I've been fighting with several libraries (irrlicht, Ogre3D etc) and falling between either too complex libraries or too complex installation guides.
I'd appreciate some pointers to how to achieve what the title suggests.
Thanks
If you're going for simplicity of setup and use, I'd recommend you Unreal Engine. It not only allows you to render both in 3D and 2D, but has a lot of other functionality including scripting in c++.
If you're looking for a more lightweight solution, though not as easy, you can try using OpenGL. It is quite easy to set up - just install Code::Blocks and start with their OpenGL template. Although it is much harder to learn and use, it is very developing.
If you don't really need to use c++, you can use Unity. Although its interface is exposed through c#, its not very hard to learn for a c++ programmer. I also find it easier to use than Unreal Engine.
I would also reccomend Vulkan, which would probably the most perforamant of all of them, but well, you wanted a "simple" solution.

What is the simplest solution for a program to draw lines and pixels using C++? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I am an electronic engineer and shall be designing a hardware system that renders 2D and later 3D graphics. Before I can do things in hardware I will need to test the algorithms that I read in books. Basically I need to write C++ program that can draw lines and individual pixels on screen. I shall use this to test all of algorithms before I write VHDL to achieve the same in hardware.
What method/solution do I use to get a window that I can draw pixels and lines in using C++? I will test my projection matrix code and bresenham integer line algorithm code among other things. I do not need anything more complex as it will defeat the purpose e.g if the program automatically shades surfaces or does automatic hiding of hidden surface then the purpose is defeated.
The easiest way for someone in your situation is probably to write a command-line program that generates a bitmap image file in a Netpbm format (PPM, PGM, or PBM).
See: https://en.wikipedia.org/wiki/Netpbm_format
They're super easy to generate. If you can't find a program to view them directly, you can convert them into a more popular compressed format with ImageMagick or similar tool

Good C++ alternative to MATLAB's "fminunc"? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am trying to convert some code written in MATLAB to C++. I'm having some (or actually quite a lot of) trouble finding an alternative to the "fminunc" function which is used in the MATLAB code that I can replace and use in the C++ code. I've been looking at the "dlib"-library because I've heard it could be a function there I can use, but I'm not sure what function to use.
This is how the "fminunc" is used in the MATLAB code I want to convert:
[theta, cost] = ...
fminunc(#(t)(costFunction(t, X, y)), initial_theta, options);
Does anyone know any good optimizing functions like this in C++?
I believe what you are looking for is Google's Ceres Solver, an open source C++ library for modeling and solving large, complicated optimization problems. The code is designed to handle two classes of problems:
Non-linear Least Squares problems with bounds constraints.
General unconstrained optimization problems.
Automatic Differentiation is also supported.
Several cool example applications can be found here.
There are a bunch of optimizers in dlib, some that use gradients and others than just work on black-box functions. You can see some examples here http://dlib.net/optimization_ex.cpp.html and more generally here http://dlib.net/optimization.html.

Recommended Animated Model Format to Load in OpenGL [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
What is the recommended animated model format that a game programmer would load in OpenGL?
I have taken a look at .md2 and .3ds formats available at some OpenGL tutorials. However, it would appear that they are both fairly old. Is there any well-supported model format that a contemporary game programmer would prefer?
If you're a beginner, you should probably start with those formats. (Or maybe MD3, which comes after MD2.) Newer 3D formats don't typically supercede old ones by being objectively better, but usually by supporting more complex features. I'd recommend not making life difficult for yourself by picking a complex format.
If you're not a beginner, then you probably wouldn't be asking this question. ;) Professional developers usually have a bespoke model type that is specific to the engine they're using.
If you have specific requirements for your models then it's possible that there exists a model format that fits your needs, but MD2 and MD3 worked fine for commercial games so they'll probably work fine for you too. Generally you should approach this from the other side - what sort of models can my artists create, or what sort of models can I obtain? What format are they in? Can I use that format?
ms3d seems quite common. (there are links to the format on that page).
FBX is another. There is no good documentation for the format but there is an SDK to load it. On directx .x files would be another option but that's probably not so much use ofor opengl. (And it's not really that well supported on directx any more).
The most common format though seems to be to define your own application specific format that contains just what you need and use an exteral converter to convert to that format.

Ideas for a C/C++ library [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I thought one of the best ways to familiarise myself with C/C++, is to make a helpful library. I was maybe thinking like a geometry library, like to calculate areas, surface area, etc. It would be useful in game programming. Or maybe an algebra library, like for different formulas like the distance formula, quadratic formula, etc. Or maybe like a standard library for very simple functions, like calculating the number of items in an array.
If it is for the sake of an exercise, writing a library to deal with fractions is a good one.
http://en.wikipedia.org/wiki/Fraction_(mathematics)
Implement the basic operations and a way to print them.
Find a problem that you need to solve. Look around to see if a library exists already. If not, then solve it in a way that others can benefit and put the library up on something like github.
But please be prepared to support it if you want to really see it being used - nothing worse than a open source project that isn't well supported.
I'd encourage you to try and come up with an application that would make use of the library. A game, a business app, whatever. Maybe even come up with an application idea first then determine what libraries you would need that aren't readily available.
That way you know you'll be creating something of practical value and not just undertaking a purely intellectual exercise. Try and avoid just plucking a library idea out of the air as you'll inevitably reimplement something that already exists. That's fine for you to learn but it would be awesome if you could create something others could benefit from in the process :)
Also, your application will provide a ready made test for your library.
Much of what you're listing has been done and can be found in Boost and or GSL. If learning is your goal, how about write a Qt application that uses some of these math functions?
Creating 'toy' level libraries doesn't help much on learning C++. I'd suggest you look at the libstdc++ bugs, try to understand and help fixing some ones.