# Draw concave roof using Ruby API

How can I draw a concave roof like this using the ruby API? Currently I’m drawing it straight with four triangle faces. I would like to draw it concave but can’t figure out how.

The base is always square and the peak/point is always above centered 1/2 of width of square.

create the profile and use `profile.followme(path)`

john

1 Like

Draw a curved vertical face [vertical-line/base-line/arc] located mid-side on one edge of the square face ‘base’, and then use followme on that face, around the square’s edges used as a the path [taking into account the now split edge with the temp vertical face]

I was afraid I couldn’t figure out how to create the arc. I was thinking about using a loop and drawing each face then softening the edges in between.

You can easily draw an edge to make a triangular facet.
You already have the start/end point - needed for the arc.
You then have the plane of the face.
From that you can get the ‘normal’ for the arc.
You need to do some trigonometry to work out the center of the desired arc.
There are various permutations of how the arc starts/ends and its radius…
As the designer that’s your decision.

Ok thanks to everyone for your help. This formula works but there is a flaw somewhere because if fails if I set the width to 48.

``````def draw_concave(ent,width)
half = width/2
path = b.edges
b.erase!
center = [half,0-(half),width]
f.followme(path)
end

draw_concave(Sketchup.active_model.entities,36)
``````

setting the width to 12 works, but 24 causes a bug splat. Hmm I’ve got the logic wrong somewhere.

My two cents worth

``````mod = Sketchup.active_model
ent = mod.active_entities
sel = mod.selection
vue = mod.active_view
val = UI.inputbox(["Length of Side:","Bulge of Arc:"],[10.feet,1.feet],"Concave Roof")
return unless val
side,bulge = val;half=side/2
pts = [[0,0,0],[0,side,0],[side,side,0],[side,0,0]]
pts = [[side,half,0],[half,half,0],[half,half,half]]
ctr = Geom::Point3d.linear_combination(0.5,pts[0],0.5,pts[2])
mp1 = Geom::Point3d.linear_combination(0.5,ctr,0.5,pts[0])
mp2 = Geom::Point3d.linear_combination(0.5,ctr,0.5,pts[2])
tr1 = Geom::Transformation.rotation(ctr,[0,-1,0], 90.degrees)
tr2 = Geom::Transformation.rotation(ctr,[0,-1,0],-90.degrees)
cv1 = ctr.vector_to(pts[0]).normalize;
cv1.transform! tr1;#p cv1
cv2 = ctr.vector_to(pts[2]).normalize
cv2.transform! tr2; #p cv2
int = Geom.intersect_line_line([mp1,cv1],[mp2,cv2])
ang = int.vector_to(pts[0]).angle_between(int.vector_to(pts[2]))
arc[0].find_faces
arc[0].faces[0].followme fac.edges
ent.grep(Sketchup::Face){|f| f.reverse! if f.normal.z<0}
``````
3 Likes

That’s way over my head. I’ll have to break it down an figure out what is actually happening. Sometime I wish knowledge was something I could purchase.

Now sometimes the faces are drawn reversed. How or why? How can I detect this and reverse the faces?

add this to the previous code

``````ent.grep(Sketchup::Face){|f| f.reverse! if f.normal.z<0}
``````