From: BERNDT, J. S. (J. (JSC-E. (LM) <jon...@js...> - 2001-09-26 20:17:29
|
> I know that we have a few math/geometry hacks lurking on the list, so > here's what I hope will be a simple problem: > > Given a line segment in 3D space defined by the points (x1, y1, z1) > and (x2, y2, z2), find a point (x3, y3, z3) on the segment where > only the z3 value is known. It's safe to assume that z3 falls > between z1 and z2, and that z1 != z2. > > All answers will be appreciated, but the appreciation for algorithmic > answers will be more sincere than the appreciation for formulaic > answers. It's sort of a variation on similar triangles. The percentage of distance that z3 falls along the whole distance z1z2 is the same as how far x3 will fall along the distance x1x2: x3 = [ (z3-z1)/(z2-z1)) * (x2-x1) ] + x1 -or- factor = (z3-z1)/(z2-z1) x3 = factor * (x2 - x1) + x1 y3 = factor * (y2 - y1) + y1 z3 = factor * (z2 - z1) + z1 Jon |