Monday, March 7, 2011

Drawing arrows in JavaFX

Some time in the past, I was wondering what's the easiest solution for drawing arrow connections between shapes. The problem boils down to computing boundary point for given shape, which intersects with connecting line.
The solution is not so difficult when we consider polygon shapes. But it becomes more difficult considering curves and far more difficult for generic SVG shapes.
In this article, I show a simple way to find such boundary points for generic SVG shapes, utilizing JavaFX "contains" method and simple bisection algorithm.
Following application does the job: Launch JNLP, Browse on GitHub.
Application allows to drag shapes to track shape boundaries.

So, "contains" method in JavaFX allows us to poll any 2D point for intersection with SVG shape. Next, we need to assume, that we know a point inside a shape, from which every ray has exactly one intersection. This includes star-like shapes and ellipses. Next, we can use simple bisection algorithm to find such boundary point. We cut off once length between two points is too small. Following snippet does the job: Next, we need to draw arrows on the ends. In order to do that, we can use JavaFX Affine Transform, which is matrix transformation for SVG path. We need to compute transformation vectors for the matrix. This sounds scarry, but in fact is relatively easy. First vector in matrix is (targetPoint - sourcePoint) / length. Second one is perpendicular to it. Following code applies transformation:

4 comments:

  1. This blog offers a great information to its readers. Thanks for sharing it. I am looking forward to reading more stuffs from you.
    buy domain in india

    ReplyDelete
  2. Really i found this article more informative, thanks for sharing this article! Also Check here
    online idea lab

    ReplyDelete
  3. Hi, Thanks for this valuable information.Mukul Sharma   When the film “Birds of Prey” was released on 07 Feb 2020, trade pundits projected it to gross $50 to $55 million during the opening weekend in the US and Canadian markets. Warner Bros, the distributors of the film had their own projection pegged at $45 million. However, It could muster only &hellip.
    https://onlineidealab.com/warner-bros-loses-22-million-in-a-weekend-due-to-poor-seo/

    ReplyDelete
  4. Some common uses of PPR pipes in Egypt:
    High Temperature Resistance: Can withstand high temperatures, making them ideal for hot water systems.
    Thermal Insulation: ppr pipe manufacturing companies thermal insulation properties, maintaining the temperature of the water.
    Durability: Long service life even under high temperature and pressure conditions.

    ReplyDelete