Line defined by the intersection of two faces. intersect_plane_plane method produces just a fragment

intersect
face

#1

Hello Folks,
Hope everybody is having a great time using Sketchup.

I am trying to get the line defined by the intersection of two faces. Please, see uploaded picture
Using the intersect_plane_plane method does not produce the whole intersection line, but just a fragment. For brevity I am including the code in the text, since it is short.

mycircle1 = Sketchup.active_model.entities.add_circle [1, 2, 3], [8, 2, 1], 7
myface1= Sketchup.active_model.entities.add_face mycircle1 
mycircle2 = Sketchup.active_model.entities.add_circle [1, 2, 3], [2, 8, 1], 7
myface2= Sketchup.active_model.entities.add_face mycircle2 

# Definition: The intersect_plane_plane method is used to compute the intersection of two planes.
# Turns out the line it produces is not the whole intersection line, but just a fragment.
# The following line produces: [Point3d(1.3, 2.3, 0), Vector3d(-0.0990148, -0.0990148, 0.990148)]
mylinedef = Geom.intersect_plane_plane(myface1.plane, myface2.plane)

myline2ndpoint = mylinedef[0] + mylinedef[1]
myline = Sketchup.active_model.entities.add_line mylinedef[0], myline2ndpoint

Why is it that the intersect_plane_plane method is not producing the entire line defined by the intersection of two faces? Isn’t that what it is supposed to do? How can I get the entire line?

Thanks in advance for your help.

Raoul


#2

The intersect_plane_plane method results in an array of a point and a vector - not what you really want:
http://ruby.sketchup.com/Geom.html#intersect_plane_plane-class_method

Why not use:
http://ruby.sketchup.com/Sketchup/Entities.html#intersect_with-instance_method

edges = model.active_entities.intersect_with(recurse, transformation1, entities1, transformation2, hidden, entities2)

The list of arguments looks complex, BUT in order, to do what you want it’ll be something like…

  • false
  • ORIGIN
  • model.active_entities
  • ORIGIN
  • false
  • [myface1, myface2]

#3

Building on what @TIG wrote, you have misunderstood what the Ruby API returns from the #intersect_plane_plane method (the terse API doc page, like some of the other Geom pages, doesn’t explain much, it assumes you know your analytic geometry!).

Specifically, the method returns an Array containing the constants of the equation for an infinite line: a Point3d and a Vector3d. The line is defined mathematically as

p(k) = p + k*v

where p(k) is another point on the line, p and v are the two entities returned by the method call, and k is a scalar parameter choosing what point on the line you will get. Such a line is an abstract object, it is not a real geometric entity in the SketchUp model data.

PS: “planes” are also handled in SketchUp as abstract mathematical objects, defined by constants used in a formula. But planes suffer from having two different representations in SketchUp, with scant documentation of which form is returned by any method or which form is acceptable as input!


#4

A line (and a plane) in SketchUp are infinite. (It says so right at the very top of the Geom module documentation page.)

So you now (after having gotten the array that describes the infinite intersection line,) need to find the two points where it crosses the face’s edges.

So this should do it:

mycircle1 = Sketchup.active_model.entities.add_circle [1, 2, 3], [8, 2, 1], 7
myface1= Sketchup.active_model.entities.add_face mycircle1 
mycircle2 = Sketchup.active_model.entities.add_circle [1, 2, 3], [2, 8, 1], 7
myface2= Sketchup.active_model.entities.add_face mycircle2 

# Definition: The intersect_plane_plane method
# is used to compute the intersection of two planes.
mylinedef = Geom.intersect_plane_plane(myface1.plane, myface2.plane)

end_pts = []

mycircle1.each {|edge|
  point = Geom.intersect_line_line(mylinedef, edge.line)
  if myface1.classify_point(point) == Sketchup::Face::PointOnEdge
    end_pts << point
  end
}

if end_pts.size != 2
  # "Houston, we have a problem."
