%mathpiper,def="Midpoint"

Midpoint(PointA_IsPoint,PointB_IsPoint) <-- 
[
    Local(x1,x2,y1,y2,midpointX,midpointY);
    
    x1 := PointA[1];
    x2 := PointB[1];
    y1 := PointA[2];
    y2 := PointB[2];

    midpointX := (x1 + x2)/2;
    midpointY := (y1 + y2)/2;
    
    {midpointX,midpointY};

];



Midpoint(segment_IsSegment) <-- 
[
    Local(x1,x2,y1,y2,midpointX,midpointY);
    
    x1 := segment[1][1];
    x2 := segment[2][1];
    y1 := segment[1][2];
    y2 := segment[2][2];

    midpointX := (x1 + x2)/2;
    midpointY := (y1 + y2)/2;
    
    {midpointX,midpointY};

];

%/mathpiper



%mathpiper_docs,name="Midpoint",categories="User Functions;Analytic Geometry",access="experimental"
*CMD Midpoint --- returns a Point which represents the midpoint between two points
*STD
*CALL
	Midpoint(p1, p2)
	Midpoint(s)
*PARMS

{p1} -- the first point

{p2} -- the second point

{s} -- a segment

*DESC

This function calculates the midpoint between two points using the 
midpoint formula.

*E.G.

In> PointA := Point(2,3)
Result: {2,3}
	
In> PointB := Point(6,8)
Result: {6,8}
	
In> Midpoint(PointA, PointB)
Result: {4,11/2}

In> Midpoint(Segment(Point(0,0), Point(3,4)))
Result: {3/2,2}

*SEE IsPoint, Point, Distance, Slope, Segment
%/mathpiper_docs
