Problem with Point3D tables

Hi all. Can someone tell me how to use 3D dot boards as an argument for a method or function? The following code doesn’t work. It displays “undefined method ‘Point3d’ for main:Object”

def trial ( pointArray3d )
    puts pointArray3d   
end

ptsArray3d = [Point3d(8.17156, -1.08138, 0), Point3d(8.19765, -0.861607, 0), Point3d(8.21782, -0.641216, 0)]
trial (ptsArray3d)

Thanks in advance

Try using “Geom::Point3d.new(8.17156, -1.08138, 0)”, etc., instead of “Point3d(8.17156, -1.08138, 0)”.

Alternately, you can use [8.17156, -1.08138, 0] to create a Point3d as well.

Ex: ptsArray3d = [[8.17156, -1.08138, 0], [8.19765, -0.861607, 0], [8.21782, -0.641216, 0]]

Actually, that does not create a Point3d object within SketchUp’s internal tolerance.
It is only an array of Float objects.

Better might be …

array3d = [
  [8.17156, -1.08138, 0], [8.19765, -0.861607, 0], [8.21782, -0.641216, 0]
]
pts = array3d.map {|pt| Geom::Point3d.new(pt) }

Or, a coder can create a method to convert arrays to points …

def points(ary)
  ary.map {|pt| Geom::Point3d.new(pt) }
end

# later calling ...
trial(points(array3d))

Phillipe,

Do not put a space between method names and their parameter lists.
It generates a warning output to STDOUT.
ie;

def trial( pointArray3d )
  puts pointArray3d
end

… NOT …

def trial ( pointArray3d )
  puts pointArray3d
end

And for the method call …

trial(ptsArray3d)

… NOT …

trial (ptsArray3d)

:wink:

1 Like

@LE_GALL - Listen to Dan … unlike myself, he knows what he’s talking about :wink:

1 Like

Thank you jimhami42, thank you DanRathbun.
My problem is a little more complicated. It is part of a gear calculation project. The dot boards that I have to deal with come out of a method that finds me the points of all instances and thus provides me with large 3D dot tables. Unless I find another technique to get non-3D points, I have to find a way to switch these 3D scoreboards into arguments, otherwise the code is likely to quickly become very heavy!
The method that sends me back from 3D dot tables is:

def plrecoveredge( instance )

  ents = instance.definition.entities
  edges = ents.grep(Sketchup::Edge)

  vertices = edges.flat_map(&:vertices).uniq
  points = vertices.map(&:position)
#  Now the points are local to the instance's transformation.
#  They need to be converted to “global” coordinates
  xform = instance.transformation
  ptsedges = points.map {|pt| pt.transform(xform) }

   ptsedges
  
 end 	#plrecoveredge

Thanks in advance

I do not understand you use of these terms:

“dot boards”
“dot tables”
“scoreboards”

What do they have to do with :gear: s ?

SketchUp is a 3D modeler. Geometry is made from 3D vertices which have 3D locations described by 3D points in Euclidean space.

What do you mean by “non-3D points” ?

1 Like

Excuse my English, I use an online translator. I’m talking about a transformation of Point3D array to coordinates [x,y,z ] simple array

Oh that is a conversion, not a transformation.
It is simple … add a call to Geom::Point3d#to_a in the #map block …

def plrecoveredge( instance )
  ents = instance.definition.entities
  edges = ents.grep(Sketchup::Edge)
  vertices = edges.flat_map(&:vertices).uniq
  points = vertices.map(&:position)
  #  Now the points are local to the instance's transformation.
  #  They need to be converted to “global” coordinates
  xform = instance.transformation
  # Convert to simple [x,y,z] array in global coordinates
  points.map {|pt| pt.transform(xform).to_a }
end #plrecoveredge

Note, by convention, Ruby uses method names that have words separated with underscores …

def pl_recover_edge( instance )
  # ... method code ...

This makes method names easier to read.

1 Like

Thank you very much. I’m going to be able to move on. Thanks again

1 Like