Equation of curve generated by QuadCurve2D in Java? - java

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

Related

Method to calculate the distance between points and return point's distance to the origin in a 3D array (java)

I'm trying to make a program that calculates the distance between one point to another in a 3D array, and then returns the point's distance to the origin. What kind of method(s) could I use for this? How should I think? Are there any good tutorials about this (that aren't too basic)? I'm a beginner and very new to methods and would really appreciate some help. :)
Here's the math basics about calculating distance between two points in 3D: https://math.stackexchange.com/questions/42640/calculate-distance-in-3d-space
The relevant Java functions that will help you are:
Math.sqrt: square root (e.g. Math.sqrt(6) => 2.44948974278)
Math.pow: raise first argument to the power of the second (e.g. Math.pow(2,4) => 16)
Give it a try and post your code if you want more specific help.

Arrangement-of-rectangles algorithm and investigating it on a per-coordinate basis

(I am not sure if this qualifies as CodeGolf, as I do actually have a use for this despite its abstract-sounding nature... xD If it does, let me know and I'll add it to the tags...)
This problem consists out of two joined-at-the-hip parts: one about finding a suitable formula/algorithm, and the other about using that algorithm to deal with the basic needs that I am eventually interested in.
Suppose you have a sufficiently large two-dimensional field that needs to be filled with rectangles. Pre-generating the locations of these non-overlapping rectangles (of various sizes, which are subject to a minimum and maximum size) is unfeasible due to memory constraints. These rectangles themselves are not subject to the 'grid' implied by the field; a random rectangle can be rotated to any degree: 30, 45 or 87 or whatever degree angle, it is fine as long as it does not overlap with any other rectangles. The 'density' of the rectangles would be rather low, thus leaving a lot of empty space between them. (If the algorithm could be easily tweaked for as far this density is concerned, that would be very interesting!) Generating the positions of the rectangles are the result of a single input 64-bit 'seed', of which varying inputs should lead to different results in the arranged layout of rectangles. Finally, the output should not be overly grid-like or recognizably regular; visually speaking, it should be a pretty chaotic arrangement if plotted.
// Note: This algorithm would not actually generate or produce to start
// off with. The logic is concentrated in the questions that follow below.
// Please note: there is NO initialization phase of any sort.
Visual aid:
Now, given only the knowledge of a certain (x, y) coordinate and the generating 'seed', how can I determine whether this coordinate is inside of a rectangle? How do I determine the corners of said rectangle? And finally, how do I get the center coordinate of the nearest Rectangle?
public Boolean isInsideRectangle(int x, int y, long seed) { ... }
public Boolean isCornerOfRectangle(int x, int y, long seed) { ... }
public Point getCenterOfNearestRectangle(int x, int y, long seed) { ... }
I simply have no clue how to approach this problem, or I would include some code. The world of math is one I am not well-versed in. So while I most definitely welcome code, explanations are even more welcome. :-)
(Pre-emptive 'No, it is not homework or anything of the sort.' needs to be included: this is just one facet of a personal project.)

Algorithm to compute shortest knight distance (chess)

I'm trying to implement the absolute rank-file distance described on Knight-Distance from the Chess Programming Wiki, but I'm a little confused on what ints a and b are supposed to be in
int knightDistance(int a, int b).
Don't you need two sets of coordinates to figure this out (start location and destination)?
I thought maybe they were using 0,0 as the start and then you just give the difference between start and end locations, but that gives bad output.
How is this supposed to work, and does this algorithm work for any size grid, or just 8×8?
I believe that a and b are the rank and file distance deltas from the current position. From symmetry, only the difference between the current position and the desired destination matter.

Lagrange Interpolation in java using BigInteger

I am trying to find a function to perform Lagrange Interpolation in java. I have 3 (x,y) pairs, where x and y are BigInteger objects, and would like to use some interpolation function to determine f(0) for the polynomial f used to calculate my x,y these pairs. Something like this seems perfect, except that this class doesn't seem to actually belong to a package I can import: http://nssl.eew.technion.ac.il/files/Projects/thresholddsaimporvement/doc/javadoc/Lagrange.html
Forgive me if my question is naive, any help I can get would really be appreciated.
A similar class seems to be in Apache Commons Math. This is probably going to be much more reliable than what you found.
http://commons.apache.org/math/apidocs/org/apache/commons/math3/analysis/polynomials/PolynomialFunctionLagrangeForm.html
It would appear that you construct it with PolynomialFunctionLagrangeForm(double[] x, double[] y), then call value(0) to get the value at x = 0.

Cubic B-spline curve in Java

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.

Categories