Problem of control of the vertices


#1

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[0]    
curve = edge.curve  
vertices = curve.vertices
for i in (1..vertices.length-1)
    pts << vertices[i].position
    puts vertices[i].position
end
#pts << pts[0]
face = ent.add_face (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[0]    
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[0]
fig = ent.add_curve (pts)
#face = ent.add_face (fig)

Yet, they are built on the same principles.

Thanks in advance


#2

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?


#3

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.


#4

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[0]    
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[0]
fig = ent.add_curve (pts)
face = ent.add_face (fig)

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[0]    
curve = edge.curve  
vertices = curve.vertices
for i in (0...vertices.length)
    pts << vertices[i].position
    puts vertices[i].position
end
#pts << pts[0]
fig = ent.add_curve (pts)
face = ent.add_face (fig)

#5

#6

OK, thanks.
I have rectified my presentation above.


#7

To edit a post, look for the three dots next to the Reply button, that brings up additional actions:

2018-08-30_12h33_54

2018-08-30_12h34_02

(I edited your first post for you by adding the backticks.)


#8

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?


#9

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?


#10

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
    ents.add_face(edgearray.collect{|e|e.vertices}.flatten.uniq << pt2)

please visit this discussion


#11

OK, thank you Williams.

It will actually be much simpler like that


#12

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[0]    
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[0]    
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[0]
fig = ent.add_curve (pts)
face = ent.add_face (pts)

Thanks in advance


#13

You can do no better than to look at another programmer’s solution to a problem you are trying to solve. If you visit the following thread you will find a link to download Jim Hamilton’s rack and pinion ruby code.


#14

OK Thanks sWilliams.
However I do not see how, by installing Jim Hamilton’s plugin, I will have access to sources?


#15

.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.


#16

Thank you very much somtum and everyone. I study the source of James and I realize that he has already realized better what I wanted to do less well. It’s a little demotivating!


#17

Is this what you are trying to create?


#18

It’s a result of my application that I was about to set up just like Jim Hamilton’s plugin. If you’re interested, I can give you the code, but in front of Jim’s, I’m ashamed.