# Thread: Z value of point in square

1. ## Z value of point in square

I have 4 points that each are 64 x,y values apart with different Z values that are arranged like this with 90 degree angles:

0,0 64,0

0,64 64,64

Also inside that square there is a 5th value I only have the X and Y value of and need to find the Z value of.

If anyone has any ideas on how to solve this id greatly appreciate it I have been at this for hours...

2. I don't get it at all.

Can you provide the exact wording of the question and possibly an associated drawing?

3. It actually is for a program im writing. I have been able to create a Z value grid that spans every 64 points on a plane (hence the 0-64 values). There will be a creation at point 5 that needs to be on the plane so as such I have to find an accurate height for the that point in relation to the surrounding 4 points based on there height. The lines from point 1 to 2 and 2 to 3 ect will be straight and not curved if that matters...

4. I see, I think, but it remains in appearance very ill-defined. What sort of relationship is supposed to hold for points in the square vs. the four corners?

1) You can average the four, I suppose.
2) One way I have used, from time to time, is the average of all five values. Yes, it's circular, but it does produce smooth results. It's almost the same as 1).
3) You can define some nice algebraic function to hold throughout each square. There are infinitely many varieties.
4) If you have a smooth function, do you need the edges to match up with their neighbors?
5) You can perform a simple weighting of the corners based on their distance from the desired point. In this case, using the Distance Formula:

(0,0) is 49.24 away from (20,45)
(0,64) is 27.59 away from (20,45)
(64,64) is 47.93 away from (20,45)
(64,0) is 62.94 away from (20,45)

As you probably do not want a direct relationship (more distance = more influence), you'll have to adjust to reverse that. I just subtracted each from the maximum possible distance, $\displaystyle 64*\sqrt{2}$, to produce:

(0,0) is weighted as 41.26
(0,64) is weighted as 62.91
(64,64) is weighted as 42.57
(64,0) is weighted as 27.56
Total of all weights is 174.30

The weighting, then: $\displaystyle \frac{41.26(10)+62.91(15)+42.57(5)+27.56(4)}{174.3 0} = 9.63$. Of course, you could use more decimal places if you wish.

Well, that's a little discussion, but really, you just have to make up your mind what it is you want and what fits into your application.

5. all 4 sides have the same distance and really i don't care how i get the z value it just needs to be accurate in relation to the pathing of the other 4 points

What would be a formula for the 5 point thing? is seems like it might work

PS: I apologise for my lack or an simple explanation just i cant think of one... If you have AIM my sn is botanicvelious

7. ok i get what you did just how do i reverse it?

Four corners, x-y address of 5th point, and some arithmetic. That is all it is.

Note: I'm more fond of the weighting than a simple average, since a simple average would produce the same value for ALL points in the square. That may be inappropriate.

9. no i mean to reverse the weighting because it would need LESS weight farther away

Also what about making it into a set of 4 right triangles?

10. Originally Posted by botanic
I have 4 points that each are 64 x,y values apart with different Z values that are arranged like this with 90 degree angles:

0,0 64,0

0,64 64,64

Also inside that square there is a 5th value I only have the X and Y value of and need to find the Z value of.

If anyone has any ideas on how to solve this id greatly appreciate it I have been at this for hours...
Originally Posted by botanic
It actually is for a program im writing. I have been able to create a Z value grid that spans every 64 points on a plane (hence the 0-64 values). There will be a creation at point 5 that needs to be on the plane so as such I have to find an accurate height for the that point in relation to the surrounding 4 points based on there height. The lines from point 1 to 2 and 2 to 3 ect will be straight and not curved if that matters...
The equation of the plane we will take to be $\displaystyle aX + bY + Z = c$. To determine the coefficients $\displaystyle a,\ b \text{ and }c,$ let $\displaystyle Z_{X,Y}$ be the value of $\displaystyle Z$ for one of the four known points $\displaystyle (X,Y)$. For example, $\displaystyle Z_{0,64}$ is the $\displaystyle Z$ value for the point $\displaystyle (X,Y) = (0,64).$

Then set $\displaystyle c = Z_{0,0}$, $\displaystyle a = (Z_{0,0} - Z_{64,0})/64$ and $\displaystyle b = (Z_{0,0} - Z_{0,64})/64.$ For the fifth point $\displaystyle (X,Y)$, $\displaystyle Z_{X,Y} = c - aX - bY.$

