Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

General formula to calculate 3d-space equal distances

it's probably not the right place to post this but i don't know where else to post it.

i have 5 lines (d1 -> d5) equally distributed from each other in 3d perspective, i have the values of (a) angle, (d1) and (b5). i need to calculate (b2, b3, b4, d2, d3, d4, d5) with jquery.

enter image description here

i can calculate d5 with:

d5 = d1 - ( b5 * Math.tan(a))

but i have no idea how to calculate b2, b3 and b4. (d1 is divided into 4 identical segaments (s)) any help would be appreciated.

like image 734
razz Avatar asked Mar 08 '13 01:03

razz


People also ask

What is 3D distance formula?

What Is 3D Distance Formula? The 3d distance formula says, the distance between two points in the space A(x1, y1, z1) and B(x2, y2, z2) is given as: d=√(x2−x1)2+(y2−y1)2+(z2−z1)2.

How do you measure distance in 3D space?

The distance formula states that the distance between two points in xyz-space is the square root of the sum of the squares of the differences between corresponding coordinates. That is, given P1 = (x1,y1,z1) and P2 = (x2,y2,z2), the distance between P1 and P2 is given by d(P1,P2) = (x2 x1)2 + (y2 y1)2 + (z2 z1)2.

What is the general distance formula?

Learn how to find the distance between two points by using the distance formula, which is an application of the Pythagorean theorem. We can rewrite the Pythagorean theorem as d=√((x_2-x_1)²+(y_2-y_1)²) to find the distance between any two points.


1 Answers

What you're looking for is a projective scale. The easiest way to do this computationally is to use homogenous coordinates, take a rectangle (like the one in the first picture below) on which V is "infinitely far to the right" and find a projective transformation that maps this rectangle to the trapezium in the second picture. The vertices of the rectangle are (0|0), (0|d1), (b5|d1), (b5|0) and the corresponding vertices of the trapezium are (0|0), (0|d1), (b5|d5), (b5|0).

Illustration of a projective transformation for obtaining a projective scale

Since these are four points of which no three are collinear, we can find a unique matrix (up to scaling) M for this transformation. After some maths, it turns out that this matrix is:

[d1*b5,0,0] 
[0,b5*d5,0]
[d1-d5,0,b5*d5]

If you want to find the coordinates b3 and d3, for instance, you can multiply this matrix with homogenous coordinates of the point in the middle of the line, i.e. the vector (0.5*b5,d1,1)^T and you get the homogenous coordinates of the point (b3|d3), which can be converted into Euclidean coordinates by dehomogenisation, i.e. dividing the first two components by the third.

In general, if you have two points (b1|d1) and (bn|dn) and want to know the coordinates of n-2 equidistant points inbetween on a projective scale like this, you can compute the coordinates bi and di as like this (in your case, n would be 5, of course):

let M := matrix [[d1*bn, 0, 0], [0, bn*dn, 0], [d1-dn, 0, bn*dn]]
let v := ((i-1)/(n-1)*bn, d1, 1)
let (x,y,z) := M*v
let bi := x/z and di := y/z

As you see, this is a simple algorithm for computing the coordinates of these projectively equidistant points, and it generalises nicely to arbitrary numbers of points.

If you'd rather have a closed formula, you can compute the bi and di directly as:

let bi := (bn*d1*(i-1))/(dn*n+(d1-dn)*i-d1)
let di := d1*dn*(n-1)/(dn*n+(d1-dn)*i-d1)
like image 103
Manuel Eberl Avatar answered Oct 12 '22 21:10

Manuel Eberl