# Default code, use or delete...
model = Sketchup.active_model # Open model
entities = model.entities # All entities in model
selection = model.selection # Current selection
entities.clear!
#p1=[-0.625.m,-0.625.m,0.m]
p2=[-0.625.m,13.225.m,0.m]
p3=[6.3.m,6.3.m,0.m]
px11=[6.m,0.m,0.m]
vY=Geom::Vector3d.new(0,1,0)
#l1=[p1,p3]
l2=[p2,p3]
lx11=[px11,vY]
#lx11=[[6.m,0,0],[6.m,20.m,0]]
#cl1=entities.add_cline(p1,p3)
cl2=entities.add_cline(p2,p3)
clx11=entities.add_cline(px11,vY)
pn2_11=Geom.intersect_line_line(l2,lx11)
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 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 Geom::Point3d.new. Deined this way, the results are as expected.

@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!