Re: geometric problem
- Posted by "Carl R. White" <C.R.White at SCM.BRAD.AC.UK> Mar 18, 1999
- 551 views
I'll attempt to sum up what I _think_ you've said :) You have the following: V1 / \. / V2 / | V4 | `-. P `. -- All Vn to Vm lines are *supposed* to be straight :) `-. | `-.V3 And want to translate to: V1'------V2' | | | | | P' | | | V4'------V3' You never said how big V'(1,2,3,4) has to be though... Why you want to do this (unless you're writing a ray-tracer) is beyond me, but I'll have a go. I'm thinking on my feet here. Be warned! The first sensible thought that occurs is the following: (this will not provide a correct answer. Approximation only) 1) Figure out the coordinates of the rectangle (X) that would completely surround V(1,2,3,4). In this case (from the diagrams above) they're: X1 = {V4.x,V1.y} X2 = {V3.x,V1.y} X3 = V3 X4 = {V4.x,V3.y} 2) Alter the P position like so: P.x = P.x + (X(1,2,3,4).x - V(1,2,3,4).x ) / 4 P.y = P.y + (X(1,2,3,4).y - V(1,2,3,4).y ) / 4 ^^^ This is really the all-important bit. There's probably a much better way to do this, but I'd have to sit for a few hours to work it out. As it stands, I've used an arithmetical mean of the differences of respective x and y coordinates. Maybe a geometric mean may have been better... ;) 3) Scale X(1,2,3,4).x, X(1,2,3,4).y and P to the sizes you want them to be (multiply or divide) to turn them into V'(1,2,3,4) and P'. You'll have to offset the coordinates so that one of the Xs is {0,0} for the scaling. Add the offset back in to complete the calculation. 4) If this was homework, I hope I got it horribly wrong. ;) HTH, Carl PS If you don't understand the notation that I munged for this post, mail again and I'll explain it. :) -- Carl R White -- cyrek- at -bigfoot.com -- http://www.bigfoot.com/~cyrek aka Cyrek -- No hyphens :) -- Bigfoot URL Alias