I'm attempting to reproduce within AfterEffects a common feature of AutoCAD drawings, in which two points (typically the two lower corners of a bounding box defining an implied edge) each stay attached to another respective object (line segment) on either side and -- driven by movements of those attached corners -- the object automatically scales up or down AND rotates to match the angle of the two points. It's similar to the now-common touch-screen gesture of scaling an image by touching the screen with two fingers and spreading the fingers apart...with the added challenge of accommodating rotation at the same time.
Basic idea / what I've tried:
1) Move anchor point for the "joint object" (the object suspended between two defined points) to its lower left corner at default rotation (zero degrees)...this becomes the "theta" of the relevant trig functions;
2) Use Expressions (and basic trig) to set the rotation of the joint object to the angle between Point A and Point B;
3) Use Expressions to calculate the Scale of the joint object (distance formula of line from A to B/original base width of joint object) * 100 (to return a percentage value);
I've managed to get something which works partially (say, within -45 degrees to 45 degrees), but my Rotation Expression for the joint object falls off into all sorts of craziness outside that range.
I also haven't come up with a fix for the divide-by-zero errors. I've tried temporarily adding in tiny numbers (.000000001) to avoid zero, but I feel mathematically guilty about it as it's a kind of cheat and I'd rather work out a proper solution.
Any recommendations -- including fresh/lateral thinking approaches to achieving the goal through some other means, would be greatly appreciated.