RectShape Intersects Method???

[quote=155529:@Oliver Scott-Brown]Oh, so the method does not (on its own) determine whether they intersect but rather, whether they intersect across an infinite line?
[/quote]
If thinking about it this way works for you, then I guess so. By definition a line is infinite…

Please reread what I said:

[quote=155641:@Jason King]If thinking about it this way works for you, then I guess so. By definition a line is infinite…

Please reread what I said:[/quote]
But what I don’t understand is why it seems to return true in all circumstances. It might self not have a return value right? I must have done something wrong???

Unless you make the lines parallel with different intercepts, the code I posted will return true. You must examine the intersection point to determine where they intersect so that the code will do what you require.

With the lines in the above picture, should it return true?

Thanks

Those coordinates do not match the lines shown in the window… The coordinates in the window would intersect at (30,0). The lines shown in the window should return false however. You have taken coordinate geometry, right?

I don’t know what you mean by ‘you have taken coordinate geometry’? I have not taken any maths classes apart from basic GCSE maths if that’s what you mean?

I used this method but I have not done anything with the intersection point. I am just trying to make it so that it does not return false every time so when I make more changes I can test if it works.

Function Intersects(other as LineShape) As boolean
  dim Aslope as Double = (Y2 - Y1) / (X2 - X1)
  dim Bslope as Double = (other.Y2 - other.Y1) / (other.X2 - other.X1)
  
  dim AIntercept as Double = Y1 - Aslope * X1
  dim BIntercept as Double = other.Y1 - Bslope * other.X1
  
  if Aslope = Bslope then //parallel lines
    if AIntercept <> BIntercept then
      Return False
    else
      Return True
    end if
  end if
  
  dim XIntersection as Double = (BIntercept-AIntercept)/(Aslope-Bslope)
  dim YIntersection as Double = Aslope*XIntersection + AIntercept
  
  DIM intersectionPoint AS xojo.Core.Point
  intersectionPoint = new xojo.Core.Point(XIntersection,YIntersection)
  
  Return True
End Function

Thanks a lot for helping

I think this may be the problem. You do not seem to have the math background to understand what Dave and I have been saying. I would recommend that you do some research on the geometry of lines so that you can understand what the code is doing. Until then you won’t be able to modify it to make it work.

May I ask, what circumstances does that method return false? Also, what websites can I look at to interactively learn it. For example, might this site be of any use:
http://www.mathsisfun.com/geometry/line.html

[quote=155820:@Oliver Scott-Brown]Also, what websites can I look at to interactively learn it. For example, might this site be of any use:
http://www.mathsisfun.com/geometry/line.html [/quote]
Honestly there is no way to know how helpful that site will be for you, it all depends on how well you will learn from it. I have no idea what “basic GCSE math classes” are, here is the US we don’t have GCSE. I think if you study almost everything on plane geometry on that site you will probably understand it, just studying that page on lines won’t cut it, however. You need to understand how to determine when shapes intersect mathematically so that you can transform it into code. Everything you need to do that is here in this thread, by the way, you just need to do some studying before you understand it.

GCSE is the final step of Maths qualification before moving further into education (unless you move further into studying maths). So I do think have a decent grasp of maths.

I have done a bit of research and I can understand the words you are using. Do you where I could an interactive example of what this method does?

I have a feeling that the knowledge is there but I’m just not great with understanding. But we will get there. :slight_smile: I might go and get help from a mentor or something. I know somebody who offered to be my mentor who owns a successful business in the IT industry.

What is confusing me is:

  • The screenshot I did shows a parallel line that does not intercept at all but the method returns true anyway.

What I think I understand:

  • The method is suppose to return whether two infinite lines (not line segments) intersect.
  • The intersection point determines the X and Y position of where the two lines meet

Right now I am not questioning quadratic shape intersection but rather line intersection.

Thanks a lot for all the help

I think this guide on algorithms seems great for learning how all this works.

http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=geometry2

Thanks