How to get smoother values? - c#

I am working on a project and one of the parts is to generate a mountain. Someone passed me the source code and I've tried to modify it to fit my needs but the output is not exactly what it needs to be.
It is great to generate some flat values for an island maybe, but not so great at generating smooth height values for a mountain.
At first, it seems to look good because it generates a nice shape but you can see the abrupt changes from color to color. When I pass the texture to a 3D Terrain, this is what it looks like:
Anyways, the 3D Mountain should not look like this even though the base shape is fine. I am looking for something similar to this height values, it's much smoother:
After analyzing the source code for a while I reckon that the problem seems to be that the values are truncated. I think the problem is in the Noise() function above, especially with the Pow functions, but I'm not sure.
I would be very glad if someone can contribute towards fixing this. Thank you and have a Great Day!

The problem was caused by the Noise function because it returned an int, which truncated all the values as a result.

Related

Slicing a 3D model?

I want to slice a 3D model relative to an infinite plane(In WPF). I'm checking if edges intersect with the infinite plane. If true, I'll create a new point at the intersection position, so I'm getting a couple of points that I want to generate a cap on so that the model is closed after slicing. For example, if this is the cross section, the result would be as follows:
Note: The triangulation ain't important. I just need triangles.
I also need to detect the holes as follows(holes are marked in red):
If it is impossible to do it the way I think(It seems to be so), the how should I do it? How do developers cap an object after being sliced?
There is also too much confusion. For example, The first picture's result may be:
What am I missing??
EDIT:
After some research, I knew one thing that I am missing:
The input is now robust, and I need the exact same output. How do I accomplish that??
In the past, I have done this kind of thing using a BSP.
Sorry to be so vague, but its not a a trivial problem!
Basically you convert your triangle mesh into the BSP representation, add your clipping plane to the BSP, and then convert it back into triangles.
As code11 said already you have too few data to solve this, the points are not enough.
Instead of clipping edges to produce new points you should clip entire triangles, which would give you new edges. This way, instead of a bunch of points you'd have a bunch of connected edges.
In your example with holes, with this single modification you'd get a 3 polygons - which is almost what you need. Then you will need to compute only the correct triangulation.
Look for CSG term or Constructive Solid Geometry.
EDIT:
If the generic CSG is too slow for you and you have clipped edges already then I'd suggest to try an 'Ear Clipping' algorithm.
Here's some description with support for holes:
https://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf
You may try also a 'Sweep Line' approach:
http://sites-final.uclouvain.be/mema/Poly2Tri/
And similar question on SO, with many ideas:
Polygon Triangulation with Holes
I hope it helps.
Building off of what zwcloud said, your point representation is ambiguous. You simply don't have enough points to determine where any concavities/notches actually are.
However, if you can solve that by obtaining additional points (you need midpoints of segments I think), you just need to throw the points into a shrinkwrap algorithm. Then at least you will have a cap.
The holes are a bit more tricky. Perhaps you can get away with just looking at the excluded points from the output of the shrinkwrap calculation and trying to find additional shapes in that, heuristically favoring points located near the centroid of your newly created polygon.
Additional thought: If you can limit yourself to convex polygons with only one similarly convex hole, the problem will be much easier to solve.

Is it possible to create isosurfaces using Oxyplot?

I'm using Oxyplot HeatMapSeries for representing some graphical data.
For a new application I need to represent the data with isosurfaces, something looking like this:
Some ideas around this:
I know the ContourSeries can do the isolines, but I can't find any option that allows me to fill the gaps between lines. Does this option exists?
I know the HeatMapSeries can be shown under the contourSeries so I can get a similar result but it does not fit our needs. .
Another option wolud be limiting the HeatMapSeries colours and eliminate the interpolation. Is this possible?
If anyone has another approach to the solution I will hear it!
Thanks in advance!
I'm evaluating whether Oxyplot will meet my needs and this question interests me... from looking at the ContourSeries source code, it appears to be only for finding and rendering the contour lines, but not filling the area between the lines. Looking at AreaSeries, I don't think you could just feed it contours because it is expecting two sets of points which when the ends are connected create a simple closed polygon. The best guess I have is "rasterizing" your data so that you round each data point to the nearest contour level, then plot the heatmap of that rasterized data under the contour. The ContourSeries appears to calculate a level step that does 20 levels across the data by default.
My shortcut for doing the rasterizing based on a step value is to divide the data by the level step you want, then truncate the number with Math.Floor.
Looking at HeatMapSeries, it looks like you can possibly try to turn interpolation off, use a HeatMapRenderMethod.Rectangles render method, or supply a LinearColorAxis with fewer steps and let the rendering do the rasterization perhaps? The Palettes available for a LinearColorAxis can be seen in the OxyPalettes source: BlueWhiteRed31, Hot64, Hue64, BlackWhiteRed, BlueWhiteRed, Cool, Gray, Hot, Hue, HueDistinct, Jet, and Rainbow.
I'm not currently in a position to run OxyPlot to test things, but I figured I would share what I could glean from the source code and limited documentation.

