Hi Ari,
Its been a while since you posed the question but I recently started looking for the answer too. Andy McW and I went over the plugin to try and figure out a spreadable method and we got a very workable if not perfect solution.
The patch explains why but it ain’t bad.
Here’s the code if you wanna peak:
#region usings
using System;
using System.ComponentModel.Composition;
using VVVV.PluginInterfaces.V1;
using VVVV.PluginInterfaces.V2;
using VVVV.Utils.VColor;
using VVVV.Utils.VMath;
using VVVV.Core.Logging;
- endregion usings
namespace VVVV.Nodes
{
#region PluginInfo
[PluginInfo(Name = "IntersectCircles", Category = "2d", Help = "Basic template with one value in/out", Tags = "")](PluginInfo(Name = "IntersectCircles", Category = "2d", Help = "Basic template with one value in/out", Tags = ""))
#endregion PluginInfo
public class C2dIntersectCirclesNode : IPluginEvaluate
{
#region fields & pins
[Input("Centers")](Input("Centers"))
ISpread<Vector2D> FCenters;
[Input("Radii", DefaultValue = 1.0)](Input("Radii", DefaultValue = 1.0))
ISpread<double> FRadii;
[Output("Intersections")](Output("Intersections"))
ISpread<Vector2D> FIntersections;
[Output("Number of Solutions")](Output("Number of Solutions"))
ISpread<int> FSolutionCount;
[Import()](Import())
ILogger FLogger;
#endregion fields & pins
//called when data for any output pin is requested
public void Evaluate(int SpreadMax)
{
FIntersections.SliceCount = SpreadMax;
FSolutionCount.SliceCount = SpreadMax;
for(int i = 0; i < FIntersections.SliceCount; i++)
{
FIntersections.RemoveAt(i);
}
for (int i = 0; i < SpreadMax; i++)
{
for (int j = i + 1; j < SpreadMax; j++)
{
Vector2D s1;
Vector2D s2;
FSolutionCount[i](i) = CircleIntersection(FCenters[i](i), FRadii[i](i), FCenters[j](j), FRadii[j](j), out s1, out s2);
FIntersections.Add(s1);
FIntersections.Add(s2);
}
}
}
private int CircleIntersection (Vector2D c1, double c1r, Vector2D c2, double c2r, out Vector2D p1, out Vector2D p2)
{
p1 = new Vector2D();
p2 = new Vector2D();
//Calculate distance between centres of circle
double d = !(c1 - c2);
double m = c1r + c2r;
double n = c1r - c2r;
if (n < 0)
n = n * -1;
//No solns
if ( d > m )
return 0;
//Circle are contained within each other
if ( d < n )
return 0;
//Circles are the same
if ( d == 0 && c1r == c2r )
return 0;
//Solve for a
double a = ( c1r * c1r - c2r * c2r + d * d ) / (2 * d);
//Solve for h
double h = Math.Sqrt( c1r * c1r - a * a );
//Calculate point p, where the line through the circle intersection points crosses the line between the circle centers.
Vector2D p;
p.x = c1.x + ( a / d ) * ( c2.x -c1.x );
p.y = c1.y + ( a / d ) * ( c2.y -c1.y );
//1 soln , circles are touching
if ( d == c1r + c2r )
{
p1 = p;
return 1;
}
//2solns
p1.x = p.x + ( h / d ) * ( c2.y - c1.y );
p1.y = p.y - ( h / d ) * ( c2.x - c1.x );
p2.x = p.x - ( h / d ) * ( c2.y - c1.y );
p2.y = p.y + ( h / d ) * ( c2.x - c1.x );
return 2;
}
}
}
Hope its still helpful,
Hadasi
Circle Interesector Demo (25.5 kB)