Creating a polygonal face until the given edges

How can I create a face (using the ruby code) that extends to some existing edges?

In the figure below, I want to extend the part of the edges of the shown rectangle to the edges on its sides (I understand that after this its shape will be distorted)

Please make an attempt at solving the problem yourself and if it fails, show us your code and ask specific questions.

Doing this will help us to help you because it will expose the answers to a lot of questions about your starting point. I may seem to be making a simple question more complicated, but that is actually backward: my intent is clearing out unstated assumptions that can make the problem harder or the answer fail. For example,

  • How good is your basic ability with analytic geometry?
  • How good is your familiarity with Ruby code?
  • How good is your grasp of the SketchUp Ruby API?
  • Where do the face and edges come from? In particular, are they drawn using the GUI or constructed by Ruby API code? That makes a difference in whether the code needs to search the model to find them or already has them referenced by Ruby variables. It also matters whether these are the only entities in the current active context or if there are other entities that must be excluded.
  • Your image and text say a rectangle. Is that the only starting shape that must be handled? If other shapes need to be handled, the logic may be more complicated.
  • It is impossible to tell from your image whether the face is aligned to one or more axes or may be skewed in 3D space. The math is much simpler when the face lies in one of the primary planes (x/y, x/z, or y/z).
  • Your image seems to show edges parallel to the existing sides of the rectangle. Is that correct, and is that the only orientation to be considered?
  • Your image shows a specific arrangement and number of edges. Is that the only case of interest, or is that just an example? Will edges offset from a side always be at the same distance, as your image seems to show, or could they be staggered? It matters less, but will all the edges be offset the same distance from the nearest sides?
  • Are the edges known to be co-planar with the face? This question entangles with the earlier one about how they were obtained. It also affects whether it is even possible to do what you ask, as all edges of a face must be co-planar.
  • Do you want to join the new edges to the face by lines perpendicular to the sides of the face, or could they be slanted?

I’ll stop there, as that’s plenty to ponder :wink:


and post an image of what the result is supposed to be.


This is what I’m looking for




Here are my answers to your questions in the same order -

  • I’m good with coordinate geometry

  • It’s been just 3 weeks since I started coding in ruby

  • Even in Sketchup Ruby API I’ve just worked for the past 3 weeks, so consider me to be very new to this

  • The faces have been drawn using Ruby API code

  • The image might be a little more complicated than that.

  • Oh no, the face will always be on the 2d plane (x-y plane) and aligned to either x or y axis

  • Yes, only parallel edges will be there

  • This image is just a simple example. The edges can also be at different distances from the nearest side.

  • Yes, the edges will always be in the same plane.

  • I want to join the new edges by lines perpendicular to the sides of the face.

Thanks for clarifying this out. I’m new here, and even new to Sketchup so might ask a few stupid questions before I get a good grasp of the API.

This sounds like you should be able to draw the entire shape edge-by-edge in the first place. You can calculate the points where the edges joining an end of a loose edge to the rectangle lie by replacing the x (or y as appropriate) value from the loose edge with the x (or y) value of the corresponding edge of the rectangle. You can create all of the vertex points of the final shape, arrange them in the order required by Entities#add_face and away you go! No need to draw the portions separately and then join them up.

Unless, of course, there’s more going on that I don’t know about yet :wink:

Edit, in case that wasn’t clear, here’s a picture