How to find orientation of a bezier curve? - geometry

How to find orientation (cw or ccw) of a closed curve that's formed by Bezier cubic segments?

It's the same as the orientation of the control polygon. See How to determine if a list of polygon points are in clockwise order? and http://www.cgafaq.info/wiki/Simple%5FPolygon%5FOrientation

Related

Closest point on a B-Spline Curve?

This thread asks how to get the closest point on a Bezier curve given an arbitrary point on the same plane: Closest point on a cubic Bezier curve?
How can I accomplish the same thing but for a B-SPline curve?

Using bezier curves to draw variable width paths

Given two points and a control point, one can easily draw a bezier path between the two points. What I would like to do use a bezier curve to draw a path that with changing width, by a assigning a "weight" to a the points of the curve which will determine its width. For example, if I give weight=0 to the first point of the curve and weight = 1 to the second point of the curve then something like the following path should be generated (the curve in the picture is cubic, but I am working with quadratic bezier curves):
In order to do this I would need to find the control points of the "edge" curves that determine the shape and then fill the shape that is found between the two new curves. However, I am quite unsure on how this can be done. One thing I thought about was to determine the starting and ending points of the new curves by simple drawing perpendicular segments to the line connecting the original control point and the original end points, but this still doesn't solve the problem of finding the new control points for the new curves.
I would use cubics instead of quadratics.
Yes you offset the control points perpendicularly by your weight but not the control points of BEZIER but control points of interpolation cubic (or catmull-rom) and then just convert that into Bezier control points. See related QAs:
How can i produce multi point linear interpolation?
How to create bezier curves for an arc with different start and end tangent slopes
draw outline for some connected lines
However much easier would be to directly render curve using Shaders and (perpendicular) distance. See:
Draw Quadratic Curve on GPU
That way you would not need to offset anything just interpolate the width of your curve ...
Maybe this could help, also there is an example on variable offseting
https://microbians.com/mathcode

Fast way to check if a rectangle is inside a triangle (2D)

Given vertices of rectangle and triangle, I can't find or figure out an algorithm that would check if a rectangle (2D, x-y axis aligned, not rotated) is inside a triangle (2D).
The only way I see it is to check if all rectangle points are inside the triangle, but I need the algorithm to be as fast as possible, so maybe there is a faster way to do this.
As both a rectangle and a triangle are convex polygons, it suffices to check that the four corners of the rectangle lie inside the triangle. This can be done by plugging the coordinates of the corners into the implicit equations of the sides and checking the signs.
Maybe using this answer: https://stackoverflow.com/a/21510010/1196549

How to apply ear clipping algorithm on a closed polygon, like a sphere?

I've been working on a project that needs to triangulate a sphere. I've known ear-clipping algorithm and know how to apply it in a non-closed polygon, like a plane.
But how to triangulate a closed polygon, like a sphere?
I'm assuming from your question that you want to panel a spherical surface with 3D patches. I would start by sketching a 2D equilateral triangle. Get some practice segmenting it into 4 half-size equilaterals, then each of those into 4 more, etc.
In 3D, you can do the same recursive triangulation on the 4 faces of a regular tetrahedron. Except, if each vertex is normalized to unit length, then you inflate your triangulated polyhedron into a sphere of triangular patches. You can use these patches to render a solid surface rendering (you'll want to learn how a simulated light source and shading works( e.g. Lambertian, Goraud, Phong ). Or, you can draw the edges of the patches as line segments to create a wireframe mesh.

Calculate size of a circle from arcs?

How can I calculate the size of a circle from a set of arcs?
Specifically, I have this SVG path definition which draws a circle, I'm looking to work out its size.
<path clip-path="url(#SVGID_2_)" fill="#99C44C" d="M334.293,56.846c0-4.782,3.88-8.659,8.665-8.659c4.78,0,8.66,3.877,8.66,8.659
c0,4.783-3.88,8.661-8.66,8.661C338.173,65.507,334.293,61.629,334.293,56.846"/>
For your information, the circle is drawn in the 'd' attribute. M334.293,56.846 moves to this x,y position, then the c commands are curves.
Curves:
Draws a cubic Bézier curve from the current point to (x,y) using (x1,y1) as the control point at the beginning of the curve and (x2,y2) as the control point at the end of the curve. C (uppercase) indicates that absolute coordinates will follow; c (lowercase) indicates that relative coordinates will follow.
relative curves
c0-4.782,3.88-8.659,8.665-8.659
c4.78,0,8.66,3.877,8.66,8.659
c0,4.783-3.88,8.661-8.66,8.661
absolute curve
C338.173,65.507,334.293,61.629,334.293,56.846
At this juncture you have two possibilites:
You can treat the bezier curve as a circle (which is, as commented, wrong; it's just really circle-looking). To calculate the area, determine the radius and use π * r^2 as usual.
If you want to calculate generally the area enclosed by a path element; that requires some moderate calculus, and is not for the faint of heart.

Resources