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.

custom shape

Idea

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.

  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)  
  • A 2d point / line is a 3D vector (x, y, w)
  • Representation of point (x, y)
  • P1 x P2 (cross-product) through P1 and P2 points
  • L1 = (A, B, C) and L2 = for two rows ( D, E, F) is given intersection
  • by 2x transcript
  • If w = 0 then there is no single point intersection to project the lid.
  • line / beijier intersections

    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 Castelzo subsection
    • Bezier clipping <
    • The method of neuton
    • Multilateral root search

      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.

  • Comments

    Popular posts from this blog

    excel vba - How to delete Solver(SOLVER.XLAM) code -

    github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

    ios - Replace text in UITextView run slowly -