I need to create a hexagon shape but am not able to actually calculate the matrix points by myself. I have a example for a triangle:
triangle.drawPolygon([
-32, 64, //First point
32, 64, //Second point
0, 0 //Third point
]);
I found the following website!
Polygon matrix coords calculator
Related
I am trying to get the transform matrix from one triangle to another. I am principally concerned about 2D. We will see for 3D later (but open to solutions).
I was reading this answer.
Now please correct me: if my first equilateral triangle, with sides of length 1, has its leftmost point located at the origin, its transform should be the identity matrix.
So, reading the solution above, the transform matrix I am looking for, should be triangle B matrix * inv(Identity) == B matrix.
I cannot wrap my head around that, because it seems wrong. In the given image, I want to transform blue to red, with blue having one point at the origin. The selected point of transform for the red triangle is always the closest to the origin.
The last missing image is the last transform merging Blue as Red (same triangle).
I am using Eigen (c++) for my transforms and calculation already.
Questions:
What info did I miss in the process?
What is the real transform matrix given those constraints?
Thanks
The inverted matrix is generated from the triangle you are translating from, not the destination. I've made a fiddle that demonstrates this here: https://jsfiddle.net/dwch1tju/
Let's say your first triangle has points at [0,0] [0.5,sin(60)] and [1,0] and the second triangle has points at [1.1,0.7] [0.9,1.9] and [1,0]. Then the triangle matrices are:
[[0, 0.5, 1],[0, 0.866, 0], [1, 1, 1]]
[[1.1, 0.9, 2.3], [0.7, 1.9, 0.6], [1, 1, 1]]
Demonstrated by:
const triangleMatrixA = createTriangleMatrix(triangleA);
const triangleMatrixB = createTriangleMatrix(triangleB);
Which creates a transform of
[[0.88, 0.56, -1.36], [0.07, 0.85, -0.67], [0, 0, 1]]
Demonstrated by:
const invertedMatrixB = invertMatrix(triangleMatrixB);
const multiplied = multiplyMatricies(triangleMatrixA, invertedMatrixB)
The fiddle then uses the transform on the three points in the second triangle, to show that they become the points of the first tringle in these lines:
const translatedA = multiplyPointByMatrix(multiplied, triangleB.a);
const translatedB = multiplyPointByMatrix(multiplied, triangleB.b);
const translatedC = multiplyPointByMatrix(multiplied, triangleB.c);
The first generated image in the fiddle shows the original location of the triangles and the second image shows that the translated points place the triangles in the same location.
The answer you link is not inverting a transform. It is inverting a triangle matrix that contains the coordinates of the triangle, then multiplying it by the other triangle matrix to create a transform.
I want to make a hole in each of these cubes.
Here is the code:
y=45;
for (i=[1:8]){
z = y*i;
difference(){
rotate([0,0,z]) translate([57,0,-5]) cube(center = true,[5,10,10]);
rotate([90,90,z]) translate([6,0,-60]) cylinder(5,2,2);
}
}
// This is a reference, translate([6,0,-60]) is correct position
rotate([90,90,z]) translate([16,0,-60]) cylinder(5,2,2);
Why
rotate([90,90,z]) translate([6,0,-60]) cylinder(5,2,2);
do not work in a for loop?
When z is setting manually to 45, 90, 135, 180...315 the holes are correct.
So the main loop will position your cuboids rotated around the origin
at an angle which is a multiple of 45 degrees. Inside the loop, you
now want to draw the cuboids, and right after that, relative to the
position of each cuboid, you make a few more transformations (a rotation
and translation) to get the cylinders to pass through the centers of the
cuboids (It also helps if the height of the cylinder is bigger than the
side of the cuboid so you can actually see it passing through):
y=45;
for (i=[1:8]){
z = y*i;
rotate([0,0,z]) translate([57,0,-5])
{
cube(center=true,[5,10,10]);
rotate([0,90,0]) translate([0,0,-5]) cylinder(r=2,h=10,$fn=100);
};
}
Now that you know the positions are correct, you can apply the boolean difference and obtain the hole at the center of each cuboid:
y=45;
for (i=[1:8]){
z = y*i;
rotate([0,0,z]) translate([57,0,-5])
difference() {
cube(center=true,[5,10,10]);
rotate([0,90,0]) translate([0,0,-5]) cylinder(r=2,h=10,$fn=100) ;
}
}
You can find all the code for this here.
I have a TrousGeometry. I need to translate this geometry to point C, intersection point of perpendicular line drawn from center point of each end A & B of the torus.
https://jsfiddle.net/arundhaj/wkLmv4cn/
You just need to use the BufferGeometry.translate() method on torusGeometry.
const torusGeometry = new THREE.TorusGeometry(
curveRadius, beginRadius, 32, 64, angle
);
torusGeometry.translate(
-curveRadius - beginRadius,
-curveRadius - beginRadius,
0
);
See line 69: https://jsfiddle.net/0L587bxe/
If you don't want to take the thickness of the torus into account, just get rid of -beginRadius in the translation.
I want to find the circles in the below image.I tried using OpenCV's Hough circle detection but it is not giving the proper results.
Is there any other way to find circles?
Here is sample code
vector<Vec3f> circles;
Mat src_gray,te;
cvtColor(tImg, src_gray, CV_BGR2GRAY);
GaussianBlur(src_gray, src_gray, Size(9, 9), 2, 2);
Canny(src_gray, te, 40, 240, 3);
/// Apply the Hough Transform to find the circles
HoughCircles(te, circles, CV_HOUGH_GRADIENT, 1, te.rows / 10, 120, 9, 5, 25);
Take contour,
1. find the centroid of the contour
2. find distance from the centroid to each contour pixels.
3. if this distance is almost same then it will be a circle.
See This link
Say I have point A (20,20) and point B (60,60).
The resulting vector would be 40, 40. How could I get the angle of this vector?
By this I mean, imagine there is an imaginary circle around the origin.
I guess sort of what atan2 does but without atan2.
Thank
Presuming that you want to find the angle of the vector against the X axis (in JavaScript):
var vector = {x: 40, y: 40};
var rad = Math.atan(vector.y/vector.x)
var deg = rad * 180/Math.PI;
alert(deg); // 45 deg
I'm not sure what you mean by angle, since you only give one vector in your example. But, given two vectors, you can find the angle between them like so:
Given vectors a and b, normalize both of them. Then, dot(a, b) = cos(θ), where θ is the angle between the two vectors. Use arccos to find θ.
Below is the link that will show you how to find the angle bewteen two vectors:
http://www.wikihow.com/Find-the-Angle-Between-Two-Vectors