Re: Intersect Function

2018-09-24 Thread dunbarxx via use-livecode
I believe the OP was talking about two arbitrary  lines, likely graphic
objects, that intersect each other. Not rectangles with points within them,
or two rectangles.

I think the only way to do this is as per the first four posts in this
thread.

Craig



--
Sent from: 
http://runtime-revolution.278305.n4.nabble.com/Revolution-User-f278306.html

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Intersect Function

2018-09-24 Thread hh via use-livecode
> Jerry J. wrote:
> I think he mentioned curved “lines”. That is a
> whole other kettle of fish.

The OP speaks of "functions for the lines", so
either he means "math lines" or, as you say,
continuous curves, say polynomials.

Yes, this isn't solvable for polynomials of higher
degree by formulas (not because mathematicians
didn't find the formula, to the contrary, it
is proved that there is no formula for that).

So the solution is a numerical one, finding the
roots of (say for simplicity) polynomials.
There are several fast algorithms for that.
One of the simplest (and usually fast enough)
is the Newton-Raphson method.

https://en.wikipedia.org/wiki/Newton%27s_method

A trial and error method as proposed by Craig may
be good enough for very simple curves. This is
also a (good) pragmatic approach.

On the other hand the Newton-Raphson method is
simple to script.

https://en.wikipedia.org/wiki/Newton%27s_method

As LC can not differentiate, you have to do that
by yourself before applying it.

[For non-math people:
The intersection point of two functions is a
root finding problem, because searching the point
x where f1(x)=f1(x) is the same as finding the
"root" (zero point g(x)=0) of g(x)= f1(x)-f2(x).]



___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: Intersect Function

2018-09-24 Thread Richmond Mathewson via use-livecode
It is, and INTERSECT with them is just a distraction. Probably time (shock,
horror) to do some Mathematics.

On Mon, Sep 24, 2018, 11:36 PM Jerry Jensen via use-livecode <
use-livecode@lists.runrev.com> wrote:

> I think he mentioned curved “lines”. That is a whole other kettle of fish.
> .Jerry
>
> > On Sep 24, 2018, at 9:23 AM, hh via use-livecode <
> use-livecode@lists.runrev.com> wrote:
> >
> > It is not this complicated. Only if you are looking for
> > the intersection of two line *segments* you have do a
> > few more checks.
>
>
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: Intersect Function

2018-09-24 Thread Richmond Mathewson via use-livecode
One could have a line consisting of a graphic object (rectangle) with a
width of one. ?

On Mon, Sep 24, 2018, 10:17 PM hh via use-livecode <
use-livecode@lists.runrev.com> wrote:

> @Richmond.
>
> You (and the author) overlooked that we have, since 1.0,
>  is within .
>
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Intersect Function

2018-09-24 Thread Jerry Jensen via use-livecode
I think he mentioned curved “lines”. That is a whole other kettle of fish.
.Jerry

> On Sep 24, 2018, at 9:23 AM, hh via use-livecode 
>  wrote:
> 
> It is not this complicated. Only if you are looking for
> the intersection of two line *segments* you have do a
> few more checks.


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: Intersect Function

2018-09-24 Thread hh via use-livecode
@Richmond.

You (and the author) overlooked that we have, since 1.0,
 is within .

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Intersect Function

2018-09-24 Thread Richmond Mathewson via use-livecode
I found THIS in the User contributed notes in the 7.1.4 documentation 
from 2009:


"The intersect() command takes two objects as inputs. In some 
situations, it may be useful to find the intersect of a point and a 
rectangle. The custom function below may be used in those cases:


function pointIntersect pPoint,pRect
   split pPoint by comma
   split pRect by comma
   return ((pRect[1] <= pPoint[1]) and (pPoint[1] <= pRect[3]) and 
(pRect[2] <= pPoint[2]) and (pPoint[2] <= pRect[4]))

end pointIntersect

Examples:
pointIntersect(the mouseLoc, the rectangle of stack "MyStack")
pointIntersect(the clickLoc, the rect of img "Splash")

Use the pointIntersect function to determine whether a point is within a 
specified rectangle.


Parameters:
The pPoint is an expression that evaluates to a point.
The pRect is a rectangle consisting of four integers separated by commas.

Value:
The pointIntersect function returns true or false.

Comments:
The pointIntersect function does not differentiate between screen 
coordinates and window coordinations.
This means that if the point is screen-relative, such as a mouseLoc, and 
the rectangle is window-relative,
such as an object's rectangle, the pointIntersect function does not 
return a reliable result."


This is NOT mine, so I can take no credit for it.

Richmond.

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Intersect Function

2018-09-24 Thread hh via use-livecode
It is not this complicated. Only if you are looking for
the intersection of two line *segments* you have do a
few more checks.

