Calculations for pen-drawn shapes may result in vertices that fall outside of the stage boundaries. Depending on how far outside the boundaries the point is, it may not be possible (without work-around code) to send the pen there. This may result in a distorted shape. The black rectangle represents the edge of the stage. The purple dots mark the vertices of a quadrilateral. Drag them to reshape/resize the quadrilateral. A red quadrilateral is first drawn to mark the entire shape. The lines are "clipped" as they are drawn to fit inside the boundaries (without altering the shape). The result is drawn in blue (over the red original shape) Lines fully outside the bounding box are not drawn at all. You may resize the bounding box by dragging the black pointers.
No trigonometry used! (too slow in my experience) To use this for other shapes, the code to draw them must draw the sides individually (rather then "pen down; move; move; move" etc. - see "Clip Quad" block for guidance) To use, backpack the "edge line-clipping" sprite. I developed this for a future attempt at 3D (for "z-clipping"). Thanks to @Whitepatchwastaken and @Purpledragon2015for detecting and reporting bugs.