Triangle Point Picking in 3D - random

To take random uniform points inside a triangle Triangle Point Picking method is used. But this is for 2D points, how can I take random points from a triangle that is defined by 3 arbitrary 3D points?
In other words, let's say I have 3 points in 3D space, and these points define a plane, how can I take random points on the plane such that my points are uniformly sampled inside the triangle that is defined by these 3 points?
Thanks in advance..

I asked the same question on math.stackexchange.com and it is answered. Here is the link.

Related

Arranging corner points of a hexahedron by coordinates

I have a list of 8 points given by their coordinates (x, y, z).
These 8 points are the 8 vertices of an hexahedron, which means that there are 6 faces which are quadrilaterals; the 4 points on each face are guaranteed to be coplanar.
I want to sort the list of points in a particular order:
the first 4 points must be on the same face, and in counterclockwise order;
the next 4 points must be their corresponding points on the opposite face.
Example:
I found similar question asked, but this algorithm fails on this example hexahedron:
I also have an idea to sort points in direct way by finding points in the same plane, then the other point in this plane, then point on same edge and etc.
But is there any easier way to order these points?

What algorithm's can be used to fill an irregular 3D object?

I have an irregular polygon in 3D, and have coordinates of points present on the boundary of the polygon. Assume that I have placed cubes of some size on all such points present on the boundary. With the help of these cubes I can search for all 3D objects which intersect with my polygon. Now in order search for all objects which are either inside or outside my polygon I need to populate the 3D polygon with such cubes.
Can anyone help on how can I fill in my 3D polygon with all such cubes.
You dont need to fill the polyhedron (this is the name of a 3d polygon), instead you could calculate its hull, which might be a Convex Hull or concave hull depending on your intent.

Reconstruct 3d points from point spacing

I have a set of e.g. 8 points. I know all distances between each points. Is there an algorithm to reconstruct the 3d coordinates of those points.
What you are try to do is called Trilateration. It might be wise to do a bit of research before you proceed, as it's tricky to get right. However, I'll start you off with the following.
The following should work, as long as you have the actual 3D distances. Problems may come up if you don't.
Take a point, p1, and assign it to be the origin, (0,0,0).
Take another point, p2, and place it at (distance(p1,p2),0,0)
Take another point, p3, and place it on the (x,y,0) plane based on it's distance from p1 and p2.
Take another point, p4, and place in 3D space, based on it's distance from p1, p2, p3.
Repeat step 4 until no points remain.
The first 3 steps are enough to orient and fix the coordinates.
Solving steps 3 and 4 can be done by making use of planar triangles, that form easily due to how the points are centered.
Let assume that points are in a general position. That no 3 points are on a same line, and no 4 points are on a same plane. It isn't a restriction, just to make algorithm simpler without checks for a special cases.
Intersection, if exists, of four spheres (in a general position) is a single point. It can be seen since intersection of two spheres is a circle, intersection of three spheres are 2 points, and if center of forth sphere isn't on a plane with centers of other 3 spheres, that sphere can pass only through one of intersection points.
So, if distances are valid, than shape can be created by incremental adding points to it.
Position on first 4 points defines orientation. E.g. first point set in origin, second point set on +X on given distance to first, third point set in XY plane in +Y direction on intersection of circles, and forth point set in +Z direction on intersection of 3 spheres.
Additional points can be positioned by intersection of 4 spheres with centers in first 4 points and radii given by distances to them.
An other possibility is the metric Multidimensionale Skalierung.

Camera homography

I am learning camera matrix stuff. I already known that I can get the homography of the camera (3*3 matrix) by using four points in a plane in object space. I want to know if we can get the homagraphy with four points not in a plane? If yes, how can I get the matrix? What formulas should I look at?
I also confused homography with another concept: I only need to know three points if I want to convert from points from one coordinate to another coordinate system. So why we need four points in computing homography?
Homography maps points
1. On plane to points at another plane
2. Projections of points in 3D (no obligatory lying on the same plane) during a pure camera rotation or zoom.
The latter can be easily verified if you look at the rays that connect points while sensor plane rotates: green are two sensor positions and black is a 3d object
Since Homography is between projections and not between objects in 3D you don’t care what these projections represent. But this can be confusing, I agree. For example you can point your camera at 3D scene (that is not flat!), then rotate your camera and the two resulting pictures of the scene will be related by homography. This is, by the way, a foundation for image panoramas.
Three point correspondences you mentioned may be reladte to a transformation called Affine (happens during large zooms when a perspective effects disappears) or to the finding a rigid rotation and translation in 3D space. Both require 3 point correspondences but the former needs only 2D points while the latter needs 3D points. The latter case has 6DOF ( 3 for rotation and 3 for translation) while each correspondence provides 2DOF, hence 6/2=3 correspondences. Homography has 8 DOF so there should be 8/2=4 correspondences;
Below is a little diagram that explains the difference between affine and homographs transformation when the original square tilts forward. In affine case the perspective effect is negligible that is far side has the same length as a near one. In the case of Homography the far side is shorter.
If you only have 4 points - and they're not on the same plane - then computing a homography will not work.
If you have a loads of points, and 4 of them do lie on a plane but some don't, there are filters you can use to try to remove the ones not lying on a plane. The filters implemented by OpenCV are called RANSAC and LMeDs.
Also as Hammer says in a comment under your question - The 4th point is there to figure out perspective.
Homography is a 3X3 matrix, which consists of 8 independent unknowns which means it requires 4 equations to solve these unknowns. So, in order to calculate homography we need at least 4 points.
In homography we assume that Z=0 in world scene, so the image projected is assumed as 2D. In a very famous journal named ORB-SLAM, the author formulated a scene-selective approach depending on motion parallax in scene.
Homography is the relation between two planes and the degree of freedom in case of homography transform is 7; hence you need minimum 4 corresponding points.
4 points will give you 4 pair of (x,y) hence you can calculate 7 variables. Homography is homogines transfrom hence the (3,3) value in homography matrix is always 1.
So your first question that can you calculate homography with 3 points in the plane and 4th not on the plane : it's not possible. You need projection of that point on the plane and then you can calculate the homography.
Your 2nd question about how to calculate homography matrix, you can see implemetation of findHomography() in opencv.

How to link four points to a convex polygon

How to link four points to a convex polygon? I mean how to identify the order of these four points.
Thanks.
Zhong
Take the center point (i.e. average of x and y coords), then calculate x/y values for y<centery, then for y>=centery. would be fastest I guess.
(that is, if I understood the question in the first place...)
Sort them vertically, connect 2 top most to each other and two lowest to each other.
Sort horizontally and then connect 2 leftmost to each other and two rightmost to each other.
EDIT: anyways, SO's cool related section on the right suggests an answered duplicate:
Sort Four Points in Clockwise Order
The atan2() method is handy for this, and is found in most languages.
atan2(y,x) and converts rectangular coordinates (x,y) to the angle theta from the polar coordinates (r,theta).
Given 4 points, find their average. Then calculate the four (x,y) vectors obtained by subtracting the average from each of the four points.
For each of these (x,y) vectors, calculate the angle θ = atan2(y,x). θ will be between -π/2 and π/2.
Sort the θ's. This will give you the order of the points, in clockwise order.
This only works for convex quadrilaterals.

Resources