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 9 years ago.
Improve this question
I am looking for the best (efficient algorithm for calculating the area of 2D polygon (especially for triangle given three points). I search on the web and I found the following link, but still I'm not sure that they are efficient in terms of memory cost or not (since my mesh is huge).
I am wondering if there is any tricks in c++ (I'm newbie in c++) which could be applied on them:
here are the links:
(stackoverflow)
How to determine if a point is in a 2D triangle?
http://www.softwareandfinance.com/Visual_CPP/Triangle_Area_Perimeter.html
It's worth to mention that the final target is to find out if a point is inside (NOT on the border) the polygon.
thanks for any help.
Joachim Pileborg suggested in comments that the area isn't needed, but that misses the point: there's an efficient algorithm which does require an intermediate value, that just so happens to be 2*Area.
However, in this case the problem is actually the input domain: a mesh of triangles. That means almost every vertex borders on two triangles. It's not like "point P lies on the left of edge E, so it's not in triangle T". There are a large set of triangles Ti, some of which lie on the left, some of which lie on the right, and one directly on either side of a given edge.
Given that complexity, you should pre-process the mesh. Partition it in some manageable chunks, e.g. 16x16, and note for each triangle in which chunks it lies. Any point P lies in exactly one chunk, so you need to test perhaps 1% of triangles (a single triangle may lie in multiple chunks, but the average is low).
(You rarely if ever need to do just a single point-to-mesh match, so preprocessing is justified. And pre-calculate the area while you're at it.)
Related
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 5 years ago.
Improve this question
I am trying to build an .obj file importer that renders said model to the screen.
At present I have imported the vertices and they are stored in a
std::vector<vec3> vertices;
My renderer class quite large so I'll link github instead of posting it here.
https://github.com/rob-DEV/OpenGL-Model-Viewer/blob/master/OpenGL-Model-Viewer/src/graphics/renderer/renderer.cpp
So at line 41 in renderer.cpp. I submit these vertexs to the renderer. Originally I just drew triangles, but I would like to take advantage of GL_ELEMENTS
My question is how (if possible) can I calculate these indices from a list of vertices? I have tried to find duplicates and do so when the model is loaded but i don't know how to map them.
Using mapped buffers (by glMapBuffer) does not work in your case.
For example, if you want to know if a vertex has been already mapped (a duplicate) you should read all of currently mapped vertices, which is slow.
If you want to use a sorted array (so fast binary search can be used) then many portions of that mapped buffer must be re-written during the sorting/storing process. Slow too.
A better option is to build your sorted vertices array on your own, on normal RAM. Be adviced of searching issues due to numerical matters when comparing two floats.
On a second pass each index is just the position of the current vertex. Same advice for numerical issues.
Data can be sent to the GPU by two simple glBufferSubData, one for vertices (and their colors and normals and etc) and another one for the indices.
If the object moves (and you prefer to update coordinates instead of use a translation matrix) then it's right to use a mapped buffer with new coordinates (as you currently do). Indices don't change, so they don't need to be updated.
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
What is the and optimal method, if not the best, for doing it?
Assume that I have an object that has 2 wheels. The only information I have available is how far the wheels have rolled at any time.
Basically, I want to know how to calculate the coordinates (x2,y2)
I put this question on the programming section because I want to solve this with an algorithm or plainly put, by programming (in c++).
Given that you have how far the wheels have rolled at any time, it means that you have two functions of time w1(t) w2(t) giving the distance covered by the wheels.
from that you may by derivation get the scalar velocity of each wheel as v1(t) and v2(t).
As your object position is the mean between the position of those two wheels, the velocity of your object is the mean of those two velocities, but the difference of the velocities gives the speed of rotation of the object. So you have essentially a velocity described as a scalar velocity plus a rotation speed.
By integrating that vectorial quantity you may arrive to the current position of your object.
Details must be thought carefully, but the idea I think is that.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I have a set of points, each with an x and y coordinates. I would like to find the 4 of these points that are closest to together (if plotted all the points would be at different locations, but 4 of these points are always closer to each other, and I want to be able to identify which of the points these four are programmatically ). How do I go about doing this? I'm told it has to do with k-means or nearest-neighbors, but from my search results so far, I don't see how I could get it to work for my case since I'm finding the proximity of the points relative to each other and not to some fixed point. Any suggestions as to what topic/algorithm to look into, or code snippets will be much appreciated.
I thought an image of the exact problem might help. So these 8 points are contained in a vector, and I'd like to be able to identify which four are the ones clustered on the right.
Thanks in advance.
A brute force method would be to select every possible selection of four points (every permutation) and calculate e.g.:
1) the area enclosed by the points,
2) the perimeter of the convex hull of the points,
3) ...
and you'll find your four points by getting the minimum of the values calculated by 1), 2) or 3).
Build a Delaunay Triangulation graph in nlog(n) complexity, there will be less than 2n edges to go over in order to find the four shortest ones.
you could try poly2tri.
You'd want to go over the edges like this: choose an edge, go three times to the shortest connected edge, and sum the edge lengths. save the vertices and the length sum of the minimal edge sum encountered thus far, and exhaust all the possible shortest neighbouring length combinations.
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 been looking on the internets for a while to find a solution to my problem. First some back ground. I'm writing a program that calculates catapult trajectory. The user must first type in a distance. Then I loop through the combinations of angle degrees and velocity to find which combination will give a distance that will come the closest to the users input. I don't quite know how to do the variable comparison to find which combination of degrees and velocity produces a distance closest to a users input of distance. I'm just trying to keep it simple and easy as possible. Also, I'm not using any kind of array to store the values. I want it done on the fly inside my for loops if possible. Any suggestions?
Well, the answer to this depends on the complexity of your trajectory formula. I'm guessing that you're not taking fluid dynamics or gravity differentials into consideration. In fact, what I imagine is that you're using a basic parabolic equation...
That equation can be solved directly by rearranging. But the thing is, you're solving for two variables that are actually co-dependent. There are infinite solutions if you allow both angle and velocity to vary, so you need to restrict the 'best' answer by some criteria (for example, desired angle or desired velocity).
If you have more variables, like lift, drag, spin, incident shape, non-constant gravity, air pressure and humidity, then you will need to employ a minimization algorithm which is non-trivial. One of the most basic, but a little unstable, is the Nelder-Mead algorithm.
If this has not been helpful enough, you should provide more information about your problem, and show some code.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
I have a system of mono-disperse spheres inside a cubic box. I am studying the volume distribution inside the sample, after tessellating it with either Voronoi and Delaunay tessellations. I am interested on some properties which should not depend on the tessellation.
Currently, I am comparing with the values obtained from Voronoi and Delaunay. I would like to know if you are familiar with another space partition approach (It is important that the final sum of the individual cells add up to the total volume, and the cells should be disjoint). Furthermore, in case you know another kind of tessellation, do you also know a library which already implements it, preferable in C/C++ or python?
Some variations, like Laguerre partitions, coincide with my current Voronoi approach since the spheres are mono-disperse. Another candidate will be the Centroidal Voronoi tessellation, although I have not found yet a library to do that (although it could lead to evenly spaced cells which does not reflect the disorder inside the system, which is not desirable).
Thanks in advance for your kind help.