x-y plot using C language [closed] - c

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
I know there are already other posts about this, but I am unable to get the recommended libraries running.
I am writing a program in C. I am fairly inexperienced at programming. I need to plot the results on an x-y graph. There will be potentially hundreds or even thousands of points. The points will be plotted as the program calculates them, so the graph may need to scroll sideways if the x-axis is exceeded.
So, basically, what I need to do is open a window with x-y axes and plot points in this graph as my program comes up with the numbers. I am looking for the simplest and quickest way to get this written, and it's just a way for me to visualise the results. Can C handle this or do I need a library? If a library, I need one that is easy to set up as my experience is limited.
Thanks in advance
Andrew

If you look for a library to be linked into yours program then MathGL (cross-platform GPL plotting library) is better than gnuplot. At this, it can handle huge data sets, can collect plotting (i.e. add plot, add new plot, add new plot, ..., save current result/plot, add new plot, ..., save result). And MathGL have C interface too.
I'm a bit confused by words "so the graph may need to scroll sideways if the x-axis is exceeded". Because it is difficult to place a point (plot) if one don't know the final axis scale(s).
May be you need just a bitmap (or XPM image - 2D array of char) each row/column is proportional to time-step and the height of point is proportional to data value, like
h[i] = Height*(y[i]-ymin)/(ymax-ymin).

I would use gnuplot if on *nix
http://ndevilla.free.fr/gnuplot/
http://ndevilla.free.fr/gnuplot/gnuplot_i/index.html
Looks pretty easy to me

Related

How to clear console without Flikerring in C/C++ [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
So I am making a snake game in C but the problem is that it causes a lot of flickering and it also slow downs the game, So I heard that double buffering can solve this but I don't know how to implement that and other ways will also be appreciated. For now I have just reposition the cursor to 0 and disable the visibility of cursor.
The way games typically prevent this "flickering" is due to double buffering. As the current view is being rendered, the back view is performing updates. When the two views swap, the back view clears and performs the updates for the next frame while the current view is being rendered from the previous frame. In Console, you don't have this luxury and when I was writing my snake game in terminal I solved it by not redrawing the entire console every "frame". Rather, I simply drew an empty space over the last tail position and kept the rest of the frame the same. Similar with the snake going over the food, just draw over it with an empty space.
I believe the function I had written was something like this.
void clearlastposition(GameState* state){
_COORD last;
last.X = state->snake.back().partposition.x;
last.Y = state->snake.back().partposition.y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),last);
printf(" ");
}
In my design, the snake body was a vector of snake parts. Where each part contained an x and y position. And the GameState just held an instance to the snake body.
This was done on Windows.

