I searched for this and found similar answers but they were more math based than programming based, and I need a little help putting it in to code.
I have an arbitrary shape, but let's call it a diamond for now, with the following coordinates:
A = (0,0)
B = (50, 50)
C = (0, 100)
D = (-50, 50)
Think of the movement contraints on this as if you had a rubber band and moved a peg. The lines will always connect but their orientation to one another must not change. So since the slope of AB is 1, it needs to remain 1. I have that part working fine.
Now, say I move "B" such that it rests at (100, 100). I know the slopes of AB (unchanged), BC (before B was moved, and after, but after is useless and wrong), CD (unchanged) and DA (unchanged). I also know the coordinates of A, B and D. I need to find the position of C, such that all slopes remain unchanged and it rests at the logical point where BC and CD should intersect.
Mathematically, I know C belongs at (50, 150) now but I need a generalized formula to figure this out. This is a single example so what I'm looking for is something generalized enough to reuse. Of course, there are snags when lines are parallel or vertical but I can handle that.
This picture should help visualize it. B started at "B" and I moved it to "B2". C needs to move to ???
Thanks a ton if you can help!
EDIT: This seems to be the answer, but I'm anything but a math whiz and don't get how it translates in to some sort of generalized formula. How do you detect where two line segments intersect?