# How to find a plane without creating face?

Hi,
I need a plan of a group of points (pts) and write the following code.

``````grp = Sketchup.active_model.active_entities.add_group
plane1 = face1.plane
grp.erase!
``````

creating grp and erasing it comes to undo. How can I find plane1 without creating and erasing the group?

1 Like

Have you considered Geom.fit_plane_to_points()?

Edit: a more precise approach would be to use that method to find a plane for the first three points and then use Point3d.on_plane?() to test any other points. Geom.fit_plane_to_points() returns a â€śbest fitâ€ť plane even if the points are not actually co-planar, incontrast to Entities#add_face() which will fail if the points are not co-planar.

5 Likes

https://ruby.sketchup.com/Geom.html
A plane can be represented as either an Array of a point and a vector, or as an Array of 4 numbers that give the coefficients of a plane equation.

Letâ€™s assume the `pts` is an array of `point3D` and there are minimum 3 points and these are on a plane.
One of the possible definition of `plane1`:

``````vec0 = pts[0].vector_to( pts[1] )
vec1 = pts[0].vector_to( pts[2] )
plane1_normal = vec0 * vec1

plane1 = [pts[0], plane1_normal]
``````

The #cross (or #*) method is used to compute the cross product between two vectors.

The cross product, also called the vector product, is an operation on two vectors. The cross product of two vectors produces a third vector which is perpendicular to the plane in which the first two lie.

2 Likes

Thank you Dezmo, Now I know different ways to find a plane. I used the following code.

``````plane1 = Geom.fit_plane_to_points(pts)
``````

Hi Dezmo,
How can I find a plane vector?

https://ruby.sketchup.com/Geom.html
A plane can be represented as either an Array of a point and a vector, or as an Array of 4 numbers that give the coefficients of a plane equation.

``````plane1 = [Geom::Point3d.new(0, 0, 0), Geom::Vector3d.new(0, 0, 1)]
plane2 = [0, 0, 1, 0]
``````

Plane (geometry) - Wikipedia
Conversely, it is easily shown that if a , b , c and d are constants and a , b , and c are not all zero, then the graph of the equation:

So e.g.:

``````def plane_as_point_and_vector(plane)
if plane.length == 2
return plane
else
a, b, c, d = plane
normal = Geom::Vector3d.new(a,b,c)
point = ORIGIN.offset(normal.reverse, d)
return [point, normal]
end
end

plane_p_v = plane_as_point_and_vector(plane)
plane_normal = plane_p_v[1]
``````
3 Likes