Finding the x and y coordinates of the peak is simple. Since there is no grid, let's arbitrarily choose to make (0,0) be the center of your rectangle and (1,1) be the top right corner. For finding the location of the peak, the height of the peak is irrelevant, so take the height of the top right corner and subtract it from all the heights (effectively lowering the height of the whole landscape). Let:
a=adjusted height of top left corner
b=adjusted height of bottom left corner
c=adjusted height of bottom right corner
0=adjusted height of top right corner ;-)
Recognize that the equation for the cone is (x-x')^2+(y-y')^2=m(z-z')^2, but we'll set m=1 because it only effects the slope and thus the height of the peak, which we're ignoring for now. Plug in the above 4 points to get 4 equations. Take the fourth equation and subtract it from the other three to get three new equations that have no ^2 terms:
4x -a^2+2az=0
4x+4y-b^2+2bz=0
4y-c^2+2cz=0
These can be solved straightforwardly. The z value in the solution is irrelevant because I've taken so many shortcuts by procrastinating dealing with z. But for the others, we get:
x= a(c-b)(a-b-c) / (4(a+c-b)) ; when (b!=c; a+c != b)
y= c(b-a)(b+a-c) / (4(a+c-b)) ; when (b!=c; a+c != b ; a!=0)
For the rest, use the similar triangles thing that everyone else recommended: Using the x,y found above, compute the distance between each corner of the rectangle and the computed x,y (remembering that the corners are located at (+/-1, +/-1)). Choose any two of those corners such that their x,y distance to the peak is not equal. Denote their heights h1 and h2 and their x,y distances to the peak as w1 and w2. h=(h1*w2 - h2*w1) / (w2-w1) (when w2!=w1).
Update:The above is based on the
incorrect assumption of slope==1. Please discard.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.