Post Reply 
(21S) The Intersection Point of a Quadrilateral
08-13-2017, 04:13 PM (This post was last modified: 08-13-2017 04:14 PM by Eddie W. Shore.)
Post: #1
(21S) The Intersection Point of a Quadrilateral
Original post: http://edspi31415.blogspot.com/2017/08/c...ction.html

This program calculates the coordinates of the center of quadrilateral. For the derivation, please see this link: http://edspi31415.blogspot.com/2017/08/g...nt-of.html

Input:

[Image: HP%2B21S%2Binput.jpg]


Program (the code and steps should be the same for the HP 20S):
Code:

Step    Code    Key
01    61, 41, A    LBL A
02    33    (
03    22, 3    RCL 3
04    65    -
05    22, 1    RCL 1
06    34    )
07    45    ÷
08    33    (
09    22, 2    RCL 2
10    65    -
11    22, 0    RCL 0
12    74    =
13    21, 8    RCL 8
14    55    *
15    22, 0    RCL 0
16    32    +/-
17    75    +
18    22, 1    RCL 1
19    74    =
20    21, 0    STO 9
21    33    (
22    22, 7    RCL 7
23    65    -
24    22, 5    RCL 5
25    34    )
26    45    ÷
27    33    (
28    22, 6    RCL 6
29    65    -
30    22, 4    RCL 4
31    34    )
32    74    =
33    21, 6    STO 6
34    55    *
35    22, 4    RCL 4
36    32    +/-
37    75    +
38    22, 5    RCL 5
39    74    =
40    21, 7    STO 7
41    33    (
42    22, 7    RCL 7
43    65    -
44    22, 9     RCL 9
45    34    )
46    45    ÷
47    33    (
48    22, 8    RCL 8
49    65    -
50    22, 6    RCL 6
51    74    =
52    21, 8    STO 8
53    26    R/S
54    55    *
55    22, 6    RCL 6
56    75    +
57    22, 7    RCL 7
58    74    =
59    21, 9    STO 9
60    61, 26    RTN


Variables – HP 21S:
Code:

Register    Input    Output
R0    A1    
R1    B1    
R2    C1    
R3    D1    
R4    A2    
R5    B2    
R6    C2    C’
R7    D2    D’
R8        X
R9        Y

Example

From top-left hand corner clockwise: (-1, 4), (4, 6), (5, -1), (0, 0)

Results:
X = 1.357142857
Y = 2.035714286
Visit this user's website Find all posts by this user
Quote this message in a reply
02-27-2021, 05:28 PM
Post: #2
RE: (21S) The Intersection Point of a Quadrilateral
(08-13-2017 04:13 PM)Eddie W. Shore Wrote:  This program calculates the coordinates of the center of quadrilateral. For the derivation, please see this link: http://edspi31415.blogspot.com/2017/08/g...nt-of.html

Instead of solving for slope (which may be infinite), then solve for intersection P, we can use vectors.

Let quadrilateral vertices be A,B,C,D, P = intersection of diagonals AC, BD

P = A + k*(C-A) = B + k2*(D-B)       // for some values of k, k2, both between 0 to 1

k*(C-A) + k2*(B-D) = B-A

Let coordinates of A,B,C,D = (x1,y1), (x2,y2), (x3,y3), (x4,y4):

k*(x3-x1) + k2*(x2-x4) = x2-x1
k*(y3-y1) + k2*(y2-y4) = y2-y1

Apply Cramers rules, solve for k:

k = det([[x2-x1,x2-x4],[y2-y1,y2-y4]]) / det([[x3-x1,x2-x4],[y3-y1,y2-y4]])

Quote:From top-left hand corner clockwise: (-1, 4), (4, 6), (5, -1), (0, 0)

Results:
X = 1.357142857
Y = 2.035714286

With D = (x4, y4) = (0,0), k simplified greatly:

k = det([[x1,y1], [x2,y2]]) / det([[x1-x3,y1-y3], [x2,y2]])

lua> x, y = {-1,4,5}, {4,6,-1}                         -- points A, B, C only
lua> k = (x[1]*y[2]-y[1]*x[2]) / ((x[1]-x[3])*y[2] - (y[1]-y[3])*x[2])
lua> k
0.39285714285714285
lua> x[1]+k*(x[3]-x[1]), y[1]+k*(y[3]-y[1])    -- P = A + k*(C-A)
1.3571428571428572       2.0357142857142856
Find all posts by this user
Quote this message in a reply
03-02-2021, 03:27 PM (This post was last modified: 03-02-2021 03:28 PM by Albert Chan.)
Post: #3
RE: (21S) The Intersection Point of a Quadrilateral
(02-27-2021 05:28 PM)Albert Chan Wrote:  Let quadrilateral vertices be A,B,C,D, P = intersection of diagonals AC, BD

P = A + k*(C-A) = B + k2*(D-B)       // for some values of k, k2, both between 0 to 1

k*(C-A) + k2*(B-D) = B-A

Previous post had D = (0,0), to simplify calculations.
If we instead let A = (0,0), it simplified more:

k*C + k2*(B-D) = B

Redo previous example, using complex numbers.

lua> I = require'complex'.I
lua> function det(z1,z2) return z1:real()*z2:imag() - z1:imag()*z2:real() end

lua> B, C, D = -1+4*I, 4+6*I, 5-I       -- assumed A = 0
lua> P = det(D,B) / det(C,B-D) * C      -- det(B,B-D) = det(B,B) - det(B,D) = det(D,B)
lua> P:real(), P:imag()
1.3571428571428572       2.0357142857142856
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)