Smrf.NodeXL.Visualization.Wpf.TriangleVertexDrawingHistory.GetEdgeEndpoint C# (CSharp) Method

GetEdgeEndpoint() public method

public GetEdgeEndpoint ( Point otherEndpoint, Point &edgeEndpoint ) : void
otherEndpoint Point
edgeEndpoint Point
return void
    GetEdgeEndpoint
    (
        Point otherEndpoint,
        out Point edgeEndpoint
    )
    {
        AssertValid();

        Point oVertexLocation = this.VertexLocation;

        // Instead of doing geometry calculations similar to what is done in 
        // VertexDrawingHistory.GetEdgePointOnRectangle(), make use of that
        // method by making the triangle look like a rectangle.  First, figure
        // out how to rotate the triangle about the vertex location so that the
        // side containing the endpoint is vertical and to the right of the
        // vertex location.

        Double dEdgeAngle = WpfGraphicsUtil.GetAngleBetweenPointsRadians(
            oVertexLocation, otherEndpoint);

        Double dEdgeAngleDegrees = MathUtil.RadiansToDegrees(dEdgeAngle);

        Double dAngleToRotateDegrees;

        if (dEdgeAngleDegrees >= -30.0 && dEdgeAngleDegrees < 90.0)
        {
            dAngleToRotateDegrees = 30.0;
        }
        else if (dEdgeAngleDegrees >= -150.0 && dEdgeAngleDegrees < -30.0)
        {
            dAngleToRotateDegrees = 270.0;
        }
        else
        {
            dAngleToRotateDegrees = 150.0;
        }

        // Now create a rotated rectangle that is centered on the vertex
        // location and that has the vertical, endpoint-containing triangle
        // side as the rectangle's right edge.

        Double dWidth = 2.0 * m_dHalfWidth;

        Rect oRotatedRectangle = new Rect(
            oVertexLocation.X,
            oVertexLocation.Y - m_dHalfWidth,
            dWidth * WpfGraphicsUtil.Tangent30Degrees,
            dWidth
            );

        Matrix oMatrix = WpfGraphicsUtil.GetRotatedMatrix(oVertexLocation,
            dAngleToRotateDegrees);

        // Rotate the other vertex location.

        Point oRotatedOtherVertexLocation = oMatrix.Transform(otherEndpoint);

        // GetEdgeEndpointOnRectangle will compute an endpoint on the
        // rectangle's right edge.

        Point oRotatedEdgeEndpoint;
        
        GetEdgeEndpointOnRectangle(oVertexLocation, oRotatedRectangle,
            oRotatedOtherVertexLocation, out oRotatedEdgeEndpoint);

        // Now rotate the edge endpoint in the other direction.

        oMatrix = WpfGraphicsUtil.GetRotatedMatrix(oVertexLocation,
            -dAngleToRotateDegrees);

        edgeEndpoint = oMatrix.Transform(oRotatedEdgeEndpoint);
    }