Numpy Line-Plane intersection - numpy

I have two planes in 3D space as shown below.
Point "e" on plane2 represents the intersection of the line which passes from point "P" of plane1 and has the direction vector of "S". Let P be the edge of plane 1.
Which are the "e" point coordinates (xe,ye, 0) with respect to the coordinates system of the plane it belongs (plane2), using Numpy?
I have the following data available:
Coordinates of the centers of each plane with respect of the global coordinate system "C".
x = np.array([x1, x2])
y = np.array([y1, y2])
z = np.array([z1, z2])
Sun direction vector S = np.array([Sz, Sx, Sy])
Point "P" location with respect to the coordinate system of plane1: P(xp,yp,0)
Each plane has the same width and length dimensions: Hw, Hl
Unit vectors normal to the plane surfaces
n = np.array([[n1z, n1x, n1y], [n2z, n2x, n2y]])
Also the azimuthial and elevation angles for both planes with respect to the global coordinate system "c" are known:
alphaH = np.array([alphaH1, alphaH2])
aH = np.array([aH1, aH2])

You have the position vector for c2 and the position vector for e in the global coordinate system then all you need to do is calculate c2-e and this will give you the position vector of e relative to c2.

Related

Vulkan calculation of Barycentric coordinates? Is area function 2D or 3D?

In section 25.8.1 Basic Polygon Rasterization of the Vulkan spec it says:
Barycentric coordinates are a set of three numbers, a, b, and c, each in the range [0,1], with a + b + c
= 1. These coordinates uniquely specify any point p within the triangle or on the triangle’s
boundary as
p = a * p_a + b * p_b + c * p_c
where p_a , p_b , and p_c are the vertices of the triangle. a, b, and c are determined by:
a = A(p, p_b, p_c) / A(p_a, p_b, p_c)
b = A(p, p_a, p_c) / A(p_a, p_b, p_c)
c = A(p, p_a, p_b) / A(p_a, p_b, p_c)
where A(l,m,n) denotes the area in framebuffer coordinates of the triangle with vertices l, m, and n.
Framebuffer coordinates technically have three components. This is specified in 24.5 Controlling the Viewport as:
The vertex’s framebuffer coordinates (x_f , y_f , z_f ) are given by [snip]
What precisely is the formula of the A function?
Is it either:
(a) the same as the formula given to calculate whether the triangle is back-facing or front-facing in 25.8.1, namely:
a = -0.5 * sum_i(x_f[i] * y_f[i+1] - x_f[i+1] * y_f[i])
That is, is it taken as read that the forumla of A does not use the z_f components of its arguments, and is purely a function of the (x_f, y_f) components? (ie It is calculating the area of the two dimensional projection of the triangle onto the x-y plane in framebuffer-space)
or (b), does A use all three framebuffer components? ie Does A return the area of the triangle in the full three-dimensional framebuffer-space (like shown here for example)
or (c) something else?
It actually doesn't matter, mathematically speaking. Whichever function you pick, you'll find that the particulars of the math divide out when computing the barycentric coordinate.
A barycentric coordinate is computed by taking the ratio of two areas. If you linearly project two co-planar triangles from 3D space to 2D space with the same projection, the ratio of their areas is unchanged (assuming that they have an area post-projection).

Rotation of a unit vector at a random point iby an angle along Y axis in 3D space

I had attached also the schematic to depict my question.
I need to rotate the vector V with the base point P by an angle and find the new vector V'.
The rotation axis is say for is about a local y axis at point P (which is parallel to global Y axis)
Subsequently, I need to rotate the initial vector V about x axis which is parallel to global Y axis.
The main reason for the rotation is to find the new vector V' at point P. Both the rotations are independent and each of the rotation provides a new V'. I'm programming this in VB.net and output is a double() of new vector V'.
Just apply the two rotations independently (see Wikipedia). The base point does not play any role in this because it is just a constant offset that never changes. If I got your description right, you want the following:
//rotation about y-axis
iAfterRot1 = cos(phi1) * i + sin(phi1) * k
jAfterRot1 = j
kAfterRot1 = -sin(phi1) * i + cos(phi) * k
//rotation about x-axis
iAfterRot2 = iAfterRot1
jAfterRot2 = cos(phi2) * jAfterRot1 - sin(phi2) * kAfterRot1
kAfterRot2 = sin(phi2) * jAfterRot1 + cos(phi2) * kAfterRot1

Co-ordinates of point on circle with minimum cos/sin

A vehicle currently at a point U = (ux, uy) is moving counter-clockwise along a circle of radius R with speed s and direction d (i.e. tangent to the circle makes an angle d with the X-axis.) What position V = (vx, vy) will it be at in time t?
The center of the circle is not specified.
The way I see it, after time t it will travel st or an angle of st/R along the circle. But I am lost trying to compute V from this info.
I can first find the center C of the circle based on (ux, uy), R and d. And then find where vector CV points, and hence V. But that's a whole lot of cosines and sines. I am constrained by CPU, so maybe one sine/cos/tan is acceptable or one or two squares/square roots are acceptable.
This calls for a diagram, but alas I lack the skill.
I assume that the radius speed and time interval are such that the vehicle will not travel more than halfway round the circle in the time available.
Let V be the point the vehicle will be at t seconds after it is at U. Let the centre of the circle (whose coordinates will not be needed) be O. Then the length of the arc from U to V is
A = s*t
and so the angle subtended at O is
a = A/R radians.
The direction from U to V will be the same as the direction of the tangent to the circle at a point midway between U and V, ie
e = d + a/2
The distance from U to V is the length of the chord from U to V. The midpoint of the chord is the vertex of two congruent right angled triangles whose hypoteneuses have length R, and the angle at O is a/2. Therefor the length of the chord is
C = 2*R*sin( a/2)
Finally
V = U + C*(cos(e), sin(e))
You may also want the direction of the tangent at V. This is d+a.
Note that if you store the direction d as a unit vector rather than an angle you can save some sin & cos calls as the direction of the chord is then the direction d rotated through a/2, and the direction at V is d rotated through a.

Kinect depth conversion from mm to pixels

Does anybody knows how many pixels correspond for each millimeter of depth value in images taken from kinect for xbox360?
I'm using the standard resolution and settings...
Thanks!
1 pixel corresponds to a number of millimiters that depends on the depth value of that pixels (i.e. its level of gray).
The simplest way you can get the distance between two pixels in a depth image is to convert those pixels (which are expressed in Depth Space) in real world coordinates (i.e. in Skeleton Space)1. Then, you can calculate the distance between those points using a common euclidean distance formula.
So if you have two pixels P1 and P2, with depth values
respectively equal to D1 and D2, you can proceed as follows:
DepthImagePoint dip1 = new DepthImagePoint();
dip1.X = P1.x;
dip1.Y = P1.y;
dip1.Depth = D1;
DepthImagePoint dip2 = new DepthImagePoint();
dip2.X = P2.x;
dip2.Y = P2.y;
dip2.Depth = D2;
SkeletonPoint sp1 = CoordinateMapper.MapDepthPointToSkeletonPoint(DepthImageFormat.Resolution640x480Fps30, dip1);
SkeletonPoint sp2 = CoordinateMapper.MapDepthPointToSkeletonPoint(DepthImageFormat.Resolution640x480Fps30, dip2);
double dist = euclideanDistance(sp1, sp2);
1 See Coordinate Spaces for more information.

finding a minimum distance

I need to find a point or points on the given circle (or curve) which minimizes d0+d1? the radius and center of the curve are (0,0) and 'r' respectively and the coordinates of points A and B are known. Let say A=(x1,y1) and B=(x1,-y1) and r> sqrt(x1^2+y1^2) . C is unknown point of the circle which should minimize the length d0+d1
d0 - the distance between A to C on the circle
d1- the distance between B to C on the circle
point C moves along the circle. I need to find a point or points on the given circle (or curve) which minimizes d0+d1?
If the line AB intersects the circle, then C is that intersection point (note that there can be two intersection points and both give an equal distance d0+d1 !).
If AB does not intersect the circle, then C is the point on the circle intersecting an imaginary line from the point on the line AB closest to the circle center.
There are many articles online about how to find the point on a line closest to another point, and how to find the intersection between two lines, which would solve the second case. For the first case you can google "line circle intersection"
The general case is very complicated, but the special situation
A=(x1,y1) and B=(x1,-y1) and r > sqrt(x1^2+y1^2)
with a circle whose centre is the origin has enough symmetries to make the solution at least in some circumstances accessible. I'm assuming A ≠ B, (equivalently y1 ≠ 0), otherwise the problem is trivial for a circle.
Let dist(P,Q) be the Euclidean distance between the points P and Q. The (closed) line segment connecting A and B is the locus of points P with
dist(P,A) + dist(P,B) = dist(A,B)
For D > dist(A,B), the locus of points with
f(P) = dist(P,A) + dist(P,B) = D
is an ellipse E(D) whose foci are A and B. Let P be a point on the circle and D = f(P).
If the tangents to the circle and to the ellipse E(D) in the point P don't coincide, P is neither a local minimum nor a local maximum of f restricted to the circle.
If the tangents coincide, and the curvature of the circle is larger than the curvature of E(D) in P, then P is an isolated local maximum of f restricted to the circle.
If the tangents coincide, and the curvature of the circle is smaller than the curvature of E(D) in P, then P is an isolated local minimum of f restricted to the circle.
If the tangents coincide and the curvature of the circle is equal to the curvature of E(D) in P, then
P is an isolated local minimum of f restricted to the circle if dist(P,A) = dist(P,B),
P is neither a local maximum nor a local minimum of f restricted to the circle otherwise.
First, if x1 = 0, it is easily seen (in case it is not geometrically obvious) that the points on the circle minimising f are the points with x-coordinate 0, i.e. P1 = (0,r) and P2 = (0,-r). [That would even be true if r² ≤ x1² + y1².]
Now, suppose x1 ≠ 0, without loss of generality x1 > 0. Then it is obvious that a point P = (x,y) on the circle minimising f must have x > x1. By the symmetry of the situation, the point R = (r,0) must either be a local minimum or a local maximum of f restricted to the circle.
Computing the behaviour of f near R, one finds that R is a local minimum if and only if
r ≥ (x1² + y1²) / x1
Since R is a point of smallest curvature of E(f(R)) (and the tangents in R to E(f(R)) and the circle coincide), R is then also the global minimum.
If r < (x1² + y1²) / x1, then R is a local maximum of f restricted to the circle. Then f has two global minima on the circle, with the same x-coordinate. Unfortunately, I don't have a nice formula to compute them, so I can't offer a better way than an iterative search.