 # Problem of control of the vertices

Hello to all,

I have a hard to master the vertices of the curves and the arc of circle in order to obtain the "pushable" of complex figures faces. Could someone explain to me why the first program works and not the second?

``````# Default code, use or delete...
mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection
vector = Geom::Vector3d.new 0,0,1
xaxis = Geom::Vector3d.new 1,0,0
center = Geom::Point3d.new 0, 0, -1
normal = vector.normalize!
pi = Math::PI
start_a = 0.0
end_a = pi/2

x1 = 10
y1 = 10
z1 = 0.0
x2 = 10
y2 = 20
x3 = 20
y3 = 10
pt1 = Geom::Point3d.new x2, y2, 0
pt2 = Geom::Point3d.new x1, y1, 0
pt3 = Geom::Point3d.new x3, y3, 0
pts = []
pts << pt1
pts << pt2
pts << pt3
r = 10
c = Geom::Point3d.new x1, y1, z1
edgearray = ent.add_arc c, xaxis, normal, r , start_a, end_a, 5
edge = edgearray
curve = edge.curve
vertices = curve.vertices
for i in (1..vertices.length-1)
pts << vertices[i].position
puts vertices[i].position
end
#pts << pts

# Default code, use or delete...
mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection
vector = Geom::Vector3d.new 0,0,1
xaxis = Geom::Vector3d.new 1,0,0
center = Geom::Point3d.new 0, 0, -1
normal = vector.normalize!
pi = Math::PI
start_a = 3*pi/2
end_a = pi

x1 = 10
y1 = 10
z1 = 0.0
x2 = 10
y2 = 20
x3 = 20
y3 = 10
pt1 = Geom::Point3d.new x2, y2, 0
pt2 = Geom::Point3d.new x1, y1, 0
pt3 = Geom::Point3d.new x3, y3, 0
pts = []
ptsarc = []
pts << pt1
pts << pt2
pts << pt3
r = 10
c = Geom::Point3d.new x3, y2, z1
edgearray = ent.add_arc c, xaxis, normal, r , start_a,end_a,  5
edge = edgearray
curve = edge.curve
vertices = curve.vertices
for i in (0...vertices.length)
pts << vertices[i].position
ptsarc << vertices[i].position
puts vertices[i].position
end
#pts << pts
``````

Yet, they are built on the same principles.

Can you click Edit on your post, select the code and click </> to format it as code and make it more readable?

That depends on what “works” means for you or someone else. Can you describe in a concise phrase what the difference between both implementations is, what you expected to happen and what actually happens instead?

I just modify the second program by reversing the direction of the plot and there surprise, it works. Could you explain to me why?
In the first version the program does not provide the coordinates of the vertex points of the arc. In the second, yes.

Here is the version that does not work:

``````# Default code, use or delete...
mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection
vector = Geom::Vector3d.new 0,0,1
xaxis = Geom::Vector3d.new 1,0,0
center = Geom::Point3d.new 0, 0, -1
normal = vector.normalize!
pi = Math::PI

start_a = 3*pi/2                     #   <======
end_a =   pi                            #   <======

x1 = 10
y1 = 10
z1 = 0.0
x2 = 10
y2 = 20
x3 = 20
y3 = 10
pt1 = Geom::Point3d.new x2, y2, 0       # <=====
pt2 = Geom::Point3d.new x1, y1, 0       # <=====
pt3 = Geom::Point3d.new x3, y3, 0       # <=====
pts = []
ptsarc = []
pts << pt1
pts << pt2
pts << pt3
r = 10
c = Geom::Point3d.new x3, y2, z1
edgearray = ent.add_arc c, xaxis, normal, r ,start_a, end_a,  5
edge = edgearray
curve = edge.curve
vertices = curve.vertices
for i in (0...vertices.length)
pts << vertices[i].position
ptsarc << vertices[i].position
puts vertices[i].position
end
#pts << pts

``````

Here is the version that works:

``````# Default code, use or delete...
mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection
vector = Geom::Vector3d.new 0,0,1
xaxis = Geom::Vector3d.new 1,0,0
center = Geom::Point3d.new 0, 0, -1
normal = vector.normalize!
pi = Math::PI
start_a = pi                                #  <=====
end_a = 3*pi/2                             #  <=====

