intersection in 2D

i tried to use the mathutil intersection

but i get error

can someone point me out in the right direction!

the error is on the last line for the interceotion itself

values for the First lines 2 vertices

vec1=[2.25-4,1.571,0]
vec2=[50,-31,0]

values for the second lines 2 vertices

vec3=[4,0,0]
vec4=[10,-12,0]

print ‘vec1=’,vec1
print ‘vec2=’,vec2
print ‘vec3=’,vec3
print ‘vec4=’,vec4
print

############# error on this line
print ’ intersect = ',LineIntersect(vec1, vec2, vec3, vec4)

it does not see the 4 vectors ?

may be this is anotther way to write this line to get the interception
and then how to extract the 2 values X and Y?

Thanks

Well, if you read the documentation on the LineIntersect() function you will see that each vector passed in is supposed to be a 3D Vector object. Not just a list of points. Try something like this…


# values for the First lines   2 vertices
vec1=Vector([2.25-4,1.571,0])
vec2=Vector([50,-31,0])
# values for the second lines   2 vertices
vec3=Vector([4,0,0])
vec4=Vector([10,-12,0])
 
print 'vec1=',vec1 
print 'vec2=',vec2 
print 'vec3=',vec3
print 'vec4=',vec4
print
 
############# error on this line
print  ' intersect =  ',LineIntersect(vec1, vec2, vec3, vec4) 

Does that make sense?

i forgot to include the parenthesis!

seems to work now!

now did you work with this intercept

i mean does the 2 lines have to intercept or
it can estimates where it’s going to intercept too ?

i have this case where one of the line1 might not cut the other line2
but i need to find the interception

i could extend it to cut the line2 but would prefer not cause that would limit otherthings
in the script

Thanks

Look here http://www.zoo-logique.org/3D.Blender/scripts_python/API/Mathutils-module.html#LineIntersect
If that is the module you’re working with, this explanation is quite clear to me. The two finite lines specified by the 4 vectors as start and endpoints do not have to actually intersect each other, as they are treated as infinite lines by the function.

Or, you can always test that, can’t you? I did not try the function now so it might be that it works differently for you, but usually you can trust the docs.

ok i did read the beginning

that’s a very good function

like it you can extrapoalte the line- very good

now i still get the error on the lieintercep

i tried it that way

values for the First lines 2 vertices

vec1=([2.25-4,1.571,0])
vec2=([50,-31,0])

values for the second lines 2 vertices

vec3=([4,0,0])
vec4=([10,-12,0])

error here for this line

z1,z2=LineIntersect([vec1, vec2, vec3, vec4])

and does not recognise tghe vector but an print theses

what did i do wrong with this last line to call the liintercep?

Thanks

In my first posting i did not just add parenthesis, i created a Vector Object! The description of the LineIntersect() function states it needs Vector objects! Look back at my first post and look closer at the code.

so to declare a vector you need to add the word vector before the list!

now it’s working nicely

Thanks

Its not that you just put the word vector, by doing that you are passing that list into the constructor of the Vector Object that is in the mathutil library.