Why do you want to restrict yourself to the two decimal places of
accuracy available from measuring on a screen, or the five places
available from echo() or an stl file, if you can have the full 18
decimal places (=64 bit) accuracy available from OpenSCAD?
Take a look here:
/*Rotation matrix from axis and angle
Sources:
https://en.wikipedia.org/wiki/Rotation_matrix#Rotation_matrix_from_axis_and_angle
https://www.varsitytutors.com/hotmath/hotmath_help/topics/multiplying-vector-by-a-matrix
*/
Angle=12; // angle of rotation
Axis=[1,2,3]; // axis of rotation
Cube=[10,20,15]; // vector defining a cube
Position=[30,20,0]; // vector defining how far the shape is to be
translated
Pos=[-30,20,0];
MyCube(Position,Angle,Axis,Cube); // packaging the action into a
module makes the list of point coordinates unavailable outside the module
/* Improper approach: packaging the action into a module
makes the list of point coordinates unavailable outside the module */
module MyCube(Position,Angle,Axis,Cube)
{
MakeCube=CubePoints(Cube); // create the list of all
8 cube vertices
MovedCube=MoveTo(Pos,MakeCube); // translate the cube to
a new position
RotatedCube=Orient(Angle,Axis,MovedCube); // rotate the cube
polyhedron(RotatedCube, CubeFaces()); // put the cube onto preview
PointerPosition=RotatedCube[0];
echo("Inside",RotatedCube,PointerPosition);
color("blue") Pointer(PointerPosition,[1,0,0],90);
}
/* proper approach: packaging the information into functions
makes the list of points available to modules inside this program,
and to modules outside this program linked to it by the
use < . . .> command.
If desired, the three functions Make(), Moved() and
Rotated() may also be merged into a single function */
function Make()=CubePoints(Cube); // create the list of
all 8 cube vertices
function Moved()=MoveTo(Position,Make()); // translate the shape
to a new position
function Rotated()=Orient(Angle,Axis,Moved()); // rotate the shape
polyhedron(Rotated(), CubeFaces()); // put the cube onto
preview
RotatedCube=Orient(Angle,Axis,Moved());
PointerPosition=RotatedCube[0];
echo("Outside",RotatedCube,PointerPosition);
color("green") Pointer(PointerPosition,[1,0,0],90);
// function Cut() // cutting action, replaces
difference()
/* Cube is a vector containing x,y,and z coordinates of a
cube /
function CubePoints(Cube)= [[-Cube.x,0,0], [0,0,0], [0,Cube.y,0],
[-Cube.x,Cube.y,0], [-Cube.x,0,Cube.z], [0,0,Cube.z], [0,Cube.y,Cube.z],
[-Cube.x,Cube.y,Cube.z]];
/ CubeFaces is the list of index numbers referencing
individual CubePoints and their coordinates */
function CubeFaces()=[ [0,1,2,3],/Bottom Face/ [4,5,1,0],/Front
Face/ [7,6,5,4],/Top Face/
[5,6,2,1],/Right Face/ [6,7,3,2],/Rear
Face/ [7,4,0,3]/Left Face/ ];
/* functions A11..A33 represent the 9 components of the
rotation matrix. When combined
into function 'Rot(Point,Axis,Angl)', they enable the
rotation of a single point around
the axis 'Axs' by the angle 'Angl'. /
function A11(Axs,Angl)=cos(Angl)+Axs.xAxs.x*(1-cos(Angl));
// column 1 of matrix describing rotation by 'Angl' around axis 'Axs'
function A12(Axs,Angl)=Axs.yAxs.x(1-cos(Angl))+Axs.zsin(Angl);
function A13(Axs,Angl)=Axs.zAxs.x*(1-cos(Angl))-Axs.y*sin(Angl);
function A21(Axs,Angl)=Axs.xAxs.y(1-cos(Angl))-Axs.zsin(Angl);
// column 2 of matrix describing rotation by 'Angl' around axis 'Axs'
function A22(Axs,Angl)=cos(Angl)+Axs.yAxs.y*(1-cos(Angl));
function A23(Axs,Angl)=Axs.zAxs.y(1-cos(Angl))+Axs.x*sin(Angl);
function A31(Axs,Angl)=Axs.xAxs.z(1-cos(Angl))+Axs.ysin(Angl);
// column 3 of matrix describing rotation by 'Angl' around axis 'Axs'
function A32(Axs,Angl)=Axs.yAxs.z*(1-cos(Angl))-Axs.xsin(Angl);
function A33(Axs,Angl)=cos(Angl)+Axs.zAxs.z*(1-cos(Angl));
function
RotX(Point,Axs,Angl)=Point.xA11(Axs,Angl)+Point.yA21(Axs,Angl)+Point.zA31(Axs,Angl);
// x-coordinate of rotated point
function
RotY(Point,Axs,Angl)=Point.xA12(Axs,Angl)+Point.yA22(Axs,Angl)+Point.zA32(Axs,Angl);
// y-coordinate of rotated point
function
RotZ(Point,Axs,Angl)=Point.xA13(Axs,Angl)+Point.yA23(Axs,Angl)+Point.z*A33(Axs,Angl);
// z-coordinate of rotated point
function
Rot(Point,Axis,Angl)=[RotX(Point,Axis,Angl),RotY(Point,Axis,Angl),RotZ(Point,Axis,Angl)];
// coordinates of rotated point as vector
function Axs()=Axis/norm(Axis); // convert 'Axis' vector to unit
vector so that Axs.xAxs.x+Axs.yAxs.y+Axs.z*Axs.z=1
/* A translation adds the same vector to all 8 points of the cube
A shape is any form of geometric "Shape'. A cube is an
example of a shape, it is a shape having 8 corners or vertices /
function MoveTo(Vector,Shape)=[for (i=[0:len(Shape)-1])
Shape[i]+Vector]; // replaces translate()
/ A rotation changes the coordinates of all points of a shape
using the function Rot((Point,Axis,Angl)) */
function Orient(Angle,Axis,Shape)=[for (i=[0:len(Shape)-1])
Rot(Shape[i],Axis,Angle)]; // replaces rotate(a=angle, v=axis)
/* debugging aid 'Pointer()' */
module Pointer(Point,Axis,Angle) // marks a 'Point' in 3D space.
'Axis' of rotation and 'Angle' mark the direction from where to mark the
'Point'
{
$fn=3;
PointerLength=10;
translate(Point) rotate(a=Angle,v=Axis)
cylinder(h=PointerLength,d1=0,d2=5,center=false);
}
As you may have noticed, this code is work in progress. Avail yourself
of it, if you like it, I do not attach any copyright to it. Tell me if
it contains bugs, but do not tell me how to extend it - those
suggestions I will ignore.
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
On 20/10/2021 21:59, Wolf wrote:
Why do you want to restrict yourself to the two decimal places of
accuracy available from measuring on a screen, or the five places a
I asked Alexa. Her answer was good enough for me - rounding up to two
decimal places can tell whether a person is in a store, or in the
neighbourhood... from blis.com - I understood that, but not all that
matrix stuff
Thanks Michael, looking forward to trying that radically different STL approach. Prompted by your post I recall vaguely that my slicing app, Cura, can measure things, although it’s not going to beat being able to do it directly in OpenSCAD.
(I’d also have to resist the temptation to go the one extra step and print it, with potential sawing/sanding/shimmying in view.)
I agree with your entreaty, essentially to get the code right in the first place. But, like you, theory versus practice… Add my novice status and impatience to get it printed and working.
Terry
On 20 Oct 2021, at 20:45, Michael Möller private2michael@gmail.com wrote:
In theory you do not need to measure or eyeball things, you know from the code you wrote where you placed it.
In practice, you want to make sure your code is correct, and does what was intended.
I am no exception. After I code the translate, rotate, sin(dist), a>b?1:0 and so on - was my thinking correct? My tool for measuring is to export the STL and use an STL viewer, which has the facility to measure the distance (and angle or radius) between any points, lines or surfaces -> www.3d-tool.de (use the free version). It does slow down the loop: code, render, export STL, import, do measurement, and then go back and iterate, but that is my encouragement to think more and experiment less :-)
(Sorry, the original OpenSCAD code has aged out of my mailwastebaset, but here is a screenshot of something similar with a measurement
<image.png>
Note it has "found" the centre of the circle even though it is in midair.)
On Wed, 20 Oct 2021 at 19:53, larry lar3ry@sasktel.net wrote:
On Wed, 2021-10-20 at 09:27 +0100, Terry wrote:
On Mon, 18 Oct 2021 13:22:24 -0600, you wrote:
My no-brainer workaround is to left-click and rotate the view
slightly.
I can't get any such small rotation to display a readable scale.
Could you show
me a screenshot please?
I see your particular object is positioned in such a way as to make it
difficult to use the scale markers at all, except for the Y markers,
and that, only for the tall vertical piece. All other parts are not
near any of the scale markers.
Sorry, but when I said it was easy, I was assuming that the object
would have several parts of interest at the origin lines, and that you
wanted to find measurements of an STL that you had not coded yourself.
So what I did, to place things next to scale markers:
Exported the object as an STL
ran a python script called stlplace on the STL, available at
https://github.com/lar3ry/OpenSCAD---Move-STL-to-origin/blob/master/stlplace.py
This will give you translate() statements to position the object at
various places:
Positions: NE, NW, SW, SE, Centre XY, Centre All
Making it a lot easier to see the markers.
I then copied the NE translate, and added lines at the beginning and
end of your code:
translate([ 6.0 , -10.0 , -0.0 ]) {
<your code>
}
See the attached for a picture.
From there, simply use one of the other positions from stlplace or
adjust the translate to bring objects of interest into the appropriate
place.
Once you have something against the appropriate markers, it's easy to
see.
One caveat; if you zoom in, at some point, the scale markers will not
be numbered unless thay are multiples of 10, but you can look at the
bigger picture before zooming.
A mmore accurate way is to create an object and place it over the part
you want to measure, and adjust it so it creates 'Z-fighting". Use the
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
Thanks for the detailed follow up. As you may have seem, Michael has also
recommended getting the STL on the case, and I'll explore. For my
relatively simple projects my favourites so far are
On Wed, 20 Oct 2021 at 18:53, larry lar3ry@sasktel.net wrote:
On Wed, 2021-10-20 at 09:27 +0100, Terry wrote:
On Mon, 18 Oct 2021 13:22:24 -0600, you wrote:
My no-brainer workaround is to left-click and rotate the view
slightly.
I can't get any such small rotation to display a readable scale.
Could you show
me a screenshot please?
I see your particular object is positioned in such a way as to make it
difficult to use the scale markers at all, except for the Y markers,
and that, only for the tall vertical piece. All other parts are not
near any of the scale markers.
Sorry, but when I said it was easy, I was assuming that the object
would have several parts of interest at the origin lines, and that you
wanted to find measurements of an STL that you had not coded yourself.
So what I did, to place things next to scale markers:
Exported the object as an STL
ran a python script called stlplace on the STL, available at
https://github.com/lar3ry/OpenSCAD---Move-STL-to-origin/blob/master/stlplace.py
This will give you translate() statements to position the object at
various places:
Positions: NE, NW, SW, SE, Centre XY, Centre All
Making it a lot easier to see the markers.
I then copied the NE translate, and added lines at the beginning and
end of your code:
translate([ 6.0 , -10.0 , -0.0 ]) {
<your code>
}
See the attached for a picture.
From there, simply use one of the other positions from stlplace or
adjust the translate to bring objects of interest into the appropriate
place.
Once you have something against the appropriate markers, it's easy to
see.
One caveat; if you zoom in, at some point, the scale markers will not
be numbered unless thay are multiples of 10, but you can look at the
bigger picture before zooming.
A mmore accurate way is to create an object and place it over the part
you want to measure, and adjust it so it creates 'Z-fighting". Use the
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
--
LargePrefPlaceholder-XKUz1MEJBwkOM