i was wondering if anyone of u here knows how to smooth a polygon in Maya? I've tried 2 methods which i found online. One of which is 'Vertice Averaging' and the other 'Smooth' which are both under the 'Mesh' option.
Vertice Averaging caused my polygons to have 'gaps' or 'holes' between the triangles, which i do not intend for that to happen.
While Smooth causes the polygon's face to have 4 vertex instead of the original 3, which i do not want as well, as i need a polygon with triangle faces.
http://img.photobucket.com/albums/v483/dragonlancer/PolygonAveragingampSmoothing.jpg
And to whoever told me that it is a bug, i tried, but doesnt work =[
You said you wanted to maintain your tris so you could switch the smooth option 'Add Divisions' from exponential to linear.
If you're getting gaps, its because the original mesh has verts which are not welded together. Try Edit Mesh > Merge with a small tolerance value before running average or smooth.
In general you'll get more pleasant results if you smooth a quadrangular mesh instead of a trimesh - when you subdivide quads the results are very similar to NURBS curves, whereas smoothed triangles always tend to look look like old-fashioned 1990's game graphics.
Related
I'd like to color faces on an triangular RGL mesh based on proximity to a vertex.
The thing is, it seems that a lot of the times that the vertices are associated with faces that are very far from the actual vertex location itself, which creates a problem when I want to color faces around one vertex; the faces end up being very far from where the barycenter actually is.
What I'm doing right now is this:
Compute the barycenter of all the faces in the mesh.
Use the FAR package to compute the closest n barycenters to the desired point. Keep those indices.
Based on the indices gathered, color those faces a certain color. The rest of the faces would be colored white.
colors=rep('white',num_faces)
colors[colored_faces]='red'
mesh$material=list(color=colors)
Then I would plot the mesh: plot3d(mesh)
The thing is, I'm getting very odd coloring right now, is there any established way to color faces that close to a certain coordinate/vertex?
This is what the mesh currently looks like, with the red as the 'colored' faces, and the blue as the points that I would like there to be a colored face near.
Mesh
Update: Seeing this, my question has now been modified to:
How can I find the closest face to a given point? It still isn't clear to me, since the face barycenters are sometimes misleading, and don't represent actual distance to a given vertex.
Update 2:
I've added example code and a file here: Files and code
Basically the code finds the nearest faces to a given vertex of the same 3d mesh with the nearest neighbor algorithm, and then we color those faces in our color vector (remembering to color the colors 4 times):
Except, when we run this algorithm, we only color one side of the shape: like so:
Odd
How can I make the coloring a bit more symmetric?
Update 3: This problem has been resolved! Please look to the unreleased version of rgl on Rforge for the newest version of rgl that allows for coloring of faces, vertices, and edges.
Update 4: Here is the new image by coloring the closest vertices (to show that the new rgl package works wonders):
Better Sink
Your code to compute the centroid is incorrect. You have
#Function for computing the barycenter/centroid of a face.
compute_face_centroid=function(vertices,face){
vertex=vertices[,face][-4,]
centroid=apply(X=vertex,MARGIN = 1,FUN = mean)
return(centroid)
}
This just removes the 4th row of the vertices array, which is the wrong way to convert homogeneous coordinates to Euclidean coordinates. You really need to divide the other rows by the 4th one. You can do this using the rgl function asEuclidean:
#Function for computing the barycenter/centroid of a face.
compute_face_centroid=function(vertices,face){
vertex <- asEuclidean(t(vertices[,face]))
apply(vertex, MARGIN = 2, FUN = mean)
}
There may also be other issues in your code, I haven't traced through everything yet.
BTW, the unreleased test version of rgl changes the way colours are handled in meshes, hopefully making that part of your code simpler. You can get it from R-forge.r-project.org if you want to try it. You can now specify colours by vertex or by face.
Edited to add:
Okay, I've taken a closer look now. I think your code was actually working. The compute_face_centroid should be corrected, but since your example always has value 1 for the final component, deleting it is okay.
The reason you got colouring different from what you expected is just that the triangles making up your mesh really vary in shape. If you plot your image as a wireframe you'll see this:
wire3d(file)
The centroids of those long thin triangles are quite far from your selected point.
So I am using Kinect with Unity.
With the Kinect, we detect a hand gesture and when it is active we draw a line on the screen that follows where ever the hand is going. Every update the location is stored as the newest (and last) point in a line. However the lines can often look very choppy.
Here is a general picture that shows what I want to achieve:
With the red being the original line, and the purple being the new smoothed line. If the user suddenly stops and turns direction, we think we want it to not exactly do that but instead have a rapid turn or a loop.
My current solution is using Cubic Bezier, and only using points that are X distance away from each other (with Y points being placed between the two points using Cubic Bezier). However there are two problems with this, amongst others:
1) It often doesn't preserve the curves to the distance outwards the user drew them, for example if the user suddenly stop a line and reverse the direction there is a pretty good chance the line won't extend to point where the user reversed the direction.
2) There is also a chance that the selected "good" point is actually a "bad" random jump point.
So I've thought about other solutions. One including limiting the max angle between points (with 0 degrees being a straight line). However if the point has an angle beyond the limit the math behind lowering the angle while still following the drawn line as best possible seems complicated. But maybe it's not. Either way I'm not sure what to do and looking for help.
Keep in mind this needs to be done in real time as the user is drawing the line.
You can try the Ramer-Douglas-Peucker algorithm to simplify your curve:
https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm
It's a simple algorithm, and parameterization is reasonably intuitive. You may use it as a preprocessing step or maybe after one or more other algorithms. In any case it's a good algorithm to have in your toolbox.
Using angles to reject "jump" points may be tricky, as you've seen. One option is to compare the total length of N line segments to the straight-line distance between the extreme end points of that chain of N line segments. You can threshold the ratio of (totalLength/straightLineLength) to identify line segments to be rejected. This would be a quick calculation, and it's easy to understand.
If you want to take line segment lengths and segment-to-segment angles into consideration, you could treat the line segments as vectors and compute the cross product. If you imagine the two vectors as defining a parallelogram, and if knowing the area of the parallegram would be a method to accept/reject a point, then the cross product is another simple and quick calculation.
https://www.math.ucdavis.edu/~daddel/linear_algebra_appl/Applications/Determinant/Determinant/node4.html
If you only have a few dozen points, you could randomly eliminate one point at a time, generate your spline fits, and then calculate the point-to-spline distances for all the original points. Given all those point-to-spline distances you can generate a metric (e.g. mean distance) that you'd like to minimize: the best fit would result from eliminating points (Pn, Pn+k, ...) resulting in a spline fit quality S. This technique wouldn't scale well with more points, but it might be worth a try if you break each chain of line segments into groups of maybe half a dozen segments each.
Although it's overkill for this problem, I'll mention that Euler curves can be good fits to "natural" curves. What's nice about Euler curves is that you can generate an Euler curve fit by two points in space and the tangents at those two points in space. The code gets hairy, but Euler curves (a.k.a. aesthetic curves, if I remember correctly) can generate better and/or more useful fits to natural curves than Bezier nth degree splines.
https://en.wikipedia.org/wiki/Euler_spiral
Let me explain my problem:
I have a black vector shape (let's say it's a series of joined, straight lines for now, but it'd be nice if I could also support quadratic curves).
I also have a rectangle of a predefined width and height. I'm going to place it on top of the black shape, and then take the union of the two.
My first issue is that I don't know how to quickly extract vector unions, but I think there is a well-defined formula I can figure out for myself.
My second, and more tricky issue is how to efficiently detect the position the rectangle needs to be in (i.e., what translation and rotation are needed by the matrices), in order to maximize the black, remaining after the union (see figure, below).
The red outlined shape below is ~33% black; the green is something like 85%; and there are positions for this shape & rectangle wherein either could have 100% coverage.
Obviously, I can brute-force this by trying every translation and rotation value for every point where at least part of the rectangle is touching the black shape, then keep track of the one with the most black coverage. The problem is, I can only try a finite number of positions (and may therefore miss the maximum). Apart from that, it feels very inefficient!
Can you think of a more efficient way of tackling this problem?
Something from my Uni days tells me that a Fourier transform might improve the efficiency here, but I can't figure out how I'd do that with a vector shape!
Three ideas that have promise of being faster and/or more precise than brute force search:
Suppose you have a 3d physics engine. Define a "cone-shaped" surface where the apex is at say (0,0,-1), the black polygon boundary on the z=0 plane with its centroid at the origin, and the cone surface is formed by connecting the apex with semi-infinite rays through the polygon boundary. Think of a party hat turned upside down and crumpled to the shape of the black polygon. Now constrain the rectangle to be parallel to the z=0 plane and initially so high above the cone (large z value) that it's easy to find a place where it's definitely "inside". Then let the rectangle fall downward under gravity, twisting about z and translating in x-y only as it touches the cone, staying inside all the way down until it settles and can't move any farther. The collision detection and force resolution of the physics engine takes care of the complexities. When it settles, it will be in a position of maximal coverage of the black polygon in a local sense. (If it settles with z<0, then coverage is 100%.) For the convex case it's probably a global maximum. To probabilistically improve the result for non-convex cases (like your example), you'd randomize the starting position, dropping the polygon many times, taking the best result. Note you don't really need a full blown physics engine (though they certainly exist in open source). It's enough to use collision resolution to tell you how to rotate and translate the rectangle in a pseudo-physical way as it twists and slides uniformly down the z axis as far as possible.
Different physics model. Suppose the black area is an attractive field generator in 2d following the usual inverse square rule like gravity and magnetism. Now let the rectangle drift in a damping medium responding to this field. It ought to settle with a maximal area overlapping the black area. There are problems with "nulls" like at the center of a donut, but I don't think these can ever be stable equillibria. Can they? The simulation could be easily done by modeling both shapes as particle swarms. Or since the rectangle is a simple shape and you are a physicist, you could come up with a closed form for the integral of attractive force between a point and the rectangle. This way only the black shape needs representation as particles. Come to think of it, if you can come up with a closed form for torque and linear attraction due to two triangles, then you can decompose both shapes with a (e.g. Delaunay) triangulation and get a precise answer. Unfortunately this discussion implies it can't be done analytically. So particle clouds may be the final solution. The good news is that modern processors, particularly GPUs, do very large particle computations with amazing speed. Edit: I implemented this quick and dirty. It works great for convex shapes, but concavities create stable points that aren't what you want. Using the example:
This problem is related to robot path planning. Looking at this literature may turn up some ideas In RPP you have obstacles and a robot and want to find a path the robot can travel while avoiding and/or sliding along them. If the robot is asymmetric and can rotate, then 2d planning is done in a 3d (toroidal) configuration space (C-space) where one dimension is rotation (so closes on itself). The idea is to "grow" the obstacles in C-space while shrinking the robot to a point. Growing the obstacles is achieved by computing Minkowski Differences.) If you decompose all polygons to convex shapes, then there is a simple "edge merge" algorithm for computing the MD.) When the C-space representation is complete, any 1d path that does not pierce the "grown" obstacles corresponds to continuous translation/rotation of the robot in world space that avoids the original obstacles. For your problem the white area is the obstacle and the rectangle is the robot. You're looking for any open point at all. This would correspond to 100% coverage. For the less than 100% case, the C-space would have to be a function on 3d that reflects how "bad" the intersection of the robot is with the obstacle rather than just a binary value. You're looking for the least bad point. C-space representation is an open research topic. An octree might work here.
Lots of details to think through in both cases, and they may not pan out at all, but at least these are frameworks to think more about the problem. The physics idea is a bit like using simulated spring systems to do graph layout, which has been very successful.
I don't believe it is possible to find the precise maximum for this problem, so you will need to make do with an approximation.
You could potentially render the vector image into a bitmap and use Haar features for this - they provide a very quick O(1) way of calculating the average colour of a rectangular region.
You'd still need to perform this multiple times for different rotations and positions, but it would bring it algorithmic complexity down from a naive O(n^5) to O(n^3) which may be acceptably fast. (with n here being the size of the different degrees of freedom you are scanning)
Have you thought to keep track of the remaining white space inside the blocks with something like if whitespace !== 0?
I have a general question about what method to use for smoothing a 3D (xyz) grid.
My program has large matrixes of 3D points obtained with a stereovision method. The shape of the result is always something like a semisphere, but it has a rugosity due to stereovision errors I want to eliminate.
The question is, how to do it? Rigth now I have half developed a method for soomthing, but I think there may be a better method.
My actual idea is to use Hermite method. The idea is to:
Take all XY and smooth in two directions ->XYnew and XnewY
Convert the Hermite lines into Bezier lines and find the cross point between XYnew and XnewY, having the new point. (Repeat with all points, normally 2000)
Use hermite XYZ smoothing having XYZnew.
Rigth now I have the hermite surface smoothing and hermite line smoothing inplemented in C++, but the middle part is not as easy as espected.
Anyway, my question is, is this a correct method or is there another one which may be better?
Of course the idea is to elliminate the error generated by the stereovision method, this is not a computer graphics problem, is more a data treatment problem
Appendix:
At first I thougth that with a Z smoothing would be suficient, but clearly it is not, there is also a lot of XY error. In the images below you can see the Z fitting working but still it is really rugous as it can be seen in the 2 image. (The colours are deformations and shoul be quite continous)
Unless you have better priors, it's hard to beat the classic Taubin's algorithm: http://mesh.brown.edu/taubin/pdfs/taubin-iccv95a.pdf
I have a 3D closed mesh car object having a surface made up
triangles. I want to calculate its volume, center of volume and inertia tensor.
Could you help me
Regards.
George
For volume...
For each triangular facet, lookup its corner points. Call 'em P,Q,R.
Compute this quantity (I call it "partial volume")
pv = PxQyRz + PyQzRx + PzQxRy - PxQzRy - PyQxRz - PzQyRx
Add these together for all facets and divide by 6.
Important! The P,Q,R for each facet must be arranged clockwise as seen from outside. (Or all counter-clockwise, as long as it's consistent for all facets.)
If the mesh has any quadrilaterals, just temporarily hallucinate a diagonal joining one pair of opposite corners. That makes it into two triangles.
Practical computationial improvement: Before doing math with P,Q and R, subtract the coordinates of some "center" point C. This can be the center of mass, a midpoint between the min/max x, y and z, or any convenient point inside or near the mesh. This helps minimize truncation errors for more accurate volumes.
From numerical point of view, what you are trying to achieve is quite simple and can be reduced to calculating few quadratures. Wikipedia will provide needed information about maths behind it.
If you are looking for out-of-the-box volume calculation, take a look at this entry.
As of inertia -- shape is not enough, as you also need distribution of mass.
Well, there isn't much information on the car being provided here - you should be able to break down the car into simpler shapes - the higher degree of approximation your require - the more simpler shapes you can break it into. (This could be difficult if the car is somehow dynamically generated and completely different every time ... but I don't see that situation making any sense).
This should help with finding the Inertial Tensor of various simpler shapes: http://www.gamedev.net/community/forums/topic.asp?topic_id=57001 , finding the volumes and the likes of things like spheres and cubes is pretty common knowledge so I won't bother linking that.
I think it was Archimedes who discovered that if you submerge the car in a volume of liquid, the displaced liquid will have the same volume as the car.
I'm not sure what this would help you in this case though. Having a liquid simulation running in the background and submerging the mesh into it sounds a bit over the top. Although, I think it does work, and therefore qualifies as a (bit useless nonetheless) answer. ;^)