Intersect_line_line problem


I have simple code like this:

# Default code, use or delete...
model = Sketchup.active_model # Open model
entities = model.entities # All entities in model
selection = model.selection # Current selection





cpn2_11=entities.add_cpoint pn2_11

The result point don’t lie on lines intersection. When i uncomment line: #lx11=[[6.m,0,0],[6.m,20.m,0]] the result is different but the line lx11 is theoreticaly the same.

Please tell me what i’m doing wrong.


Please put three backticks and the word ruby on a line before the code and three backticks on a separate line after the code. That way the forum’s formatter will present it cleanly.

Although a point and vector are [x,y,z] arrays, it makes a difference when defined this way or using the Deined this way, the results are as expected.,-0.625.m,0.m),13.225.m,0.m),6.3.m,0.m),0.m,0.m)

1 Like

@sdmitch is correct. You are falling victim to the Ruby API overloading Array to represent several flavors of Geometric objects: Point3d, Vector3d, and line (which has no explicit type of its own). Also, the API docs say that a line can have two different representations, but don’t explain the difference between these two representations!

So, when you create l2=[p2,p3] or add_cline(p2,p3) the API is taking both p2 and p3 to be Point3d. It thus creates a finite line segment joining those two points (which is technically not a line, which is supposed to be inifinite according to the docs!). But when you create lx11=[px11,vY] or add_cline(px11, vY), because vY is explicitly a Vector3d the API interprets it differently. It creates an infinite line consisting of all the points offset from px11 in the direction given by vY, that is all the points of the form p = px11 + k*vY, where k is a real multiplier.

Now, here’s the kicker: when you call Geom.intersect_line_line(l2, lx11), because l2 is really just an Array, it gets interpreted as if p3 is a Vector3d (remember, it is just an Array). If you explicitly create a Vector3d from p3 and add_cline(p2,v3) you will see that it passes exactly through the intersection point pn2_11!


Thank you very much. :slight_smile:

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