Finding the intersection of 2 ray normals - geometry

I have 2 rays, defined by a common point and a direction vector and I want to find the point at which the normals of the 2 rays intersect at a given distance along the normals and the distance along the rays these normals start at.
So in this system, A is the common point of the two rays, B and C are the direction vectors, and D and E are the length of the normal vectors.
I want to find the three ? points.

Here's my idea
First, define a line that is parallel to the existing line, that is, through A oriented along vector B, but is offset by vector E.
Define a second line that is parallel to the existing line, that is, through A oriented alone vector C, but is offset by vector D.
Find the intersection of these two new lines, this should give you the topmost ? you are looking for.

Related

Finding the Dimension of OBJ objects

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.

Calculate minimum distance between two lines and two arc

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

Find angles of polygon using only known distances

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.

Having objects trajectories and directions. How to find where objects traverse same path?

I have N objects that travel on some trajectories inside some box. (unique for each object). At each agent curve point we can get object speed (direction). Having some distance creteria d how to find where more than one curve go in same direction cloze to each other with distance <= d. How to find such curves? (question is aboun M dimesional space, each point of each given trajectory can participate only in one such curve at a time, given trajectories do intersect)
alike having black object trajectory curves we find red curve that with some d follows most curves direction:

Given 2 points how do I draw a line at a right angle to the line formed by the two points?

Idealy I want to supply a sequence of points and have a line drawn at a right angle at every point (starting at the second point).
The direction of each line would alternate, so if I happened to draw a curve cosisting of 6 points, a line of a given lenth would be drawn for each point starting with the second point, i.e 5 additional lines on alternating sides of the curve, a bit like a caterpillar with alternating legs.
(I understand that the lines won't be entirely at right angles to the curve but rather at right angle to the line formed by any two points on the curve).
It's a question of vector mathematics. You can calculate the directing vector between two points A and B by subtracting A from B. In 2D and only in 2D the vector right angled to this vector can be obtained by reversing x and y component and taking one component negative. If you negate the new x component you'll make a left turn, by negating y you'll make a right turn. You can then reduce the directing vector to unit size (= of length 1) by dividing each component by the length of the vector (sqrt(xx + yy)). Finally you can stretch the unit vector again by your desired length and have one of the size you want. If you add this vector to either A or B you'll get a point to which you want to draw your line.
Here's a little math help:
These are points A and B expressed as vector.
The directing vector is calculated by a simple subtraction.
The normal vector is given by flipping the directing vector, that is to reverse the components and make one component negative. nl = normal, flipped to the left, nr = normal, flipped to the right
The unit vector of the normal vector is given by dividing each component by the length of the vector.
Calculates the length of a vector
If you want to draw a line from B to the left (when coming from A) you calculate the point P to draw the line to as
So you want to alternate that one time you draw to the left and one time to the right when iterating over the points.
If you have points lying outside your canvas, then you length is probably too large. You can of course calculate the point at which the vector to P would cross the boundary by calculating the intersection point of the vector BP and the border.

Resources