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
Lines Crossing
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Livecode Opensource Backer
- Posts: 9388
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Lines Crossing
-
- Livecode Opensource Backer
- Posts: 9388
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Lines Crossing
With wiggly lines things get nasty as one has to determine which 2 line segments cross each other before performing that sort of operation.
-
- VIP Livecode Opensource Backer
- Posts: 9669
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Lines Crossing
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.
Craig
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.
Craig
-
- Livecode Opensource Backer
- Posts: 9388
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Lines Crossing
Cripes, I thought the chunky sweater I was wearing stopped them showing.you need to dumb down your points
Last edited by richmond62 on Thu Sep 27, 2018 9:23 pm, edited 1 time in total.
-
- VIP Livecode Opensource Backer
- Posts: 7237
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Lines Crossing
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
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 9669
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Lines Crossing
You know, I seem to remember this.the engine helpfully rounded them for me. Worth testing.
And it does indeed round to the nearest whole number. Convenient; likely little downside.
Craig
Re: Lines Crossing
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...
https://www.tutorialspoint.com/computer ... mation.htm
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