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 4 years ago.
Improve this question
I am looking for a memory-efficient yet convenient data structure for a 3D mesh or face-set consisting of triangles.
Currently I am using this 'classical' structure:
a list of points, and a list of triangles.
Each point has a X, Y, and Z value.
Each triangle has three indices i0, i1, i2, which refer to a point in the point list.
This is the most compact layout I can think of. It is perfect if all I want to do is draw the mesh, and never modify or filter it.
However it does make most operations that modify the mesh or generate a new partial mesh very cumbersome, for example:
Removing triangles is very inefficient.
generating a new mesh with only triangles that have less than 3 neighbors
Finding and removing all triangles that have one or all point within a given bounding box
finding all edges with a certain angle
removing all edges shorter than a certain length
Basically anything that requires modifying the mesh, or iterating over the edges or finding neighboring faces/edges, requires generating and discarding several temporary dictionaries and hash sets. There is no easy way to iterate over the points or edges of an individual face, or the edges/faces around an individual point. removing a point means removing it from each triangle, then changing the index values for all other points in all triangles, etc.
Is there a canonical data structure that does not have these drawbacks, yet is memory-efficient?
I am not looking for an entire library, just a structure I can implement myself (although it may be interesting to know how particular libraries have solved this problem)
There's a couple of open source data structure that may fit your needs:
CGAL https://www.cgal.org/
OpenMesh http://openmesh.org/
Surface Mesh http://opensource.cit-ec.de/projects/surface_mesh
I've oredered them from the harder to the easier to use. They are all half edge data structures
Take a look at this paper from Bielefeld university (developers of the Surface mesh), I think that it's a good starting point for you!
Related
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
How can I get my NPC AI to locate all objects within X distance, identify each object and then be able to Target a specific object?
An example being:
The AI is in an area, and there are 4 objects within it's range. Those objects are 2 tree, a rock, and a pig. The AI needs wood, and then will need some rock. How do I get the AI to be able to identify the 2 tree, the rock, and the pig, and then go to a tree, and then go to the rock?
To search for certain type objects:
var foundObjects = FindObjectsOfType<TextMesh>();
https://docs.unity3d.com/ScriptReference/Object.FindObjectsOfType.html
To locate them (note that foundObjects is object[], you need to loop over them):
foundObject.transform.position;
Needs can be stored in priority queue. It is basically self ordering data collection, if you solve the highest priority task of ex: finding 2 wood, it will get you the next highest priority task to do.
This question is broad, There are so many aspects to going about this. I suggest attempting one aspect / researching it. Once you come to a stump in code that you cant understand, come ask. If I had to suggest a starting point, I would look up how to code the distance from one object to another. Then look up how to do that for multiple objects in a scene. Then look up how to identify those, whether it be by Tag or GameObject, etc..
Start from there, I wish you the best of luck on your journey!
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 4 years ago.
Improve this question
I have the following Problem:
I have a list Vector3 positions of an object I tracked in Unity (e.g. an animated sphere flying some track). I am adding the position of it every frame to the List. Which leads to a sum of e.g. 500 values. When it's animation stopped i want to "clean" the recorded track and only keep the most distinct values (in the right order). But the List.Count has to be EXACTLY 100. So it has to check for "equal" values with a threshold.
What i've done so far: I am recording the position of "trackableObject" as Vector3 in every frame and cleaning it directly (only keep values that are further away than 'cleaningDiffTolerance' and/or have a greater angle difference then 'cleaningAngleMaxDiff'). This way i am getting only values for significant changes in direction/distance and get more points i curves/corners.
What i want: Do the cleaning not every frame but do it after i stopped recording. Then I want to only keep the most distinct values in correct order and exactly 100 values.
It depends how precise your result needs to be (and how you define 'precise').
The first question would be:
Must the 100 values be exact position values from the first list, or is it ok if it is near.
Position values won't change much every frame. An easy way tou solve the problem would be to average every step:
Compute how many values must be grouped together: n = totalValues/100
Take the first n values and store the average in your final list
Do the same for the next n values, and so on
Alternatively, if you need to have exact values, replace step 2 by "take first value of the groupe" for example.
This approche will be precise enough if the move is smooth.
The problem with this is that if you have a sudden position change (like an angle instead of a smooth turn), you will likely not get the exact position at which the angle occure. The only solution to identify these is to do some more advance analysis. You can search on google for "High Pass Filter" for instance.
I would recommend trying the simple approach first and see if it is fine for your needs
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
Let's say I have few points : -5,-4,-3,-2,-1,0,1,2,3,4,5
I'm at point 0, I need to create a line that goes all through the points of 1,2,3,4,5,-1,-2... etc.
The line would start at 0 and end at whatever point that ends as the shortest.
The answer for this example would be that it'd go like this 0->1->2->3->4->5->-1->-2->-3->-4->-5 or that it'd go first to -1 and go all through the minus to the plus, same result (5*4=20 length).
If for example we'd go 0->1->-1->2->-2... it'd end as the longest line that goes straight from point to point (1+2+3+4+5+6+7+8+9+10=10*11/2=55 length)
The question is how to write this in code?
The points might also consist of 2 or 3 dimensional points, where the start would be (0,0,0,0) or whatever, eventually the line can go through all of these points, but which way will achieve the shortest line?
How to make it as a code, as we see it in the eye?
I think this is basically the Travelling Salesman problem. You've got N destinations, and each pair of destinations has a concrete length between them, and you're trying to find out the shortest travel time to visit all destinations.
You've got two different directions to pursue this, that I can see. First, is to read up on the Travelling Salesman problem and the various algorithms that have been proposed for it (it's a very famous algorithm problem) and then try to implement one in C# - though just to warn you, you should be very proficient in math, because it's not an easy problem. Or, alternatively, you can look for someone else's existing implementation for it and just use it without understanding the theoretical underpinnings.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
This question is regarding WPF.
I have two balls, one static and the other is moving towards the static ball. On collision the balls would move in the direction that would be decided by the collision that at which angle they would collide and move accordingly.
My question is basically for suggestions for what is the easiest and the most effective way of colliding the objects in WPF and after collision giving them a path to move accordingly. Apart from deceleration etc, what should be the best strategy that should be applied to DETECT collision and GIVE NEW PATHS TO THE BALLS AFTER COLLISION.
Simply figure out the distance of the centers of the 2 balls.
if (distance(ball1.Center, ball2.Center) <= ball1.Radius + ball2.Radius)
{
// collision
}
For the distance use this:
double x = ball1.Center.X - ball2.Center.X;
double y = ball1.Center.Y - ball2.Center.Y;
double distance = Math.sqrt(x*x + y*y); // pythagoras
For calculating the new directions you'll need some more math. Have a look for a geometrics library like it is delivered with XNA. Try googeling your question again and use XNA in the search instead of WPF - this will solve your problem, i guess.
I would calculate the distance (pythagoras) between them, if the distance is smaller than the two radius added, a collision occurs.
Check here for the angle between the points:
Math Calculation to retrieve angle between two points?
You could check this one:
Ball to Ball Collision - Detection and Handling
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'd like to be able to generate a bell curve to use for probability in procedural generation in games.
For, example if I want to generate a forest, I could give it a radius and intensity and make a bell curve of the right shape to give me the probability of whether a tree should be placed or not. I should end up with a lot of trees in the centre and they would become less frequent as you approach the radius distance out from the centre.
I've done something similar before using a sine wave. But I have no idea how to make a bell curve. These equations are greek to me. I have forgotten how to read them, but it would be greek to the computer anyway.
Could someone write down the equation for bell curve in C# (or python would be my 2nd choice) and maybe explain it a bit?
Sure.
p(x) = exp(-(x-mu)^2/(2*sigma^2))/sqrt(2*pi*sigma^2)
The bell curve is also called the gaussian probability distribution. It is basically taking e to the power of a negative square of the x value. The rest is to make sure that it is centered at mu and scaled to the specifics of the particular problem you are modeling, and to make sure that the integral over all values of x sums to 1.
To generate random samples from this distribution in Python, you can do something like the following:
import random
sample = random.gauss(mu, sigma)
# where mu is the center of the bell curve, and sigma is proportional to its "width"
If you want to have a two-dimensional bell curve, it's nice to know that you can find X and Y values separately like in the above, and the 2D plot will be a 2D bell curve, where the density is highest at the center (mu_x, mu_y).