A LC object "line" is a line segment given by two pairs
of points (x,y).
The OP probably mean with line the math object line that is
given by and passing through these pair of points.

For example to get the intersection of two lines (if not
parallel) this works here.

-- pts1 = two lines of points from the first LC-"line"
-- pts2 = two lines of points from the second LC-"line"
function lineIntersection pts1,pts2
  put pts1 & pts2 into p
  repeat with i=1 to 4
put item 1 of line i of p into x[i]
put item 2 of line i of p into y[i]
  end repeat
  put (y[4]-y[3])*(x[2]-x[1]) \
 - (y[2]-y[1])*(x[4]-x[3]) into d
  if abs(d) < 0.1 then
return "parallel"
  else
put (x[4]-x[3])*(x[2]*y[1]-x[1]*y[2]) \
  - (x[2]-x[1])*(x[4]*y[3]-x[3]*y[4]) into xn
put (y[1]-y[2])*(x[4]*y[3]-x[3]*y[4]) \
  - (y[3]-y[4])*(x[2]*y[1]-x[1]*y[2]) into yn
  end if
  return format ("%0.3f,%0.3f", xn/d, yn/d)
end lineIntersection

on mouseUp
  put the points of grc 1 into p1
  put the points of grc 2 into p2
  if there is no grc "ip" then
create grc "ip"
set style of grc "ip" to "oval"
set rect of grc "ip" to (0,0,10,10)
set foreColor of grc "ip" to "255,0,0"
set lineSize of grc "ip" to 1 
  end if
  put lineIntersection(p1,p2) into ip
  put ip into fld "info"
  if ip is not "parallel" then
set loc of grc "ip" to \
  round(item 1 of ip),round(item 2 of ip)
  end if
end mouseUp


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Intersect Function

2018-09-24 Thread dunbarxx via use-livecode
Well and good.

I repeat that in a computer screen, with fixed pixel coordinates, you will
likely need just a bit of rounding forgiveness when doing the math. You need
to write a bit of code, in other words, that will accept close matches
between the string of pixels and the calculated "points" along the line.

Craig



--
Sent from: 
http://runtime-revolution.278305.n4.nabble.com/Revolution-User-f278306.html

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Intersect Function

2018-09-24 Thread Beat Cornaz via use-livecode
Thanks Craig, I was already afraid of that. Yes, I guess I could figure out
the math. I will have the 2 functions of the lines and if I set them equal,
I could solve the intersection point of the two. Your way is also valid,
but as I need to determine many intersection points, the script might get
slow. Of course your way might prove better if we're looking at curves. The
amount of points in a curved line increases some in comparison to a
straight line, but in setting the functions equal, I'd have to deal with
quadratic functions. It just comes to me, that that is quite doable : move
everything to one side of the equal sign and apply the famous 'abc formula'
(at least that it was called in my high school years in Holland). It's used
to solve a quadratic equation. Once the 'x' is known, I can put it into one
of the functions to get the 'y' coordinate. I will see what goes faster.

Cheers, Beat

On Mon, Sep 24, 2018 at 3:15 PM dunbarxx via use-livecode <
use-livecode@lists.runrev.com> wrote:

> Hi.
>
> No.
>
> But you can determine the points of a line graphic, and calculate all the
> pixels it "contains" from its starting point to its ending point. Do the
> same for a second line.
>
> Then you can determine the point that seems to be common to both lines. I
> say seems, because when you do the math, that is, using the slope of each
> line and calculating the points using that information, you may find that
> there are no exact matches. But you can allow a small differential, and the
> closest pair of points will be the one you want.
>
> Can you do the math?
>
> Craig Newman
>
>
>
> --
> Sent from:
> http://runtime-revolution.278305.n4.nabble.com/Revolution-User-f278306.html
>
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Intersect Function

2018-09-24 Thread dunbarxx via use-livecode
Hi.

No.

But you can determine the points of a line graphic, and calculate all the
pixels it "contains" from its starting point to its ending point. Do the
same for a second line.

Then you can determine the point that seems to be common to both lines. I
say seems, because when you do the math, that is, using the slope of each
line and calculating the points using that information, you may find that
there are no exact matches. But you can allow a small differential, and the
closest pair of points will be the one you want.

Can you do the math?

Craig Newman



--
Sent from: 
http://runtime-revolution.278305.n4.nabble.com/Revolution-User-f278306.html

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Intersect Function

2018-09-24 Thread Beat Cornaz via use-livecode
Is there a function to determine the intersection point (x,y) of two lines?
The intersect function in LC only gives me a true or false, and I need the
exact location (x,y) of the intersection.

Thanks, Beat
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode