I have reduced my problem (see
Trouble-with-rotating-Text-to-correct-orientation <http://forum.openscad.org/Trouble-with-rotating-Text-to-correct-orientation-td30280.html> ) to one rotating angel, I cannot find the correct calculation. The task is to span an area between two points P1 and P2 in a direction given by a direction vector D (which is identical to the problem in the subject). The image illustrates it: <http://forum.openscad.org/file/t2988/span-area.jpg> If you load the attached script ( span-area.scad <http://forum.openscad.org/file/t2988/span-area.scad> ) into OpenSCAD and open the Customizer, you can move P1 and P2 anywhere and the grey fill area is placed perfect. You can also change d.z from the direction vector d. But if you change d.x or d.y, then the fill area goes out of the target plane. I only miss one rotation angel (rx), I tried several combinations of trigonometrics, but none of them were correct. Any help would be thankfully appreciaded. If I have solved this problem, I'm ready to share some - I believe - very helpful modules for OpenSCAD. Regards -- Sent from: http://forum.openscad.org/ _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
Euler rotations always confuse me so I did it with Frenet-Seret style vector maths. Seems to work. function unit(v) = let(n = norm(v)) n ? v / n : v; // Convert v to a unit vector function orientate(p, r) = // Matrix to translate to p and rotate to r let(x = r[0], y = r[1], z = r[2]) [[x.x, x.y, x.z, p.x], [y.x, y.y, y.z, p.y], [z.x, z.y, z.z, p.z], [ 0, 0, 0, 1 ]]; //---------------------------------- // WorkInProgress // fill area spanned by p1-p2 and d //---------------------------------- module fill(p1,p2,d) { // this is the vector v=p2-p1; // length of vector l=norm(v); // length of d h=norm(d); // angel between v and d is amout to shear sxy=angel(v,d); tangent = v; normal = d; binormal = cross(tangent, normal); x = unit(tangent); z = unit(binormal); y = -unit(cross(tangent, binormal)); rot = [[x.x, y.x, z.x], [x.y, y.y, z.y], [x.z, y.z, z.z]]; multmatrix(orientate(p1, rot) * sxy(sxy)) area(l,h,"p1","p2","p1+d","p2+d"); // DEBUG: show sheared area before translate/rotate #multmatrix(sxy(sxy)) area(l,h,"p1","p2","p1+d","p2+d"); } On Sat, 31 Oct 2020 at 08:38, jjvbhh <[hidden email]> wrote: I have reduced my problem (see _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
Bit more concise version: binormal = cross(v, d); x = unit(v); z = unit(binormal); y = unit(cross(binormal, v)); On Sat, 31 Oct 2020 at 11:47, nop head <[hidden email]> wrote:
_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
In reply to this post by nophead
nophead wrote
> Euler rotations always confuse me so I did it with Frenet-Seret style > vector maths. Seems to work. Yes, works fine! Your great, many thanks for your quick response. This really brings me a giant step forward my targets. Now I only have to understand your magic code. I will come back soon with some fine measure modules Regards -- Sent from: http://forum.openscad.org/ _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
My code basically sets up a new coordinate system aligned to the vectors and then maps the original plane x, y, z to that new set of axes. On Sat, 31 Oct 2020 at 12:36, jjvbhh <[hidden email]> wrote: nophead wrote _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
The new x axis is along v. The new z axis is at right angles to both v and d by taking the cross product. The new y axis is then at right angles to both z and x using another cross product. On Sat, 31 Oct 2020 at 12:38, nop head <[hidden email]> wrote:
_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
In reply to this post by nophead
On 2020-10-31 12:47, nop head wrote:
> Euler rotations always confuse me so I did it with Frenet-Seret style > vector maths. Seems to work. Why such complicated approach? What is wrong with simply adding the vector to the two points to obtain the rectangle area? Carsten Arnholm _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
It isn't a rectangle, it is a parallelogram with sheared text on it. On Sat, 31 Oct 2020 at 12:49, <[hidden email]> wrote: On 2020-10-31 12:47, nop head wrote: _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
On 2020-10-31 13:51, nop head wrote:
> It isn't a rectangle, it is a parallelogram with sheared text on it. My question still stands if it is a parallelogram Carsten Arnholm _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
So what is your solution to construct a transform to rotate and shear a plane to align with an arbitrary parallelogram? On Sat, 31 Oct 2020 at 12:56, <[hidden email]> wrote: On 2020-10-31 13:51, nop head wrote: _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
On 2020-10-31 13:58, nop head wrote:
> So what is your solution to construct a transform to rotate and shear > a plane to align with an arbitrary parallelogram? The problem was presented with this illustration http://forum.openscad.org/file/t2988/span-area.jpg As far as I can tell you can do exactly what the figure indicates, add the vector d to each point to arrive at the parallelogram. But maybe I am missing something? Carsten Arnholm _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
Yes it would be easy to calculate the forth vector to complete the polygon but then how do you draw it with text, which are 2D operations operating in the XY plane? On Sat, 31 Oct 2020 at 13:05, <[hidden email]> wrote: On 2020-10-31 13:58, nop head wrote: _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
On 2020-10-31 14:10, nop head wrote:
> Yes it would be easy to calculate the forth vector to complete the > polygon but then how do you draw it with text, which are 2D operations > operating in the XY plane? I have not studied the details, but obviously you can compute the plane equation from 3 points. Or even simpler, create a vector from P1 to P2 and compute a couple of cross products (the first with vector d) to arrive at the 3 first columns of the transformation matrix. The fourth is simply choosing an origin. So I thing you can transform the text with the resulting matrix. Carsten Arnholm _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
That is pretty much exactly what I did. On Sat, 31 Oct 2020 at 13:22, <[hidden email]> wrote: On 2020-10-31 14:10, nop head wrote: _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
Here is a simpler version. Instead of computing the shear and applying it I simply set up the X and Y axes along the edges of the parallelogram and make Z orthogonal to both with a cross product. module fill(p1,p2,d) { // this is the vector v=p2-p1; // length of vector l=norm(v); // length of d h=norm(d); x = unit(v); y = unit(d); z = unit(cross(v, d)); m = [[x.x, y.x, z.x, p1.x], [x.y, y.y, z.y, p1.y], [x.z, y.z, z.z, p1.z], [0, 0, 0, 1 ]]; multmatrix(m) area(l,h,"p1","p2","p1+d","p2+d"); } On Sat, 31 Oct 2020 at 13:37, nop head <[hidden email]> wrote:
_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
On 2020-11-01 10:15, nop head wrote:
> Here is a simpler version. Instead of computing the shear and applying > it I simply set up the X and Y axes along the edges of the > parallelogram and make Z orthogonal to both with a cross product. > > module fill(p1,p2,d) > { > // this is the vector > v=p2-p1; > > // length of vector > l=norm(v); > > // length of d > h=norm(d); > > x = unit(v); > y = unit(d); > z = unit(cross(v, d)); > m = [[x.x, y.x, z.x, p1.x], > [x.y, y.y, z.y, p1.y], > [x.z, y.z, z.z, p1.z], > [0, 0, 0, 1 ]]; > > multmatrix(m) area(l,h,"p1","p2","p1+d","p2+d"); > } That's pretty much it, except with this you are assuming it is a rectangle, not a parallelogram. In the above, d is typically not orthogonal to v, so the matrix m is then incorrect. That's why I said "a couple of cross products" and not just one as in your code. If you cross z with x you can arrive at a new y and thus arrive at an orthogonal m. Carsten Arholm _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
My previous iteration had two cross products so that the new axes were mutually orthogonal because I thought that was a requirement. But it seems not as aligning the axes with the parallelogram works to skew the rectangle to map onto it. Presumably the matrix values are identical to the version with orthogonal axes post multiplied by the skew matrix. The end result looks the same. On Sun, 1 Nov 2020 at 09:46, <[hidden email]> wrote: On 2020-11-01 10:15, nop head wrote: _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
Free forum by Nabble | Edit this page |