How to calculate inner and outer sides of solid?

Using Sketchup::Geom only.
For example: we have four points that do not belong to the same plane. How to calculate the normals of the faces directed inwards or outwards?

What do you mean by inner and outer sides? Faces or Planes? What do you want to calculate?

Where are these four example points located? What do the four points have to do with a face and which face? The normal of face is always a vector which is perpendicular to the face in the front direction. What does it mean if the face is directing outwards or inwards? In a “good” solid object these always directing outwards (you can see the front of the face)…

Can you have screenshots with comments, and perhaps an example model, so you can elaborate more what you want to achieve?

1 Like

Four points that do not lie in the same plane and segments connecting them in pairs, define the pyramid. When I talk about the faces, I mean the base and sides of this pyramid, not Sketchup::Face instance. Each of these sides will lie on a plane and each plane will have two perpendicular normal vectors.I want to find vectors directed inside the pyramid. The solution for this case will be simple - a vector from the projection of a point on a plane defined by the three remaining, to this point.

What about a rectangular parallelogram or a box? What about any solid?

The Sketchup::Geom module does not currently define any plane or solid geometric “virtual” objects other than BoundingBox, such as Circle, Triangle, Rectangle, Sphere, Cone, Pyramid, etc. You would need to define custom classes for these inside your namespace module, or find a existing library that already defines these.

What specifically is causing you problems?
Are you having issues writing the geometric algorithms?

What have you tried so far? We usually ask that you at the very least make an attempt yourself. Then when you run into a “roadblock”, … post the failing code here with a specific coding question.

1 Like

Following your theory, If you have more than 4 points it can define more than one solid object, so you need to have more info which one you want to examine…
But, as Dan mentioned, solids - in Sketchup - are not defined by points “virtually”.

In Sketchup, solid objects (group or component instances) are made up of faces bounding it ( edges bounding the faces). I think that’s how it makes sense. Make a solids, and then you can “examine.”
Let’s assume you created them (correctly) with the front of the faces facing outwards.

In this case, the inverse of the normal vectors of the faces is the inward-pointing vectors.
Something like that:

# find the solid objects in a root of the model
solids = Sketchup.active_model.entities.select{|e|
  ( e.is_a?(Sketchup::Group) ||
    e.is_a?(Sketchup::ComponentInstance) ) &&
    e.manifold?
}
#e.g. find one of the solid vectors directed to "inside"
vectors_0_to_inside = solids[0].entities.grep(Sketchup::Face).map{|f| f.normal.reverse }

(You may need to consider the transformation of component/group instances …)

You misunderstood me. The triangular pyramid was given as the simplest example.

I may not have used the term accurately. I meant three-dimensional shapes that have volume. An instance of the class describing this shape may have a method that returns an array of polygons (array of Point3d) representing the faces of the shape.
My question was to find the vectors perpendicular to the faces of this shape, pointing inwards. This shape is virtual, I need to avoid using Drawingelement subclasses to calculate.

Thank you for your answers, they were very helpful.

I read the sketchup ruby api documentation before asking this question.

I assumed that a solution using shape construction (creating Faces, not virtual) would be proposed. As suggested by @dezmo

I do not know how to describe the task in more detail. Suppose I have a class that describes a rectangular box. This class has a instance method sides that returns an array of 6 rectangles (array of 4 Point3d) representing the faces of the box. I want to find vectors perpendicular to these faces directed inside the box.

Perhaps this task is also trivial for the box. You can find the intersection point of the diagonals of the box, or take one of the points that does not lie on the face and build a projection onto the plane of the face. But I would like to find a common algorithm for all shapes with volume.

Since you don’t want to create SketchUp DrawingElements, you will need to work purely with the math of 3D geometry. SketchUp provides very limited support for this, so you will mostly need to roll your own. Here are some ideas

To avoid confusion with SketchUp::Face, I’ll call a surface polygon of your shape a “facet”.

The first task is to find a vector perpendicular to the facet. I can think of several ways to do this. The simplest one is to calculate vectors from a corner point of the facet to two other corner points and take their vector cross product. The result is a vector perpendicular to the facet.

Your next task is to decide whether this vector points into or out of the shape. One way to do this that works if the shape is convex is to calculate a vector from the center point of the facet (easy to find for any convex polygon) and a corner point from another facet that is not also used by the selected facet. The inner product between this vector and the perpendicular one will be positive if the perpendicular is pointing inside the shape, negative if pointing out.

BTW, per your original question, you need to clarify your notion of front and back sides of a polygon. Otherwise the question is meaningless: a polygon per-se does not have a front or back. SketchUp uses the convention that the corner points are traversed in counter-clockwise order when viewed looking at the “front” along the reverse normal vector (“right-hand rule”).

Thank you for your help.