[OpenSCAD] Can you suggest some libraries of standard geometry conversions?

ufomorace ant.stewart at yahoo.com
Wed Sep 30 15:12:06 EDT 2015


I will collect as many simple maths functions as i can and will write them to
the top of this page in .scad form, feel free to post any 3d manip functions
i will make a neat library in the OP.

Because of the lack of rewriteable variables and the translation of code it
would take a lot longer to make and verify a 3d functions library in .scad
language than just copy pasting a c++ one.  for example lookat function, i
have cubes arranged in a sphere around origin and want to make them all look
at the centre, or any other random point. 

here is look at:

// C++ code
// this code assumes the camera is initially looking towards (1,0,0)
positive z direction
// if you want the initial direction to be along the x or y coordinates then
try swapping
// the order when setting the components
// dir = target direction
// up = a vector which is perpendicular to the camera axis
void LookAt(const vector3& dir, const vector3& up, matrix33& m) { 
        vector3 z(dir); 
        z.norm(); 
        vector3 x( up * z ); // x = up cross z 
        x.norm(); 
        vector3 y( z * x ); // y = z cross x 
        m.set_components(x,y,z ); 
} 

first we have to write the matrix of any objects that need to be looked at:

have to convert position where objects are created to a matrix version using
this:

 // Extract new local position
 Vector3 position = m.GetColumn(3);
 
 // Extract new local rotation
 Quaternion rotation = Quaternion.LookRotation(
     m.GetColumn(2),
     m.GetColumn(1)
 );
 
 // Extract new local scale
 Vector3 scale = new Vector3(
     m.GetColumn(0).magnitude,
     m.GetColumn(1).magnitude,
     m.GetColumn(2).magnitude
 );






--
View this message in context: http://forum.openscad.org/Can-you-suggest-some-libraries-of-standard-geometry-conversions-tp13900p14038.html
Sent from the OpenSCAD mailing list archive at Nabble.com.




More information about the Discuss mailing list