Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for inconsistencies between place() and intersects() #112

Merged
merged 5 commits into from
Apr 16, 2018

Conversation

robinhouston
Copy link
Contributor

@robinhouston robinhouston commented Apr 15, 2018

Improved place(a, b, c) function that avoids overlaps between c and a or b.

Note that flare-test.js fails. I haven’t investigated why: I hope it is simply a result of the changes in numerical precision causing slightly different circle placements.

See discussion on #111. Fixes #109.

We’re looking for cases where place(a, b, c) will place c so it
intersects with a or b.
The old place(a, b, c) function would sometimes place c so it overlapped
with a and/or b, if c had a much larger radius than a and b.

This version doesn’t seem to.

As per discussion on d3#111.

This commit also updates the tests in find-place-bugs.js to
use the new function, and updates the intersection test in
siblings-test.js to match

Note that flare-test.js fails. I haven’t investigated why: I hope it is simply
a result of the changes in numerical precision causing slightly different
circle placements.
@mbostock
Copy link
Member

I like the idea of choosing the larger of the two circles as the starting center. I’ve written up some notes here and will take a crack at merging our two implementations soon:

https://beta.observablehq.com/@mbostock/tangent-to-two-circles

@robinhouston
Copy link
Contributor Author

robinhouston commented Apr 16, 2018

The idea behind my code is to use a coordinate frame in which the first circle (say a) is centred at the origin, and the second (say b) at (1, 0).

In this frame the equations are easy to solve, then we transform the result back to the original coordinate system.

Subtracting the equations gives 1 - 2x = (rb + rc)^2 - (ra + rc)^2 = (rb - ra)(ra + rb + 2rc), which gives x; then y = ±sqrt((ra + rc)^2 - x^2).

Since the values that had been divided by scale = sqrt(dc) are
only being used in pairs, we can avoid the square root and just
divide by dc instead.

This should help with the precision, marginally, I hope.
@mbostock
Copy link
Member

Our approaches are equivalent:

image

@mbostock mbostock merged commit 125af32 into d3:place-precision Apr 16, 2018
This was referenced Apr 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants