How to get a 3D point on a plane (which is represented as normal and offset from origin)? - game-engine

I know how to get the intersection point between a ray and a plane, if I know the ray and
a point on the plane, and the plane normal.
In the code I use the plane is represented as signed offset from origin, and normal, and I
need to get some, any point on the plane. How to do this?
So, the plane equation: Ax + By + Cz + D = 0, and I know A,B and C, that is basically
the normal of the plane and I know D, which is the signed distance from the origin. And
my question is, given that how do I get some 3D point on the plane?
Thanks

If (A, B, C) are normalized vector, the point on the plane closest to original is simply:
(-AD, -BD, -CD)
This can be easily known from your description that (A, B, C) is the plane normal, and D is the distance between the plane and origin.
This method is simple and do not need any branching.
Point on plane closest to origin

You get one plane point by intersecting plane with a ray (line) :-)
Choose some point P=(x,y,z), calculate w=Ax+By+Cz.
If w=-D than P is on the plane.
For w!=-D, choose some direction Q=(dx,dy,dz) for which l=Adx+Bdy+Cdz!=0, e.g. q=(A,0,0), if B!=0 or C!=0. Than point P+l*Q/w is on the plane.

Related

Calculate angle on a plane in 3D space from a 2D image

I have 2 input images of a plane where the (static) camera is at an unknown angle. I managed to extract edges and points of interests using opencv. But I'm stuck calculating real angles from the images.
From image #1 I need to calculate the camera angle relative to the plane. I know 3 points on the plane that form a equilateral triangle (angles of 60 degree). The center point of the triangle is also the centerpoint of the plane. However the plane center point on the image is covered by another object.
From image #2 I need to calculate the real angle of an object (Point C) on the plane to one of the 3 points and the plane center point (= line A to B).
How can I calculate the real angle β as if the camera had no angle towards the plane?
Update:
I was looking for a solution for my problem at https://docs.opencv.org/3.4/d9/d0c/group__calib3d.html
There is a number of functions but I couldn't figure out how to apply them to my specific problem.
There is a function to calculate Homography using two images with keypoints but I do not have images of the scene from different camera angles.
Then there is cv::findHomography which Finds a perspective transformation between two planes. I know 4 source points but what are my 4 destination points?
Another one I was looking at is cv::solvePnP and cv::solvePnPRansac but again I only know 4 source points on the plane. I don't know about their 3D correspondence point.
What am I missing?
#Micka: Thanks for your input. I have 4 points for processing the image (the 3 static base points + the object at point C). I can assume these points are all located on the plane at z=0. However I do not have coordinates for a second plane neither the (x,y) of the corresponding 3D points.
Your description does not explicitly say it, but if you can assume that segment AB bisects the base of the triangle, then you have 4 point correspondences between the plane and its image, so you can use cv::findHomography.

How to convert relative GPS coordinates to a "local custom" x, y, z coordinate?

Let's say I know two persons are standing at GPS location A and B. A is looking at B.
I would like to know B's (x, y, z) coordinates based on A, where the +y axis is the direction to B (since A is looking at B), +z is the vertically to the sky. (therefore +x is right-hand side of A)
I know how to convert a GPS coordinate to UTM, but in this case, a coordinate system rotation and translation seem needed. I am going to come up with a calculation, but before that, will there be some codes to look at?
I think this must be handled by many applications, but I could not find so far.
Convert booth points to 3D Cartesian
GPS suggest WGS84 so see How to convert a spherical velocity coordinates into cartesian
Construct transform matrix with your desired axises
see Understanding 4x4 homogenous transform matrices. So you need 3 perpendicular unit vectors. The Y is view direction so
Y = normalize(B-A);
one of the axises will be most likely up vector so you can use approximation
Z = normalize(A);
and as origin you can use point A directly. Now just exploit cross product to create X perpendicular to both and make also Y perpendicular to X and Z (so up stays up). For more info see Representing Points on a Circular Radar Math approach
Transfrom B to B' by that matrix
Again in the QA linked in #1 is how to do it. It is simple matrix/vector multiplication.

