How to draw bounded b-spline surface in OpenGL? - bspline

I want to draw a bounded b-spline surface with 26 b-spline boundary curves.
I can draw b-spline surface (without any boundary) in OpenGL, but it is too difficult for me to draw surface and fit the boundary curves.
Any suggestions or ideas are appreciated.
https://drive.google.com/file/d/0ByjklWbi44oBZDhocGdNLWNvUWM/view?usp=sharing
PS: The Files is a sample in .stp format

B-spline surfaces are naturally bounded. So when you say B-spline surface without any boundary, I think you are talking about untrimmed B-spline surfaces and what you want to do is to be able to draw trimmed B-spline surfaces.
Drawing a surface typically involves tessellation, which turns a continuous surface into a triangle mesh consist of many small triangles. Therefore you will need to do the following:
Find the surface parameter curve (SP curve) of the boundary curves. The SP curve is a 2D curve defined on the parametric domain of the B-spline surface.
Tessellate the 2D region on the parametric domain enclosed by all SP-curves.
Map the 2D tessellation on parametric domain back to 3D space to find the 3D triangle mesh.
Step 1 and step 2 are both non-trivial. So, indeed this will be a large task if you don't have any 3D library at your disposal and have to implement everything by yourself.

Related

What is the Pseudo-Hillbert curve equivalent for hexogonal and triangular tesselations?

Triangles, squares and hexagons can all be used to fill a surface (tessellation).
For now let's assume the surface has a limited number of tiles (triangles, squares or hexagons)
The goal is to define a line that touches each tile so that points that are close to each other or the line (1D) are also close to each other on the surface (2D).
The solution for a square based tesselation you have the (Pseudo)-Hillbert curve. Below is an example of a second order pseado-hillbert curve.
Explained in this fantastic video
I was wondering what the equivalent (if any) of the pseudo-hillbert curve for tesselations based on triangles or hexagons are. I am looking for a full tesselation so no holes as in a Sierpinsky Triangle.
I found this great resource
And for triangles using a Peano curve.

Triangle pattern GLSL shader

Is there any simple algorithm like Voronoi diagram to divide any rectangular plane to triangles, eventually, using # of pre-defined points.
To be honest, I have to write a very simple fragment shader like this.
Theoretically, this Voronoii shader could be 'upgraded' by Delaunay triangulation
but wanna find the more elegant solution.
The first thing that comes to my mind is to create n random points (with specific seed) to fill a cylinder volume. The triangle points will be intersection of lines between those points and plane going through the axis of cylinder. The animation would be simply done by rotating the plane ...
I see it something like this:
So the neighboring points should be interconnected with each other. Forming tetrahedrons that fills the volume of the cylinder. So create uniform tetrahedron grid and add random noise to the points position (with specific seed).
This whole task is very similar to rendering cross section of 4D mesh see:
4D rendering techniques
As the 4D simplex is also tetrahedron. The only diference is you are in 3D and cutting by 3D plane.
You can reverse-engineer this example shadertoy.com/view/MdfBzl
like I did. Thanks to mattz.

Bezier curve fitting with known end points

I want to fit a bezier curve with known end points (p0 and p3) to noisy 2d data. This seems like an easier problem than traditional 4-point bezier curve fitting but still too hard for me to figure out.
Can someone point me to existing code or an algorithm to find the best values for the control points p1 and p2?
edit: The points that I'm trying to fit with a bezier curve comes from curves drawn with a mouse (imagine drawing something with a brush in Paint, there could be hundreds of recorded points in one long stroke). The anchor points p0 and p3 are created in advance but the control points p1 and p2 should be calculated so that the bezier fits the shape of the curve sketched out with the mouse.
I stumbled on a paper called "Approximation of data using cubic Bezier curve least square fitting" by "M.Khan" which describes an algorithm to calculate the exact thing I'm looking for.
Implementation in javascript was easy. It works quite good and is fast but the resulting bezier curves are not perfect. Could be a bug in my code but I suspect that better curves could be obtained by iteratively adjusting the matching points on the bezier curve to better fit the data .
edit: It turns out you can use newton-raphson to optimize each individual t-value for the bezier curve. After doing that the curve fits great, atleast for curves with only few points that don't self intersect but I have to do some more testing.

Find 2D plane in the center of 3D object

I'm building a segmentation algorithm. I'm segmenting pieces of paper in a book that have been slightly crumpled. Imagine taking a piece of paper, crumpling it into a ball, and then trying to straighten it back out.
The piece of paper is an actually 3D object (has depth -- small but still existent), but I want to segment a 2D plane running through the geometric center of the 3D object. Is this a center of mass problem?
I have a 3D matrix of binary values -- 1 being on the piece of paper, and 0 not on the piece of paper.
What kind of algorithm can I run to find the 2D plane?
You may want a 3D least-squares plane fit. This will minimize the separation between your plane and the voxel points. See here for math and code: http://www.ilikebigbits.com/blog/2015/3/2/plane-from-points

Filling the area inside of a irregular shaped polygon in opengl es

I have a set of points that outlines my polygon. The polygon can have many different shapes including convex shapes (imagine the shape of a crescent moon). I thought I could fill the inside of these shapes by using a triangle fan that started at the first point on the perimeter, but this fails badly on certain shapes.
How do people get this done? I wish there was a glPaintBucket function.
I believe you need to use the (intrinsically filled) triangle primitive after breaking up your polygon into triangles (start here to learn about polygon triangulation).

Resources