I need to use a cubic B-spline curve but cannot find code for it anywhere. The only curves available in Java API are QuadCurve2D, Path2D and CubicCurve2D. I think they all are Bezier, but I'm not sure about it.
If you know where can I find code for cubic B-spline preferably that extends Java Shape class and supports contains(Point p) for onMouseOver please help.
CubicCurve2D is a cubic B-spline.
However, this may or may not be what you need as there are other cubic B-splines.
That is, all CubicCurve2Ds are cubic B-splines. Not all cubic B-splines are CubicCurve2Ds.
Apache has a class to represent spline curves:
http://jmeter.apache.org/api/org/apache/jmeter/visualizers/Spline3.html
However, it doesn't extend Shape or support what you want. The class works by interpolating the curve between nodes with a cubic curve. For contains(Point P) You might be able to use the getPlots() method, compare its results to the x and y values of P.
Related
I have a curve (say JTS edge):
How to find all curve direction change points that surpasses given angle using JTS (Java) or NTS (C#):
I did some research and made some tests on JTS, and the best way I found is:
Create polygons and use the function union
Then iterate over the Coordinates, and create a sub-array on each "hard angle" (negative scalar product) and when the sum of angle reaches 180 (don't take the last angle to avoid non-function issues)
Then I change the base to an orthonormal base with x(firstElemOfSubArray, lastElemOfSubArray) by computing the base-changing matrix, and I then recompute the sub-array in a new coordinate system
I then create a function using org.apache.commons.math3.analysis.interpolation.SplineInterpolator to interpolate the function of the course, and then I get the derivative and search the extrema (don't take elements with an ordinate that is too low). With its absysse you can find which point is an inflexion point
So the point you search for are first elements of each sub array, and its inflections points (if there are any)
Java Topology Suite has Geometry class, which has getNumPoints() method. According to documentation, it counts all vertices in all constituent geometries.
How to enumerate all these points? They can be obtained by getCoordinates() method, but this looks not optimal, since (1) is not iterative and (2) requires to convert each coordinate tuple into Point by GeomertFactory.
As you probably have some proper geometry type like LineString or Polygon, use that (cast your Geometry to it), then you can use getPointN(index).
Coordinates are not Points by the way. Coordinate is not a geometry in JTS, just a class to hold numeric values. Points are actual geometries.
This is a fairly remedial question. I have been looking at the documentation for the JTS DelaunayTriangulationBuilder and I am at a loss as to how to do what seems like it should be a simple thing. I wish to take a series of points, triangulate them, and then interpolate the Z value of a random point within that mesh. It's non-obvious from a cursory reading how to do this. Any ideas?
After you've loaded up the triangulation object, call getSubdivision() on it to get the triangulation. It uses a quad-edge data structure, which you'll need later. (It's easier to understand if you know what a half-edge or winged-edge representation is.) The resulting QuadEdgeSubdivision has a method locate that, given a coordinate, returns one of the edges of the enclosing triangle (as a quad-edge). Get its origin vertex with orig() and its destination vertex with dest(). Get another edge with oNext() Its destination vertex is the third vertex (also dPrev().origin() is the same vertex). Now that you have the three vertices, represent your test point as a Vertex and call interpolateZValue.
For example:
public static double
interpolateZ(DelaunayTriangulationBuilder triangulation,
Coordinate coordinate) {
QuadEdgeSubdivision quadEdgeSubdivision = triangulation.getSubdivision();
QuadEdge edge = quadEdgeSubdivision.locate(coordinate);
return new Vertex(coordinate.x, coordinate.y)
.interpolateZValue(edge.orig(), edge.dest(), edge.oNext().dest());
}
You're right, though. It's not obvious how to do this from reading their API.
I'm not familiar with JTS DelauneyTriangulationBuilder, but it sounds like you have a collection of points (x,y,z), and you are submitting the 2D (x,y) pairs to the triangulator. This gives you a planar triangulation of the (x,y) points, but also a mesh who's vertices are the original (x,y,z) points.
Once you have a triangulation, you wish to find the point (p,q,r) on the mesh that corresponds to the planar point (p,q). To do so, find the triangle T of the Delauney triangulation that contains (p,q). Find the barycentric coordinates of (p,q) relative to T, and use these to compute a weighted average r of the z values corresponding to the vertices of T. That weighted average is the Z value you're looking for. In other words, (p,q,r) is on the mesh.
I need to calculate the distance from a point [x y z] to the surface of an object (at this stage a simple rectoid, but later an arbitrary shape) along [0 0 1].
I could do this defining the surfaces as planes using unit vectors and then doing a linear algebra calculation to find the distance to all the planes along [0 0 1] but as someone fairly new to coding and Java, I wanted to see if there was a library or a more efficient way of doing this as in the long term I may have complex convex objects, so need to be careful to use standard practices (so I can use something else to generate the planes!)
Thanks,
If you are using Point3D to represent your points then you have a distance method you can use to calculate the distance. So the question is which point on the surface do you want? If you just need any point on the surface you could just pick one of the corner points and use that to calculate the distance.
I have drawn a quadratic curve using the QuadCurve2d in java using start, end and one control points. Is there a way I can find out the equation of this curve? The reason why I need is that at some point of this curve it might intersect a circle and I want to know their point of intersection. So basically I want to solve two equations, but I dont know the equation of the curve generated by QuadCurve2D.
Any help will be appreicated.
Regards
S
See the Javadoc for java.awt.geom.PathIterator, specifically the SEG_QUADTO field, in which the control equation in terms of the start, end and control points is given.
Take a look at Area class. Method
public void intersect(Area rhs) {
curves = new AreaOp.IntOp().calculate(this.curves, rhs.curves);
invalidateBounds();
}
You can investigate the sources to understand how intersection point are calculated.
That function uses a quadratic bezier curve:
You can find it on Wikipedia