1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
// ----------------------------------------------------------------------------
// Copyright (c) 2014, Nicolas P. Rougier. All Rights Reserved.
// Distributed under the (new) BSD License.
// ----------------------------------------------------------------------------
/* ---------------------------------------------------------
Computes the center of the 2 circles with given radius passing through
p1 & p2
Parameters:
-----------
p0, p1: Points ascribed in the circles
radius: Radius of the circle
Return:
-------
Centers of the two circles with specified radius
--------------------------------------------------------- */
vec4 circle_from_2_points(vec2 p1, vec2 p2, float radius)
{
float q = length(p2-p1);
vec2 m = (p1+p2)/2.0;
vec2 d = vec2( sqrt(radius*radius - (q*q/4.0)) * (p1.y-p2.y)/q,
sqrt(radius*radius - (q*q/4.0)) * (p2.x-p1.x)/q);
return vec4(m+d, m-d);
}
|