Smoothing function for PRM output

I've implemented a Probabilistic roadmap method function, which works and executes correctly. The only problem is that the output of the prm is not smooth for example, if a hand needs to rotate from 30 to 100 degrees, the steps might be 30,55,42,66,99,100, i wat to be able to smoothen the transition betwen the 30 and 100 degree. I know that the problem is related tp smoothing of a signal yet i dont know what type of smoothing might be able to do the job. No sophisticated method is needed. My implementation is in c#, if possible i wish to let such job be done by a library. Is there any such library? which i can give it an array of integers and likewise produce an array of smoothed values.
I think what you need is a simple curve fitting algorithm. A quick google search will give you lots of example code. And if you want to have a strictly increasing curve, you need to sort the values before you do the curve fitting.
If you are just interested in reaching the target, you can drop the values in between and do a linear interpolation from start to end or something similar.

Random rectangles placement with minimal overlap and good dispersion

I have a Big Rectangle (axis-oriented) containing a lot of Small Rectangles (with the same orientation of the parent and with a fixed size of 82x176 pixels).
Now I have a Small Rectangle which is outside and I have to put it inside the Big Rectangle such that it is: - Randomly placed; - Not overlapping other Small Rectangles unless necessary due to lack of space (and, in this case, with the minimum overlap).
The algorithm, which will be used multiple times during my code execution, also needs to include a good distibution so that Small Rectangles will be nicely dispersed around the center of the Big Rectangle and not all clumped into one corner.
Googling, I found several algorithms concerning rectangles packing, largest empty rectangle, random distributions... but nothing really addresses my requirements nor shows a good code implementation.
Does anyone have any good ideas (code or pseudo-code is better, if possible, as normally my brain crashes when I see maths formulas)?
Your question is far too vague and far too difficult for anyone to post a solution; this isn't a solution. Rather, it is a lesson in how to attack this sort of problem. Start by reading this:
http://en.wikipedia.org/wiki/How_to_Solve_It
And maybe pick up a copy of the book while you're at it.
As Polya wisely says
If you can't solve a problem, then there is an easier problem you can solve: find it.
Here is a far easier version of your problem:
I have a straight line. On this line I have a collection of line segments. The start and end points of each line segment in the collection are both between 0 and some parameter n, inclusive. Some of the line segments might overlap each other.
Given the length of a new line segment, less than n, randomly place the new line segment such that its start and end points are both between 0 and n, and it does not "overlap" any line segment in the collection. If doing so is not possible then compute the start and end coordinates of the new line segment that minimize the amount it overlaps.
Can you write me a solution to that problem in C#? Believe me, if you can't solve the easier problem, then you'll never solve the rectangle version.
If you can't solve that problem then again make it easier until you can solve it. What if n is never bigger than 200? What if the collection of existing segments only has zero, one or two elements? What if the length of the new segment is always three? What if you get rid of the requirement of randomness? What if you get rid of the minimization problem? And so on. Keep on making the problem simpler until you can solve it. Once you have a solution to the simpler problem, try to adapt it into a solution to the larger problem. By practicing solving simpler problems you'll gain insight into solving the harder problem.
Depending on what you need it for, something may already exist. For example, if you are developing a web app, then look at jQuery Masonry: http://masonry.desandro.com/demos/basic-multi-column.html.
If that code serves your needs, but you're not doing a web app, then maybe you can inspect the source code to get what you need.
Hope this helps.

Polygon Triangulation c#

I need to calculate triangles of a polygon. Polygon can contain holes. And Req an efficient way.
So I think I need Constrained Delaunay Triangulation.
I must do that in c#, only need calculation not drawing or something.
poly2tri seems good but idk its not working for me :S
Anyway I need help. How can I calculate that triangles?
(If your best offer is poly2tri, i can explain my problem on it)
Delaunay was not designed for this, use Ear Clipping instead.
I suppose my simple solution on github:gist (but it's rather old and probably not optimal).

Categories