Since 3 points determine a plane, the fourth known point should satisfy $\displaystyle Z_{64,64} = c - 64a - 64b.$

11. ?? Plane? We know 4 and are determining the 5th.

12. Originally Posted by botanic
no i mean to reverse the weighting because it would need LESS weight farther away
This is already in the original description above. Initial distances are subtracted from the maximum possible distance.

Also what about making it into a set of 4 right triangles?
That is essentially what was done with the distance formula.

13. Originally Posted by botanic
It actually is for a program im writing. I have been able to create a Z value grid that spans every 64 points on a plane (hence the 0-64 values). There will be a creation at point 5 that needs to be on the plane so as such I have to find an accurate height for the that point in relation to the surrounding 4 points based on there height. The lines from point 1 to 2 and 2 to 3 ect will be straight and not curved if that matters...
Originally Posted by TKHunny
?? Plane? We know 4 and are determining the 5th.
Yeah, the talk of a plane and an accurate height threw me off. Instead, the 4 points are not on a plane and there is no unique accurate height.

I'd solve the problem by using points (0,0), (64,0) and (0,64) to determine a triangle and corresponding plane with the Z values and the points (64,0), (0,64) and (64,64) to determine a second triangle and plane. Then depending which triangle the fifth point falls in, I'd put the fifth Z value on the corresponding plane using the method I suggested.

14. As an opportunity to use a program I wrote to create 3D graphs using LaTeX, I'll finish off my suggestion.

I'd solve the problem by using points (0,0), (64,0) and (0,64) to determine a triangle and corresponding plane with the Z values and the points (64,0), (0,64) and (64,64) to determine a second triangle and plane. Then depending which triangle the fifth point falls in, I'd put the fifth Z value on the corresponding plane using the following method.

The equation of a plane is $\displaystyle aX + bY + Z = c$. To determine the coefficients $\displaystyle a,\ b \text{ and }c,$ let $\displaystyle Z_{X,Y}$ be the value of $\displaystyle Z$ for one of the four known points $\displaystyle (X,Y)$. For example, $\displaystyle Z_{0,64}$ is the $\displaystyle Z$ value for the point $\displaystyle (X,Y) = (0,64).$

Now let $\displaystyle (X,Y)$ denote the fifth point. Take the first triangle to be (0,0), (64,0) and (0,64). The fifth point is in this triangle if $\displaystyle X + Y \le 64.$ Then set $\displaystyle c = Z_{0,0}$, $\displaystyle a = (Z_{0,0} - Z_{64,0})/64$ and $\displaystyle b = (Z_{0,0} - Z_{0,64})/64.$ For the fifth point, $\displaystyle Z_{X,Y} = c - aX - bY.$

The second triangle is (64,64), (64,0) and (0,64). The fifth point is in this triangle if $\displaystyle X + Y \ge 64.$ Then set $\displaystyle c = Z_{64,0} + Z_{0,64} - Z_{64,64}$, $\displaystyle a = (Z_{64,64} - Z_{0,64})/64$ and $\displaystyle b = (Z_{64,64} - Z_{64,0})/64.$ For the fifth point, $\displaystyle Z_{X,Y} = c - aX - bY.$

Here is the picture using botanic's example with points (0,0,10), (64,0,4), (0,64,15) and (64,64,5) and fifth point (20,30,$\displaystyle Z$). (I'm using a little different fifth point so it is not too close to the boundary of the two triangles.) The fifth point falls in the first triangle and has $\displaystyle Z$ value 10.469 shown by the +.

$\displaystyle \setlength{\unitlength}{.1cm}\begin{picture}(83,59 )(-10,-20) \qbezier(19,29)(19,29)(48,-8)\put(23,14){+} \qbezier(48,-8)(48,-8)(48,-10)\qbezier(48,-8)(48,-8)(-0,7)\qbezier(48,-8)(48,-8)(63,14)\qbezier(48,-10)(48,-10)(0,0)\qbezier(48,-10)(48,-10)(63,11)\qbezier(-0,7)(-0,7)(0,0)\qbezier(-0,7)(-0,7)(19,29)\qbezier(63,14)(63,14)(63,11)\qbezier(6 3,14)(63,14)(19,29)\end{picture}$

15. Much thanks now i just need to convert that into a programmable format and im good to go