x1 = 10
y1 = 10
z1 = 0.0
x2 = 10
y2 = 20
x3 = 20
y3 = 10
pt3 = Geom::Point3d.new x2, y2, 0                    #    <=====
pt2 = Geom::Point3d.new x1, y1, 0                    #    <=====
pt1 = Geom::Point3d.new x3, y3, 0                    #    <=====
pts = []
pts << pt1
pts << pt2
pts << pt3
r = 10
c = Geom::Point3d.new x3, y2, z1
edgearray = ent.add_arc c, xaxis, normal, r , start_a,end_a,  5
edge = edgearray
curve = edge.curve
vertices = curve.vertices
for i in (0...vertices.length)
pts << vertices[i].position
puts vertices[i].position
end
#pts << pts
``````

OK, thanks.
I have rectified my presentation above.

To edit a post, look for the three dots next to the Reply button, that brings up additional actions:  I’m not fully understanding your question. Can you elaborate on what doesn’t work and what works? Also, can you detail more on what you are trying to do? Perhaps some screenshots to illustrate?

The goal of my project is to make a program in ruby ​​under sketchup to draw automatically gears. This requires mastering the creation of surfaces with complex contours. Overcoming problems that I do not understand, I analyze these problems on simpler examples (Surfaces with two straight lines [10,10,0], [10,20,0] and [10,10,0], [20 , 10.0] closed by a circular arc of radius 10 concave or convex). I have noticed that the sense of tracing matters and that the levorotatory direction must be respected for convex surfaces, and dextrorotatory for concave surfaces. If this is the case, it will make the project much more difficult. So is this the case?

Using Edge.curve will give you unexpected results in many situations. It is better to iterate through the edges returned from Entities.add_arc and collect the unique vertices. Like so:

``````    mod = Sketchup.active_model # Open model
ents = mod.entities # All entities in model

r = 10
c = Geom::Point3d.new(20,20,0)
start_a = 270.degrees
end_a = 180.degrees

edgearray = ents.add_arc( c, X_AXIS, Z_AXIS, r, start_a, end_a, 5)

pt2 = 10,10,0

``````

OK, thank you Williams.

It will actually be much simpler like that

Hi Mr. Williams,
After a lot of attempts, I have not managed to adapt your example to my program. I have to get something like this first:

to have that:

then a gear like this:

I must say that I am a beginner in ruby ​​language and even more skechup ruby. To reach my goals I had to write a “gas plant” (I do not know how you would say it in English).
Could you if you have the time to correct according to your methods the little program below written according to my methods and who does that: ``````# Default code, use or delete...
mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection
vector = Geom::Vector3d.new 0,0,1
xaxis = Geom::Vector3d.new 1,0,0
center = Geom::Point3d.new 0, 0, -1
normal = vector.normalize!
pi = Math::PI

start_a = pi
end_a = 3*pi/2
pts = []
x1 = 0
y1 = 10
z1 = 0.0
x2 = 0
y2 = 40
x3 = 20
y3 = 10
x4 = 20
y4 = 20
pt0 = Geom::Point3d.new x3, y3, 0
pt1 = Geom::Point3d.new x4, y4, 0

pts << pt0
pts << pt1

r = 10
c = Geom::Point3d.new 20, 30, z1
edgearray = ent.add_arc c, xaxis, normal, r , start_a,end_a,  50
edge = edgearray
curve = edge.curve
vertices = curve.vertices
n = vertices.length
for i in (1...n-1)
k = n - 1 - i
pts << vertices[k].position
puts vertices[i].position
end

start_a = 0.0
end_a = pi/2

r = 10
c = Geom::Point3d.new 0, 30, z1
edgearray = ent.add_arc c, xaxis, normal, r , start_a, end_a, 50
edge = edgearray
curve = edge.curve
vertices = curve.vertices
for i in (0...vertices.length-1)
pts << vertices[i].position
puts vertices[i].position
end
pt3 = Geom::Point3d.new x2, y2, 0
pt2 = Geom::Point3d.new x1, y1, 0
pt1 = Geom::Point3d.new x3, y3, 0

pts << pt3
pts << pt2
pts << pt1
#pts << pts
``````

`.rbz` files are simply zip files with a different extension. So just copy the rbz, rename to `rack_and_pinion.zip` , extract it, and you’ll have the ruby files that Jim Hamilton wrote.