LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

shortest distance between two line segments

Hi Sir Altenbach,
Thanks for your reply too.

What determines the rotation speed and lenght of each stick at any given time?

>>> the stick has an encoder on it which gives rotational values from 0-360 degress, and a potentiometer (0-90 deg)which determines the length of each stick.

What is the program allowed to do to prevent collision (change speed/direction, change radius, stop everything)

>>>for instance if their distance is about 6 meters from each other i can change their speed from high speed to low speed and when it is on the minimum allowed distance possible, say 3 meters, both of them will stop and the only possible movement is go the other way.

Since you want to prevent collision, you need a predictive algorithm. Once they overlap, the collision has already happened. Too late!

>>>yes. that is what i am trying to find.

What information does your algorithm get (e.g. r1, r2, theta1, theta2, delta-thetat1, delta-theta2, etc.), i.e. does the program only get static information and need  to construct the trajectory from sequential history data or does it get dynamic information about speed and direction?

>>>i do get dynamic data, i have the following data; coordinates of stick one at both ends, coordinates of stick two at both ends, Radius of each stick

0 Kudos
Message 11 of 19
(2,040 Views)

Hello

I made an example VI to show what i wanted to do. But i am still stuck to the same problem of getting the nearest distance between the two lines. Kindly see the attached Vi`s.

If you run the VI, and play on the inclinometer and encoder control i will know if the two circle will have a chance to collide if the LED lits. But i still cant find out how can i get the distance between the two stick so that i can create a preventive measure before they will collide.

Thanks for any advise.

Download All
0 Kudos
Message 12 of 19
(2,018 Views)

Hi jtc,

why do you think this don´t work? If you only need the distance, please try the attached example.

Hope it helps.
Mike

0 Kudos
Message 13 of 19
(2,012 Views)

Hi jtc,

which distance do you mean?

Mike

0 Kudos
Message 14 of 19
(2,008 Views)
Thanks for your reply Mike,
In your VI it will calculate for the distance whenever i moved the inclinometer. But if i move the encoder it will not change the distance value hence the two stick collides.
0 Kudos
Message 15 of 19
(2,007 Views)

Hi jtc,

that´s right. So you need the distance between the other two points? Please see my previous post.

Mike

0 Kudos
Message 16 of 19
(2,000 Views)

Hi jtc,

is this what you want?

Mike

0 Kudos
Message 17 of 19
(1,982 Views)
jtc,

I think you can do all the calculations for all possible cases with fairly simple algebra.

First, note that all possible collisions involve one end of one stick hitting the side or end of the other stick.

If D is the distance between the fixed endpoints, then consider the following cases:

1. If R1 + R2 < D, no collision is possible. This it the trivial case which Altenbach pointed out previously.
2. If R1 + R2 > D and R1 < D and R2 < D, then collisions of the free ends with the side of the other stick are possible.
3. If R1 > D, then stick 1 can collide with either end of stick 2.
4. If R2 > D, then stick 2 can collide with either end of stick 1.

Some additional combinations are possible, such as cases 3 and 4 both being true.

To check for impending collisions:
1. Check case 1.
2. If a collision is possible, perform the following calculation for each endpoint which could be involved in a collision (results of Cases 2, 3, 4):
A. Generate equation of line for the other stick (the one which will be hit by the endpoint of the other). Use the two-point formula (since you said you could calculate the coordinates of the free endpoint of the stick).
B. Generate the equation of a circle of radius Rc centered on the endpoint to be checked. Rc is the collision avoidance radius.
C. Substitute Equation (A) into Equation (B). Check the resulting quadratic equation in x for solution type (b^2 - 4*a*c >0?, =0?, <0?):
i. Solutions are complex: No collision.
ii. Distinct real solutions: Two possible collision points.
iii. One real solution: One collision point: The stick ends will touch when aligned.
D. Since the equation applies to an infinite line, if C.ii. is found, additional calculation may be necessary to confirm whether an actual collision can occur or whether the intersection of the equations is beyond the end of the stick.
E. Repeat A, B, C, D for each possible collision combination identified by Cases 2, 3, 4.

Note that all the equations can be solved analytically so that only the numerical calculations (adds and multiplies) need be performed while running.

Lynn
0 Kudos
Message 18 of 19
(1,959 Views)

Hello Mike and Lynn,

Thank you for all your reply and sample VI. Please give me a little time to study your suggestions and will get back to you shortly.

Thanks a lot.

jtc

0 Kudos
Message 19 of 19
(1,943 Views)