tags:

views:

128

answers:

5

Hi,

A-B-C-D are 4 points. We define r = length(B-C), angle, ang1 = (A-B-C) and angle ang2 = (B-C-D) and the torsion angle tors1 = (A-B-C-D). What I really need to do is to find the coordinates of C and D provided that I have the new values of r, ang1, ang2 and tors1. The thing is that the points A and B are rigidly connected to each other, and points C and D are also connected to each other by a rigid connector, so to speak. That is the distance (C-D) remains fixed and also distance A-B remains fixed. There is no such rigid connection between the points B and C.

We have the old coordinates of the 4 points for some other set of (r,ang1,ang2,tors1) and we need to find the new coordinates when this defining set of variables changes to some arbitrary value.

I would be grateful for any helpful comments. Thanks a lot.

I'm not allowed to post a picture because I'm a new user :(

Additional Info: An iterative solution is not going to be useful because I need to do this in a simulation "plenty of times O(10^6)".

A: 

you are describing a set of constraints.

what you need to do is for every constraint check if they are still satisfied, and if not calc the most efficient way to get it correct again.

for instance, in case of length b-c=r if b-c is not r anymore, make it r again by moving both b and c to or from eachother so that the constraint is met again.

for every constraint one by one do this. Then repeat a few times until the system has stabilized again (e.g. all constraints are met).

that's it

Toad
I think in his specific case the solution is entirely solvable from the parameters given; there are certainly sets of (r,a1,a2,t) that aren't valid, though. But either way you shouldn't have to iterate.
Mikeb
no he is describing a 'physics simulation' where some of the points are moved (by the simulation)... He then needs, given the new situation to make sure everything is back as it should. This is done with the approach I described. But maybe I misunderstood the intention of the 'helpseeker'
Toad
Yes, I need a way to do this without iterations. I am looking for a way to do this. I have a hunch about using a bunch of rotations but I'm not sure about how the angle change can be effected.
floatingpoint
+1  A: 

I think the best way to approach this problem would be to think in terms of analytic geometry. Each point A,B,C,D has some 3D coordinates (x,y,z) and you have some relationships between them (e.g. distance B-C is equal to r means that

r = sqrt[ (x_b - x_c)^2 + (y_b - y_c)^2 + (z_b - z_c)^2 ]

Once you define such relations it remains to solve the resulting system of equations for the unknown values of coordinates of the points you need to determine.

This is a general approach, if you describe the problem better (maybe a picture?) it might be easy to find some efficient ways of solving such systems because of some special properties your problem has.

Krystian
Thanks, the general approach is known to me too but a method that's iterative will not do. I need to this in a simulation probably millions of times, so a method that can take me from state1 to state2 is needed.
floatingpoint
+1  A: 

You haven't mentioned the coordinate system. Even if (r, a1, a2, t) don't change, the "coordinates" will change if the whole structure can be sent whirling off into space. So I'll make some assumptions:

Put B at the origin, C on the positive X axis and A in the XY plane with y&gt0. If you don't know the distance AB, calculate it from the old coordinates. Likewise CD.

A: (-AB cos(a1), AB sin(a1), 0)
B: (0, 0, 0)
C: (r, 0, 0)
D: (r + CD cos(a2), CD sin(a2) cos(t), CD sin(a2) sin(t))

(Just watch out for sign conventions in the angles.)

Beta
I'm sorry I assumed that people will imagine the a Global Frame of Cartesian coordinates and yes you are right that even if the ordered quadruplet doesn't change, the 4 points can be sent whirling off. However, the question is how to assign the new coordinates (x,y,z) for the points once the ordered set changes to a known value.
floatingpoint
Umm... isn't that what I just gave you?
Beta
+1: Looks like you gave the OP the answer to me...
tom10
Hi Beta, you certainly gave an answer and I'm thankful for that, but I'm not sure how to use it. In the general situation where I cannot define the Coordinate system this way for each such transformation how would I proceed? Think of it as 5 such changes done one after the other on 5 sets of points and defining the location and orientation of the set (i+1) with respect to the previous set (i). These sets of points are all in the same Cartesian system. If you can point me to the source of that formula, I'll be grateful. Thanks.
floatingpoint
You cannot determine the new coordinates without choosing a coordinate system. The parameters you give are not enough to describe the movement of the object. Here, try this: I have a point at (0,0,0), then it moves, what are its coordinates?
Beta
A: 

You are asking for a solution to a nonlinear system of equations. For the mathematically inclined, I will write out the constraint equations:

Suppose you have positions of points A,B,C,D. We define vectors AB=A-B, etc., and furthermore, we use the notation nAB to denote the normalized vector AB/|AB|. With this notation, we have:

AB.AB = fixed
CD.CD = fixed
CB.CB = r*r
nAB.nCB = cos(ang1)
nDC.nBC = cos(ang2)
Let E = D - DC.(nCB x nAB) // projection of D onto plane defined by ABC
nEC.nDC = cos(tors1)
nEC x nDC = sin(tors1) // not sure if your torsion angle is signed (if not, delete this)

where the dot (.) denotes dot product, and cross (x) denotes cross product. Each point is defined by 3 coordinates, so there are 12 unknowns, and 6 constraint equations, leaving 6 degrees of freedom that are unconstrained. These are the 6 gauge DOFs from the translational and rotational invariance of the space.

Assuming you have old point positions A', B', C', and D', and you want to find a new solution which is "closest" (in a sense I defined) to those old positions, then you are solving an optimization problem:

minimize: AA'.AA' + BB'.BB' + CC'.CC' + DD'.DD'
subject to the 4-5 constraints above.

This optimization problem has no nice properties so you will want to use something like Conjugate Gradient descent to find a locally optimal solution with the starting guess being the old point positions. That is an iterative solution, which you said is unacceptable, but there is no direct solution unless you clarify your problem.

If this sounds good to you, I can elaborate on the nitty gritty of performing the numerical optimization.

Victor Liu
A: 

This is a different solution than the one I gave already. Here I assume that the positions of A and B are not allowed to change (i.e. positions of A and B are constants), similar to Beta's solution. Note that there are still an infinite number of solutions, since we can rotate the structure around the axis defined by A-B and all your constraints are still satisfied.

Let the coordinates of A be A[0], A[1] and A[2], and similarly for B. You want explicit equations for C and D, as you mentioned in the response to Beta's solution, so here they are:

First find the position of C. As mentioned before, there are an infinite number of possibilities, so I will pick a good one for you.

Vector AB = A-B
Normalize(AB)

int best_i = 0;
for i = 1 to 2
    if AB[i] < AB[best_i]
       best_i = i
// best_i contains dimension in which AB is smallest

Vector N = Cross(AB, unit_vec[best_i]) // A good normal vector to AB
Normalize(N)

Vector T = Cross(N, AB) // AB, N, and T form an orthonormal frame
Normalize(T) // redundant, but just in case

C = B + r*AB*cos(ang1) + r*N*sin(ang1)

// Assume s is the known, fixed distance between C and D
// Update the frame
Vector BC = B-C, Normalize(BC)
N = Cross(BC, T), Normalize(N)

D = C + s*cos(tors1)*BC*cos(ang2) + s*cos(tors1)*N*sin(ang1) +/- s*sin(tors1)*T

That last plus or minus depends on how you define the orthonormal frame. Try one and see if it's what you want, otherwise it's the other sign. The notation above is pretty informal, but it gives a definite recipe for how to generate C and D from A, B, and your parameters. It also chooses a good C (which depends on a good, nondegenerate N). unit_vec[i] refers to the vector of all zeros, except for a 1 at index i. As usual, I have not tested the pseudocode above :)

Victor Liu