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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function findBoundaryPoint(a:Point2D,b:Point2D):Point2D { | |
// a is outside, b is inside | |
var m:Point2D = middle(a,b); | |
if (pointsLenSqr(a, b) < 1.) { | |
return m; | |
} else { | |
var n:Point2D = Point2D { | |
x: m.x - position.x | |
y: m.y - position.y | |
} | |
if (contains(n)) { | |
return findBoundaryPoint(a,m); | |
} else { | |
return findBoundaryPoint(m,b); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var u:Point2D = a.findBoundaryPoint(b.position, a.position); | |
var v:Point2D = b.findBoundaryPoint(a.position, b.position); | |
var l:Float = Math.sqrt(pointsLenSqr(u, v)); | |
content = [ | |
Path { | |
transforms: [ | |
Affine { | |
mxx: (v.x-u.x)/l | |
mxy: (v.y-u.y)/l | |
myx: (v.y-u.y)/l | |
myy: -(v.x-u.x)/l | |
tx: u.x | |
ty: u.y | |
} | |
] | |
elements: [ | |
MoveTo { | |
x: 0 | |
y: 0 | |
} | |
LineTo { | |
x: l | |
y: 0 | |
} | |
LineTo { | |
x: l-10 | |
y: 5 | |
} | |
MoveTo { | |
x: l | |
y: 0 | |
} | |
LineTo { | |
x: l-10 | |
y: -5 | |
} | |
... |
This blog offers a great information to its readers. Thanks for sharing it. I am looking forward to reading more stuffs from you.
ReplyDeletebuy domain in india
Really i found this article more informative, thanks for sharing this article! Also Check here
ReplyDeleteonline idea lab
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.
ReplyDeletehttps://onlineidealab.com/warner-bros-loses-22-million-in-a-weekend-due-to-poor-seo/
Some common uses of PPR pipes in Egypt:
ReplyDeleteHigh 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.