java - Get intersection points of line and shape -
I have a custom size as shown in the image. Suppose that the blue rectangle covering the shape in the image shows the bounding box of that size.
If I have to draw a line from the boundary of the bounding rectangle, how can I get the intersection points (in the image they use the green color)? I am using Java 2D, I have a generic path with all coordinates, out of which I draw the size on the screen. You can take the Genre Path to your Segments (get-path, line-to, quad-to, cubic-to, Off) using the getPathIterator () method. Now you can search per segment for intersection with line. There are quadratic and cubic bezier loans in a path, to find points of intersection between a line and a bezier curve, there are several algorithms available, for example: < / P> De Castelzeau subdivision is easy to implement, but there are some problems in relatively rare cases. If you do not want to use the math library which can calculate the intersections for you, then I advise to apply the Castelluz subdivision. Edit: Another option, the path of the beijier curve segment line segment, then you need to find line / line holes.
Idea
public fixed point [] getIntersections (path path, line line) {list & lt; Point & gt; Intersection = new arreelist & lt; Point & gt; (); PathEyiterator = path.getPathIterator (); Double [] cos = new double [6]; Double [] position = new double [2]; While (! It.isDone ()) {int type = it.currentSegment (coords); Switch (Type) {Case Pathitator. SEG_ MOVETO: pos [0] = Cores [0]; Pos [1] = Cores [1]; break; Case PathIterator.SEG_LINETO: Line L = New Line (pos [0], pos [1], Codess [0], Coors [1]); Pos [0] = Cores [0]; Pos [1] = Cores [1]; Point intersection = get holes (line, L); If (intersection! = Null) intersections.add (intersection); break; // ... Default: Throw New IllegalStateException ("Unknown PathEighter Section Type:" + Type); } It.next (); } Return intersection. To Array (new point [] {}); } Line / Line intersection line / line intersections can be calculated directly, for example, using vector algebra: < (X, y, 1)
line / beijier intersections
Comments
Post a Comment