Should I use vectors?

I am making a trim tool that creates base trim, casing, and crown molding by creating a face and extruding it on multiple paths. I gather input from the user to create the trim. Should I use vectors or regular points? Here’s some of my code.

       #Input for trim
       prompts = ["Casing Thickness:            ", "Casing Width:",  "R:", "G:", "B:"]
       defaults = [0.75, 3, 255.0, 255.0, 255.0]
       list = ["", "",  "", "",  ""]
       input = UI.inputbox(prompts, defaults, list, "Casing")
       return unless input

       case axis
       when X_AXIS
         [ [0,0,0], [width,0,0], [0,thickness,0], [width,thickness,0] ]
       when Y_AXIS
         [ [0,0,0], [0,width,0], [thickness,0,0], [thickness,width,0] ]
       when Z_AXIS
         [ [0,0,0], [0,0,width], [thickness,0,0], [thickness,0,width] ]

It depends on what you want to do.

You are actually using arrays ([float, float, float]).

Points are specific absolute positions in a coordinate system. Vectors describe a parallel movement, how a second point is positioned relative to a first point. Thus vectors can be seen as the difference between points (distance and direction).

Generally vectors more useful because we can describe a point by a corresponding vector that is relative to the origin. However in SketchUp’s API there are unfortunately methods that don’t work with vectors and vice versa. SketchUp as overloaded the array class so you can use it as a shorthand for, float, float) or, float, float) and all SketchUp API methods accept it.

From your code I guess these are used coordinates of corner points of a rectangle. If you want to move them relative to reference point (add them to a point), then you need vectors. But you can also apply a Transformation.

Check whether the inputbox returns text strings, then you need to parse them to floating point numbers (width.to_f).


for doing what ?

1 Like

I want to create the faces on wherever in the model to extrude them on paths of selected edges.

Well, if the creation of these faces are what the question was aimed at, … then finding the answer is simple.

Look at the documentation for Sketchup::Entities#add_face method and see what the method takes as it’s arguments.

Hint: Vectors are not among the argument types allowed. So you are limited to either a list (or array) of either points, edges (which can be loose edges along with the edges that make up curve objects,) or a single curve object.

1 Like