Lines Crossing

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9387
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Lines Crossing

Post by richmond62 » Tue Sep 25, 2018 6:55 pm

on mouseUp
put item 1 of the topleft of grc "g1" into X1
put "x1 = " & X1 into line 1 of fld "fPOINTS"
----------
put item 2 of the topleft of grc "g1" into Y1
put "y1 = " & Y1 into line 2 of fld "fPOINTS"
----------
put item 1 of the bottomright of grc "g1" into X2
put "x2 = " & X2 into line 3 of fld "fPOINTS"
----------
put item 2 of the bottomright of grc "g1" into Y2
put "y2 = " & Y2 into line 4 of fld "fPOINTS"
----------
----------
put item 1 of the bottomleft of grc "g2" into X3
put "x3 = " & X3 into line 5 of fld "fPOINTS"
----------
put item 2 of the bottomleft of grc "g2" into Y3
put "y3 = " & Y3 into line 6 of fld "fPOINTS"
----------
put item 1 of the topright of grc "g2" into X4
put "x4 = " & X4 into line 7 of fld "fPOINTS"
----------
put item 2 of the topright of grc "g2" into Y4
put "y4 = " & Y4 into line 8 of fld "fPOINTS"
----------
-- Heavy Lifting Starts Here
----------
put (((X1*Y2)-(Y1*X2))*(X3-X4)) into P1
put (((X3*Y4)-(Y3*X4))*(X1-X2)) into P2
put ((X1-X2)*(Y3-Y4)) into P3
put ((Y1-Y2)*(X3-X4)) into P4
put (P1-P2)/(P3-P4) into XX
--------------
put (((X1*Y2)-(Y1*X2))*(Y3-Y4)) into Q1
put (((X3*Y4)-(Y3*X4))*(Y1-Y2)) into Q2
put (Q1-Q2)/(P3-P4) into YY
--------------
put "Lines intersect at " & XX & "," & YY into fld "OOT"
end mouseUp
Intersection.png
INTERSECTIONS1.livecode.zip
Here's the stack.
(1.59 KiB) Downloaded 196 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9387
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Lines Crossing

Post by richmond62 » Tue Sep 25, 2018 6:58 pm

With wiggly lines things get nasty as one has to determine which 2 line segments cross each other before performing that sort of operation.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9663
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Lines Crossing

Post by dunbarx » Tue Sep 25, 2018 7:52 pm

Richmond.

Mostly good. But go back to the thread that started all this. When you do the math, like you did, you get points to six decimal places, assuming you do not touch the numberFormat. You must, and it is a little thing to do, find the nearest intersecting pixel.

Pixels are fixed, er, points on screen. Points are mathematical objects. In order to use them later, unless this is just a math exercise instead of a programming one, you need to dumb down your points. :wink:

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9387
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Lines Crossing

Post by richmond62 » Tue Sep 25, 2018 8:11 pm

you need to dumb down your points
Cripes, I thought the chunky sweater I was wearing stopped them showing. 8)
Last edited by richmond62 on Thu Sep 27, 2018 9:23 pm, edited 1 time in total.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7237
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Lines Crossing

Post by jacque » Wed Sep 26, 2018 5:48 pm

If I remember right, the last time I had to deal with fractional points the engine helpfully rounded them for me. Worth testing.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9663
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Lines Crossing

Post by dunbarx » Wed Sep 26, 2018 7:03 pm

the engine helpfully rounded them for me. Worth testing.
You know, I seem to remember this.

And it does indeed round to the nearest whole number. Convenient; likely little downside.

Craig

capellan
Posts: 654
Joined: Wed Aug 15, 2007 11:09 pm

Re: Lines Crossing

Post by capellan » Thu Sep 27, 2018 9:27 pm

Hi All,

For beginners that are reading this forum thread,
I just want to remember you something obvious
for anyone who had worked before
with vector graphics:

The actual graphic, (the real graphic) is made of
coordinates with large decimal points. Coordinates
like these:

371.142785,164.376481
35.274689,287.410245

The graphics that you see on the screen, are draw
using plain coordinates like these:

371,164
35,287

When you apply 2D Transformation to vector graphics,
math operations like scale, rotation, translation, shearing,
reflection, perspective, etc. always, always, always
create, use and store coordinates with large decimal points,
like these:

371.142785,164.376481
35.274689,287.410245

For example, if you receive these coordinates:
371,164
35,287

convert them to:
371.000000,164.000000
35.000000,287.000000

using the numberformat function...

Code: Select all

put 371 into x1
set the numberformat to "#.000000"
put x1 * 1 into x1
put x1 -- x1 now contains 371.000000
https://www.tutorialspoint.com/computer ... mation.htm

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”