I have two problem first how to calculate the minimum distance between two lines.
For details I am attaching an image here.
In the image describe the line with start and end point. I already have start and end point for both lines but I am not getting any idea how to calculate the minimum distance between two lines.
Another problem is that how to calculate the minimum distance between two arc.
I am attaching another image here
For arc I have the start, end and center point also I have the start and end angle.
This link has lot more things - Shortest distance between a point and a line segment
I also got help from above link.
This is the another issue what I am facing now. In this scenario how to calculate minimum distance between two arc?
Any idea how solve this two issue?
Let the two segments be AB and CD. Their parametric equations can be written
P = A + u AB, Q = C + v CD, with u, v in [0, 1].
You want to minimize the (squared) distance
PQ² = (CA + u AB - v CD)², under the given constraints,
and you can cancel the first derivatives with
(CA + u AB - v CD).AB = 0
(CA + u AB - v CD).CD = 0
After resolution of the 2x2 system you get a pair (u, v). If both variables fall in [0,1], there is an intersection and the distance is 0.
Otherwise, clamp u and/or v to the relevant bound of range [0, 1] and compute the corresponding distance.
If one variable was clamped, the distance was between an endpoint and a segment; if two were clamped, it's between two endpoints.
A similar approach can be adopted for the arcs (using trigonometric functions), and lead to an optimization problem under linear constraints. Less easy to handle as the objective function is non-linear, though.
We can also proceed as follows:
find the points that make the shortest distance between the whole circles. There are two cases:
the circles intersect, at two places
the circles do not intersect; the shortest distance is between the intersection points of the two circles and the center line.
then check if these points do belong to the arcs by angle comparison. If yes, you are done (the distance is either 0 or the distance between the intersections).
otherwise, consider the endpoints of an arc against the other circle. The closest point is the intersection of the circle with the line through the point and the center. If the intersection belongs to the arc, keep the distance between the point and the intersection. Repeat this for all four combinations endpoint/arc and keep the closest pair.
If no valid pair was found, keep the shortest endpoint/endpoint distance.
The picture shows the distances that can be considered. In green, endpoint/circle; in red, endpoint/endpoint. In this case, the circle/circle distance is zero as they intersect. A distance can be considered if it joins two points inside the arcs.
Distance between two intersecting lines is 0
Otherwise, what you want is to calculate the endpoint of one of the line to the other one.
If you want to calculate the distance between a point and a line :
It is the length of the line segment which joins the point to the line and is perpendicular to the line.
For arcs I think arcs are part of circles, distance between them is the distance between their center points and minus their radiuses.
Probably you can find more here: Calculate the minimum distance between two given circular arcs
Example
Related
How to place n points in a plane so that the distance between every two points is unique and at the same time we could choose one of them that is the closest for all others n-1 points.
I tried to draw it. But I was able to draw it only for max n=5. I drew two perpendicular lines. One point I was intersection of the lines and the others points lie on the line so that they formed a quadrilateral and point I was inside. With more points it seems impossible to me but I can't prove why
I have 5 {x,y} points randomly placed on a grid
Each of the points do not know the {x,y} coordinates of the other points
Each of the points do know the distance of each of the other points from their {x,y} position
Each of the points exchanges this distance information with every other point
So every point knows every distance of every other point
Using this distance information every point can calculate (by finding the angles) triangles for every other point using itself as a reference point
Example, point 1 can calculate the following triangles:
1-2-3,
1-2-4,
1-2-5,
1-3-4,
1-3-5,
1-4-5,
and using the distance data recieved from the other points it can also calculate
2-3-4,
2-3-5,
2-4-5,
3-4-5
I would like to build a map of the location of every other point relative to a single point
How should I go about doing this? I am asuming it would be some kind of triangulation algorithm but these mainly seem to compute the location of a point from three other points, not the other way around where the other points {x,y} coordinates are discovered based on only the distance information.
I have tried plotting the two possible triangles for every 3 triangle points and then rotating them on a fixed known point to try and align them, but I think this avenue will end up with too many possibilities and errors
Ultimately I would like every point to end up with {x,y} coordinates of every other point relative to itself
You know the distance from one point to every other, dij. Thus, point 2 lies in a circumference of center point 1 and radius = d12. Point 3 lies in a circumference of center point 1 and R=d13 and it also lies in another circumference of center point 2 and R=d23.
See this picture:
I've set point 2 in X-axis for simplicity.
As you see, point 3 is on the intersection of two cicrcumferences centered at P1 and P2. There is a second intersection, P3a. Let's choose the one that is upwards and continue.
For P4 we can use three circumferences, centered at P1, P2 and P3. Again we get two solutions.
The same process can be done with the rest of points. For Pn you have n-1 circumferences.
I'm sure you can find the maths for circle-circle intersection.
Some remarks must be observed:
1) The construction is simpler if you first sort the points by distance to P1.
2) Not all distances generate a solution. For example, increase d13 an there's no intersection between the two circumferences for P3. Or increase d14 and now the three circumferences don't intersect in just the two expected points 4 and 4a.
3) This fact can be overworked by considering the average of intersections and the distance from each solution to this average. You can set a tolerance in these distances and tell if the average is a solution or else some dij is wrong. Since two solutions are possible, you must consider two averages.
4) The two possible triangulations are symmetric, over X-axis in the case I've drawn.
The real solution is obtained by a rotation around P1. To calculate the angle of rotation you need the {x,y} coordinates of another point.
I am having a Three OBJ file, Cone, Sphere and Cube. How can I find the dimension of these objects, so that I can use it in my collision detection class?
i.e How can I find Radius, Length of Cube and Radius and Height of cone? Or is there any better way for collision detection, I have hundreds of random particle in my game which may or may not collide with these objects.
Length of the cube would be the distance of two consecutive points in one face.
If by radius of a cube you mean its diagonal it would be sqrt{3} of its length.
For a sphere, you can find its center by averaging all the vertices.
Its radius would be the distance between any vertex and the center.
It works fine if the sphere is not high resolution.
Otherwise, you have to solve a system of equations to find the sphere that passes through four points. You can take a look at this:
https://www.quora.com/How-do-you-find-the-center-and-radius-of-a-sphere-given-any-four-arbitrary-points-x_1-y_1-z_1-x_2-y_2-z_2-x_3-y_3-z_3-x_4-y_4-z_4
For the cone: there is probably one vertex that is connected to all other vertices. This vertex is probably easy to find for you. Let's call that p.
Take three vertex other than p. Find the circle passing through those vertices. Call that c. The distance between p and c is the height. The distance between c and any vertex other than p would be the radius. To find the circle passing through three points, you again need to solve a system of equations with three unknowns. As the equation of a circle is (x-a)^2+(y-b)^2=r^2. You need to put the values of your three points in the equation and find a,b, and r. Note that this equation assumes that the circle is in 2D. To use it for 3D, you need to first find the plane passing through these three points. If you do not want to go through all these. you can again average all vertices except p and find the center of the circle. the radius would be the distance between the center and any point. I actually assumed that the circles and spheres in your input are uniformly sampled which is the case for most of the available Obj files for these shapes.
I've got a mesh of points, but simplified I've got 5 points with 2 being primary points.
All distances from A and B to any other points are known ( C, D, E ), but the distance from A and B is not known. Neither are the location of these points, only the distances. Although A can be considered the origin (0,0).
Is it possible to find the internal angles and then consequently the distance between point A and B.
Otherwise how would this scenario need to be modified in order to find this distance.
Or is there simply just not enough information known?
The actual scenario can have more points with distances from points A and B known, but I've just tried to simplify here.
No. Lets fix A at (0,0) and B along the horizontal axis. Each two leg pair ACB, AEB and ADB can flex its elbow joint to allow for any position of B along the horizontal axis.
Given an AB distance then all the angles and points are uniquely defined. But if AB is unknown then the shape can fold on itself.
I have a set of vertices to draw a circle, but I want to draw a high-res circle by drawing twice the number of vertices, I cant just increase the number of vertices what I need is to calculate the mid points from the supplied vertices, if that makes sense
So from that image how can I calculate the points A, B, C, ... given the points V0, V1, V2, ... and the center point of the circle ?
Please note that I cant just calculate the mid-points by rotating the vertices they need to be calculated using their position
Thanks
The center of the circle can be determined by making a perpendicular line to two neighboring "sides", and intersecting them.
If there are an even number of vertices, just pick two which are opposite to each other, and "avarage them" - calculate the midpoint.
Then, you can just rotate all the vertices to either way by 180°/No.vertices around this center, so you get the ones you are looking for. Of course, you should keep the existing ones too.