Does that help It's easy enough to get the matrix that represents that orientation; you can work backwards from that to rotations. If you're sure the quad is planar, you can just use the face normal (which should be equivalent to any of the vertexface normals). If not, you can derive it from the cross vectors as you tried to do in your example. If the geometry is really planar the results will be the same. code :
import pymel.core as pm
from pymel.core.datatypes import Matrix, Vector, TransformationMatrix
points = [Vector(pm.xform('pPlane1.vtx[%i]' % i, q=True, t=True, ws=True)) for i in range(4)]
local_x = (points[1]  points[0]).normal()
local_z = (points[2]  points[0]).normal()
local_y = local_x.cross(local_z).normal()
centroid = sum(points) / 4.0
matrix = TransformationMatrix (
local_x.x, local_x.y, local_x.z, 0,
local_y.x, local_y.y, local_y.z, 0,
local_z.x, local_z.y, local_z.z, 0,
centroid.x, centroid.y, centroid.z, 1
)
locator = pm.spaceLocator()
pm.xform(locator, m=matrix, ws=True)
eulers = matrix.getRotation()
quat = matrix.getRotationQuaternion()
Share :

How can I find the rotation of a quad in 3D?
By : COBRAws
Date : March 29 2020, 07:55 AM
it helps some times OK. I am frankly still not really clear on what it is you're looking for, but let me try to clarify the problem and then address my best guess as to what you really want and see if that helps. As mentioned in the comment thread, a rotation is a transformation that maps one set of stuff (eg, vectors A, B, C...) to a different set of stuff (A', B', C'...). We can fully define this transformation in terms of an angle (call it θ) and an axis of rotation we'll call R. code :
theta0 = atan2(A.x, A.y);
theta1 = atan2(A_prime.x, A_prime.y);
theta = theta1  theta0;
// A and B are adjacent corners of the square
// B  A is the direction of the edge joining them
// theta is the angle between that side and the X axis
// (rotating by theta around Z should align the square)
theta = atan2(B.x  A.x, B.y  A.y);
theta1 = atan2(x,y);
hypoXY = sqrt(x*x + y*y);
c1 = x/hypoXY;
s1 = y/hypoXY;
[ c1 s1 0 ]
[ s1 c1 0 ]
[ 0 0 1 ]
theta2 = atan2(z, sqrt(x*x + y*y));
c2 = z;
s2 = hypoXY;
[ c2 0 s2 ]
[ 0 1 0 ]
[ s2 0 c2 ]
[ c2c1 c2s1 s2 ]
[ s1 c1 0 ]
[ s2c1 s2s1 c2 ]

Camera pixels to planar world points given 4 known points
By : user2400406
Date : March 29 2020, 07:55 AM
will help you try this approach: compute the homography from 4 point correspondences, giving you all information to transform between image plane and ground plane coordinates. code :
cv::Point2f transformPoint(cv::Point2f current, cv::Mat transformation)
{
cv::Point2f transformedPoint;
transformedPoint.x = current.x * transformation.at<double>(0,0) + current.y * transformation.at<double>(0,1) + transformation.at<double>(0,2);
transformedPoint.y = current.x * transformation.at<double>(1,0) + current.y * transformation.at<double>(1,1) + transformation.at<double>(1,2);
float z = current.x * transformation.at<double>(2,0) + current.y * transformation.at<double>(2,1) + transformation.at<double>(2,2);
transformedPoint.x /= z;
transformedPoint.y /= z;
return transformedPoint;
}
int main()
{
// image from http://d20uzhn5szfhj2.cloudfront.net/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/5/2/52440chessboard.jpg
cv::Mat chessboard = cv::imread("../inputData/52440chessboard.jpg");
// known input:
// image locations / read pixel values
// 478,358
// 570, 325
// 615,382
// 522,417
std::vector<cv::Point2f> imageLocs;
imageLocs.push_back(cv::Point2f(478,358));
imageLocs.push_back(cv::Point2f(570, 325));
imageLocs.push_back(cv::Point2f(615,382));
imageLocs.push_back(cv::Point2f(522,417));
for(unsigned int i=0; i<imageLocs.size(); ++i)
{
cv::circle(chessboard, imageLocs[i], 5, cv::Scalar(0,0,255));
}
cv::imwrite("../outputData/chessboard_4points.png", chessboard);
// known input: this is one field of the chessboard. you could enter any (corresponding) real world coordinates of the ground plane here.
// world location:
// 3,3
// 3,4
// 4,4
// 4,3
std::vector<cv::Point2f> worldLocs;
worldLocs.push_back(cv::Point2f(3,3));
worldLocs.push_back(cv::Point2f(3,4));
worldLocs.push_back(cv::Point2f(4,4));
worldLocs.push_back(cv::Point2f(4,3));
// for exactly 4 correspondences. for more you can use cv::findHomography
// this is the transformation from image coordinates to world coordinates:
cv::Mat image2World = cv::getPerspectiveTransform(imageLocs, worldLocs);
// the inverse is the transformation from world to image.
cv::Mat world2Image = image2World.inv();
// create all known locations of the chessboard (0,0) (0,1) etc we will transform them and test how good the transformation is.
std::vector<cv::Point2f> worldLocations;
for(unsigned int i=0; i<9; ++i)
for(unsigned int j=0; j<9; ++j)
{
worldLocations.push_back(cv::Point2f(i,j));
}
std::vector<cv::Point2f> imageLocations;
for(unsigned int i=0; i<worldLocations.size(); ++i)
{
// transform the point
cv::Point2f tpoint = transformPoint(worldLocations[i], world2Image);
// draw the transformed point
cv::circle(chessboard, tpoint, 5, cv::Scalar(255,255,0));
}
// now test the other way: image => world
cv::Point2f imageOrigin = cv::Point2f(87,291);
// draw it to show which origin i mean
cv::circle(chessboard, imageOrigin, 10, cv::Scalar(255,255,255));
// transform point and print result. expected result is "(0,0)"
std::cout << transformPoint(imageOrigin, image2World) << std::endl;
cv::imshow("chessboard", chessboard);
cv::imwrite("../outputData/chessboard.png", chessboard);
cv::waitKey(1);
}
[0.174595, 0.144853]

In a Quad tree of points, how do you partition a quad if your insert point falls exactly on the partition line?
By : 学习者SID
Date : March 29 2020, 07:55 AM
should help you out The usual definition for rectangles is that the left and lower border is included (part of the rectangle), and the right and upper border is excluded. This will be considered in the splitting code using the appropriate < and <= related to that rule.

Using OpenCV to Solve for Transform between non planar object Points and image points
By : phanjo33
Date : March 29 2020, 07:55 AM

Given a set of points, find if there exists a convex quad from these points with no points other then its corners are in
By : user2601529
Date : March 29 2020, 07:55 AM
it helps some times Create a Delauny triangulation. Find two adjacent triangles inside the convex hull (it means at least one of them is not located over convex hull) and report! To find more about Delauny triangulation read here. As if there is any concave angle between four adjacent points, it will be flipped we can say every four adjacent points inside the convex hull create a convex quad.

