Post Reply 
(42S) Determine Circle From Three Given Points
07-15-2018, 04:38 PM (This post was last modified: 07-15-2018 04:45 PM by Dieter.)
Post: #2
RE: (42S) Determine Circle From Three Given Points
(07-15-2018 08:43 AM)gerry_in_polo Wrote:  Calculates the center and radius of the circle passing through three given points. Example, enter X1=1, Y1=4, X2=-1, Y2=2, X3=4, Y3=-3. Result, center (Xc,Yc)=(2.5,0.5) and radius R=3.8079.

Thank you very much for your program. This problem, solving a circle through three given points, reminds me of the early days with my first programmable calculator, a 34C. I had a HP67/97 book which included auch a program, and I tried to adapt it for the 34C.

Essentially the problem boils down to solving a linear equation system with three unknowns. In matrix notation it can be written this way:

Code:
(x1  y1  -1)     (2*xc          )     (x1² + y1²)
(x2  y2  -1)  *  (2*yc          )  =  (x2² + y2²)
(x3  y3  -1)     (xc² + yc² - r²)     (x3² + y3²)

Since the 42s features matrix support, this approach can be implemented in a quite compact program. So here is my alternative solution:

Code:
00 { 184-Byte Prgm }
01>LBL "CIRCLE"
02 3
03 ENTER
04 NEWMAT
05 STO "C"
06 3
07 ENTER
08 1
09 NEWMAT
10 STO "B"
11 1.003
12 STO 00
13>LBL 00
14 INDEX "C"
15 RCL 00
16 "X"
17 AIP
18 |-"^Y"
19 AIP
20 |-"?"
21 1
22 STOIJ
23 PROMPT
24 X<>Y
25 STOEL
26 J+
27 X^2
28 X<>Y
29 STOEL
30 J+
31 X^2
32 +
33 -1
34 STOEL
35 INDEX "B"
36 RCL 00
37 1
38 STOIJ
39 R^
40 STOEL
41 ISG 00
42 GTO 00
43 RCL "B"
44 RCL "C"
45 ÷
46 STO "X"
47 INDEX "X"
48 RCLEL
49 2
50 ÷
51 STO "XC"
52 X^2
53 I+
54 RCLEL
55 2
56 ÷
57 STO "YC"
58 X^2
59 +
60 I+
61 RCLEL
62 -
63 SQRT
64 STO "R"
65 CLV "B"
66 CLV "C"
67 CLV "X"
68 "Xc=\LF   "
69 ARCL "XC"
70 AVIEW
71 STOP
72 "Yc=\LF   "
73 ARCL "YC"
74 AVIEW
75 STOP
76 "R=\LF   "
77 ARCL "R"
78 AVIEW
79 END

Note: "|-" means "append", "^" is "↑" and "\LF" is a line feed.

Your example:

Code:
XEQ "CIRCLE"
X1↑Y^1?
           1  [ENTER]  4 [R/S]
X2↑Y^2?
          -1  [ENTER]  2 [R/S]
X3↑Y^3?
           4  [ENTER] -3 [R/S]
Xc=
   2,5
              [R/S]
Yc=
   0,5
              [R/S]
R=
   3,807786...

Since I am not very familiar with 42s matrix programming the program can probably be improved with more efficient code. So if someone can provide a better version: go ahead.

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (42S) Determine Circle From Three Given Points - Dieter - 07-15-2018 04:38 PM



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