Determine tangent based on initial tangent and curvature

I'm having the following scenario :
2 points, A and B are on a circle
curvature of the circle, c (and hence its radius = 1/c) is known
the tangent to the circle at point A, mA is known.
the direct distance from A to B, dAB is known
the arc distance dAB_arc is known
the sector angle between A and B, theta is known
I'm trying to deduct the tangent at point B, mB. Could anyone please help out ?
Thanks in advance.
If mA is slope of tangent (angular coefficient k in equation like y=kx+b), then
mB = tg(arctg(ma)+theta) = (mA + tg(theta))/(1-mA*tg(theta))

How to calculate the quaternion that represents a triangle's 3D rotation?

Or to look at it another way, let's say we have 2 same size triangles located and orientated at different parts of 3D space. How do you calculate the quaternion that describes the rotation such that applying the quaternion to triangle A would have it sit at triangle B? It is difficult to see how finding the normal of A and B and calculating the quaternion from this would work because the normal vector does not contain information about rotation (or rather, it assumes the standard base frame for the normals of both triangles thus throwing away valuable information). It seems you would need to find the vectors from each triangles (a, b, c) to the others (a, b, c) and somehow construct a quaternion out of this. Way beyond me, and could any mathematicians please dumb it down.
First orient the normal vectors then the plane.
Source=(s1,s2,s3)
Target=(t1,t2,t3)
NormSource = (s1 - s2)cross(s1 - s3)
NormTarget = (t1 - t2)cross(t1 - t3)
Quat1 = getRotationTo (NormSource,NormTarget)
Quat2 = getRotationTo ( Quat1 * (s1 - s2),(t1 - t2) );
QuatFinal = Quat2 * Quat1

Reflecting a circle off another circle

Working with iPhone and Objective C.
I am working on a game and I need to correctly reflect a ball off a circle object. I am trying to do it as a line and circle intersection. I have my ball position outside the circle and I have the new ball position that would be inside the circle at the next draw update. I know the intersect point of the line (ball path) and the circle. Now I want to rotate the ending point of the ball path about the intersection point to get the correct angle of reflection off the tangent.
The following are known:
ball current x,y
ball end x,y
ball radius
circle center x,y
circle radius
intersection point of ball path and circle x and y
I know I need to find the angle of incidence between the tangent line and the incoming ball path which will also equal my angle of reflection. I think once I know those two angles I can subtract them from 180 to get my rotation angle then rotate my end point about the angle of intersection by that amount. I just don't know how.
First, you should note that the center of the ball doesn't have to be inside of the circle to indicate that there's a reflection or bounce. As long as the distance between ball center and circle is less than the radius of the ball, there will be a bounce.
If the radius of the circle is R and the radius of the ball is r, things are simplified if you convert to the case where the circle has radius R+r and the ball has radius 0. For the purposes of collision detection and reflection/bouncing, this is equivalent.
If you have the point of intersection between the (enlarged) circle and the ball's path, you can easily compute the normal N to the circle at that point (it is the unit vector in the direction from the center of the circle to the collision point).
For an incoming vector V the reflected vector is V-2(N⋅V) N, where (N⋅V) is the dot product. For this problem, the incoming vector V is the vector from the intersection point to the point inside the circle.
As for the reflection formula given above, it is relatively easy to derive using vector math, but you can also Google search terms like "calculate reflection vector". The signs in the formula will vary with the assumed directions of V and N. Mathworld has a derivation although, as noted, the signs are different.
I only know the solution to the geometry part.
Let:
r1 => Radius of ball
r2 => Radius of circle
You can calculate the distance between the two circles by using Pythagoras theorem.
If the distance is less than the r1+r2 then do the collision.
For the collision,I would refer you Here. It's in python but I think it should give you an idea of what to do. Hopefully, even implement it in Objective C. The Tutorial By PeterCollingRidge.