Model 3D spring from points [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 have generated points like this and now I what to connect all these points into one model - spring. How can I achieve this? I've tried iterating through each point and build it from polygons or triangles but I have failed.
I have set of rings where each ring was build from points which coords I have.
You probably want to treat these as generalized cylinders and tessellate a triangle mesh. This can be done by sweeping a circle along the path. Some of the details are tricky since undefined tangents can lead to unexpected twists in your triangle mesh. You might want to study the GLE library or the TubeGeometry implementation in ThreeJS.
For simplestic rendering, note that OpenGL has GL_LINE_STRIP. It also has glLineWidth, although many platforms have a max width of 1. You would need to take care to use separate draw calls for seperate springs, otherwise they'll be connected.

C guessing game between two players with visual output [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 5 years ago.
Improve this question
I have been given the assignment to create a quite complicated to me, but simple to some C game. The program will run and generate 25 random numbers between 1 to 100 (no repeats). The game is between two users.
Both the players will get two guesses each time. Every correct guess will be counted as 1 correct answer and will be displayed on the screen in the board.
The player having more number of correct guesses will be a winner.
The game will continue until the board is completely revealed.
The first screen should ask the user for his name, print a welcome message, and displays an empty 5x5 board. But this 5x5 board has the values in it internally
Now the program should ask the number of players (1 or 2)
If one, ask one name and second is computer and if 2 ask two names
For playing against computer, you are asked for two guesses and every correct guess is shown on the board.
Now 2 guesses for computer would be taken and shown on the screen.
I have tried everything to my knowledge to complete this but I lack a full understanding of C. Any help would be appreciated. I did not include my code because, honestly its just a mess and does not even run.
I would like to see someone be able to make such a game, so that I can study the logic. NOT COPY THE WORK
Simple steps. Start small and grow.
Easy one is to remove all questions to the user(s). Hard code the answers in the program. You can retrofit the IO later.
Start with a way ot generating 25 random numbers and load them into an array. Place the array in a global variable. You need a another array to show when a number is sucessfully guessed.
Now write a function to display that guessed array as 5X5.
Gradually build the program up
Always make functions
generate_array
show_guessed
....
If get stuck on specific things then post a new question.
This is not a direct answer, but a very long comment with some requests for more information and effort.
The problem I have with your request is that I see zero effort. I see a request for teh C0d3z and a promise not to cheat after receiving something that makes it far too easy to cheat.
What I, and probably others here, want to see is effort and some attempt.
Do you know how to print text to the screen like you see in the requirements? Do you know how to print text at all? If so, make the print routines and state this.
Do you know how to generate random numbers? If so, say so in your question and we see effort.
Do you know how to receive input from the user?
Do you know what an array is?
Do you know how to save code in your editor and compile it?
You can see that without any sort of background or starting code, we don't know where you are in your learning.
So...
Post an attempt at solving your problem in your question. If you are truly so new to coding that you cannot do this, then you need to sit down with your professor / TA / whomever and tell them this. Reading through your teaching material (textbook or whatever) should help a whole lot as well. This assignment feels like something I would see towards the end of a beginner's C class. If this is where you are, and you really have no clue what to do, then you may need to retake the class.

Camera calibration across multiple images [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
Taking one camera and moving it around to take two images of the same object, from a different viewpoint, one should be able to compute a matrix that relates these two scenes. In OpenCV, how is this accomplished?
If said object is a calibration pattern like the chessboard used by OpenCV, then the camera calibration routine mentioned by ChrisO would give you both the camera intrinsics (focal length, principal point, and lens distortion) as well as the camera extrinsics (where they are relatively in space).
If you have general object, then you need to establish a set of 2D correspondences which you can feed into cvFindFundamentalMat. This finds the fundamental matrix which relates the two perspectives. Namely, for each point x in camera 1 and corresponding point x' in camera 2, x'Fx = 0. You can similarly find the epipoles, etc. This uses the 8 point algorithm which requires at least 8 point pairs of point correspondences.
You can get the correspondences either manually or with a robust feature extractor and matcher along the lines of MSER/Affine Harris + SIFT.

Sokoban solver, tips [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 9 years ago.
Improve this question
I have to do a Sokoban solver (http://en.wikipedia.org/wiki/Sokoban).
Have you ever done one? I am searching for tips, not for code. Like "you may use the IDA* alg" or "I used that heuristic and it was quite good" or "I use that tech no avoid deadlocks".
Basically I want to write on a paper the strategy before writing any code.
I have written my Master's thesis on Sokoban algorithms. I aimed to provide a good overview on the techniques used in Sokoban solvers. It does not provide definite answers, but might provide a good starting point for someone interested in writing a Sokoban solver.
http://weetu.net/Timo-Virkkala-Solving-Sokoban-Masters-Thesis.pdf
Terms
field - the level, whole playing area of the current game.
position - a phase, set-up in the field.
final position - a position in which no turn is possible - either the goal or a deadlock.
box - same as crate.
Theory
Just a little bit of logic - it seems obvious but we'll use it in the implementation part.
So - about every game of Sokoban, we can say that it is one of these:
solvable, unsolved - in the process of solving
solvable, solved - the goal
unsolvable, unsolved - if our implementation yields no results, and there are no more possible moves / combinations of moves
Now - a Sokoban game consists of turns that are:
moves - the character can move in an area defined by walls and/or boxes, this area is smaller or equal (if not counting the walls, and there are no boxes) to the whole playing area - however, moving the character around the field makes no difference except score, which is irrelevant for the actual solution - let's ignore it for now
pushes - pushing the boxes is much more important, and can potentially lead to our goal - solving the field - by pushing the boxes at their respective goals
A box can be:
in-goal - most likely this box does not need to be moved, and some rules can prohibit a box from moving when at a goal position (very unusual)
pushable - in 1 to 4 directions
unpushable, not at goal
blocked by 2 walls - the current position is unsolvable no matter what
other - we will get to this box later - for now a crate stands in our way
Process
This is the step-by-step process we will use in solving (definitions underneath):
populate possibleTurnsn with every directly accessible push (pushable or in-goal) in the current position, with player at the current place
take the first item in possibleTurnsn, remove it and execute it
see if the current position:
is final - goal - solved, do not do anything
is final - deadlock - this turn led to a deadlock, don't populate it anymore, go back to 2. step, n stays the same
is not final - increment n and populate possibleTurnsn with possible turns in this position
Definitions:
possibleTurnsx - a two dimensional array, or an array of arrays - the x defines the "depth" of the turns
n - in the beginning is zero, will be incremented in the execution of the algorithm above
Tips
Finally - the process above will leave you with a combination of turns that will leave to a solved position. Last thing to do is to use an algorithm like A* to determine the shortest route between these turns / pushes, to maximize the speed and score, minimize number of in-game turns.
You can create a brute force solver that tries to move your man in every possible direction. By using recursion (or a stack) you can track back your steps if a solution is not found.
A* probably won't do you any good, because you don't have to find your way through a maze, but also need to move the boxes. This means you may need to take a step back in the same direction you came from after moving a box. So for every step you need to evaluate all directions, including the one you came from. That is, unless you didn't move a box in the previous step.
[edit]
You could use A* to make it a little smarter; to find a way from your current position to any of the positions you can move a box from. That would probably make your solution more efficient, because you won't have to track all positions inbetween, but only the positions from the last box you pushed to the next box you'll push.

Resources