function xyw = circle_segment_rule_from_chord ( r, c, p1, p2, p ) 

%*****************************************************************************80
%
%% circle_segment_rule_from_chord() returns a circle segment quadrature rule.
%
%  Discussion:
%
%    Begin with a circle of radius R.  Choose two points P1 and P2 on the
%    circle, and draw the chord P1:P2.  This chord divides the circle
%    into two pieces, each of which is called a circle segment.
%    Consider one of the pieces.  The "angle" of this segment is the angle 
%    P1:C:P2, where C is the center of the circle.  Let Q be the point on 
%    the chord P1:P2 which is closest to C.  The "height" of the segment
%    is the distance from Q to the perimeter of the circle.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    21 May 2013
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real R, the radius of the circle.
%    0 < R.
%
%    real C(2,1), the center of the circle.
%
%    real P1(2,1), P2(2,1), the endpoints of the chord.
%
%    integer P, the algebraic precision of the rule.
%    0 <= P.
%
%  Output:
%
%    real XYW(N,3), columns of X and Y node coordinates, and weights.
%    N = ceil((p+1)/2) x ceil((p+2)/2).
%

%
%  Determine the angular width of the circle segment.
%
  theta = circle_segment_angle_from_chord ( r, c, p1, p2 );
%
%  Determine the rotation of the segment.
%
  alpha = circle_segment_rotation_from_chord ( r, c, p1, p2 );
%
%  Get a quadrature rule for a circle of center (0,0), with central angle 0
%  and half angle width theta/2.
%
  thetah = theta / 2.0;
  xyw = gqcircsegm ( p, thetah, r );
%
%  Rotate the XY coordinates by ALPHA.
%
  xyw(:,1:2) = xyw(:,1:2) * [ cos(alpha), -sin(alpha); sin(alpha), cos(alpha) ]';
%
%  Translate the XY coordinates by C.
%
  xyw(:,1) = xyw(:,1) + c(1);
  xyw(:,2) = xyw(:,2) + c(2);

  return
end