else
  myline = Sketchup.active_model.entities.add_edges(end_pts)
end

Just for clarity of the fact that a line and an edge are different in the SketchUp API, …
I’ll use the #add_edges() method, even though we are only adding one segment.


#5

I also suppose we could break out of the iteration once we have found two points (to speed the code up a bit):

mycircle1.each {|edge|
  point = Geom.intersect_line_line(mylinedef, edge.line)
  if myface1.classify_point(point) == Sketchup::Face::PointOnEdge
    end_pts << point
  end
  break if end_pts.size == 2
}

#6

Folks,
Thanks to all of you for your answers. Unfortunately, unexpected and pressing matters prevented me from coming back sooner, and frankly I don’t have the energy now, but tomorrow you will hear from me. Promise.


#7

Alright Folks,
I am back. Finally, a moment to catch up with this. Like it’s said, when it rains it pours, and more stuff came my way during the day. Sorry for the hiatus, but I guess today is still yesterday’s tomorrow, so I am still within the bounds of my promise. :rolling_eyes:
Thanks TIG, Steve and Dan for your priceless help.
Again, for the benefit of the community, I will be sharing some finding I dug while exploring some of the solutions proposed.


#8

TIG, your method will get me there, but I guess this time around for the sake of getting myself acquainted (which I sorely need) with the usage of vectors in Sketchup, I will go into the nuts-and-bolts using Steve’s and/or Dan’s solutions.
Thank you so much for your help.


#9

Steve,
You’re analytic-geometry lesson proved useful, as I was under the assumption that all vectors would have (as we learned in physics) a direction and a magnitude. So, I assumed that the resulting vector would have the magnitude (length) that would be determined by the size of the interception line. However, what I got was a unit-vector, which I had not expected, since the two intercepted surfaces were known finite quantities. However, I neglected the fact the surfaces’ planes from which the vector was calculated are just abstractions of the actual surface with seemly no specific magnitude either and (as you also explained) a dual personality.
Thank you.


#10

Dan, your code is quite interesting. I studied it carefully. At first I thought it would not be robust if the edges of one circle did not exactly lined up very well with the edges of the other circle as to create a visually verifiable interception. This situation could result from particular angles at which they could intercept, and/or from the circles having a different number of edges. Please, see the uploaded picture, where I created an extreme case of the second condition where one of the circles has far less edges than the other, as to resemble more a polygon than a circle. However, to my surprise, your code was still robust under such an extreme condition. I guess the construction of circles using edges, is just a visually satisfactory process to balance a visually acceptable representation with reasonable performance. Nonetheless, internally, it seems that as long as the entity has the identity of a circle, it is treated as such and satisfies all its mathematical properties, even if the visual representation does not offer us clues of the internal treatment. You know the heart of the beast. :thinking:
I did, however, ran into a bit of a wrinkle. When by chance, the interception of the circles at the edges brings one of the vertices of one circle very close to a vertex of the other, Sketchup will combine the two edges into a single one. That causes one of the adjacent edges to the vertex that was combined to break. In such case, the face of the circle whose edge was broken is voided or not formed. Perhaps, after an edge is broken Sketchup does not consider it a circle anymore. Please, see the second uploaded picture This problem can be fixed by changing the number of edges of one or both circles and hope for better luck.
Thanks also for the additional optimization of the code.



#11

It was just the simplest of solutions to the simplest of examples (the problem given in the original post.)

You’ll need to take it further for more extreme situations.[quote=“wisesketch, post:10, topic:42435”]
Nonetheless, internally, it seems that as long as the entity has the identity of a circle, it is treated as such and satisfies all its mathematical properties, even if the visual representation does not offer us clues of the internal treatment.
[/quote]

Well yes and no. They have some rudimentary properties of circles, (radius, diameter) but are (down deep) just polygons with x sides approximating circles. Ie, there are no true curves or circles in SketchUp.


#12

This topic was automatically closed after 91 days. New replies are no longer allowed.