Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #13193

Re: intersection of circles

From mhx@iae.nl (Marcel Hendrix)
Subject Re: intersection of circles
Newsgroups comp.lang.forth
Message-ID <93099112978435@frunobulax.edu> (permalink)
Date 2012-06-23 12:26 +0200
References <3086ada2-f554-4193-9a69-cacabe8be1ba@h20g2000yqe.googlegroups.com>
Organization Wanadoo

Show all headers | View raw


Krishna Myneni <krishna.myneni@ccreweb.org> writes Re: intersection of circles

> Surprisingly, the following problem isn't easily handled by a couple
> of scientific computing packages:

> If solution(s) exist, find the intersection points of two circles in
> the x-y plane. This requires solving a system of two quadratic
> equations in two variables:

> 1)  (x - a)^2 + (y - b)^2 = r1^2

> 2)  (x - c)^2 + (y - d)^2 = r2^2

I guess 'requires' should be 'could be done by'?

> where the points (a, b) and (c, d) are the centers of two circles of
> radii r1 and r2.

[..]

-marcel

-- ------------------

0e FVALUE a    0e FVALUE b    0e FVALUE r1  
0e FVALUE c    0e FVALUE d    0e FVALUE r2  

0e FVALUE alpha  
0e FVALUE beta   

-- Shift a,b to origin, then rotate c-a, d-b to x-axis  
: transform-> ( -- )
	d b F- FSQR  c a F- FSQR F+ FSQRT TO alpha
	d b F-       c a F- FATAN2        TO beta ; 

: solution' ( F: -- x y )
	alpha F0= ABORT" SOLUTION' :: The origins of the circles should be distinct"
	r1 FSQR  r2 FSQR F- alpha FSQR F+   alpha F2* F/ ( F: -- x )
	r1 FSQR  FOVER FSQR F- FDUP F0< ABORT" SOLUTION' :: the circles do not touch" FSQRT ; 

: transform<- ( F: x y -- x1 y1 x2 y2 )
	F2DUP FSWAP FATAN2       FLOCAL gamma
	FSQR FSWAP FSQR F+ FSQRT FLOCAL rr 
	beta gamma F+ FSINCOS rr F* a F+  FSWAP rr F* b F+
	beta gamma F- FSINCOS rr F* a F+  FSWAP rr F* b F+ ; 

: 2CIRCLES ( a b r1  c d r2 -- x1 y1 x2 y2 )
	TO r2 TO d TO c  TO r1 TO b TO a
	transform-> solution' transform<- ;

        A few results:

	FORTH> 0e 0e 1e  0.5e 0.5e 1e    2CIRCLES f2swap fswap f. f. fswap f. f.  -0.411438 0.911438 0.911438 -0.411438  ok
	FORTH> 0e 0e 1e  0.5e 1e   1e    2CIRCLES f2swap fswap f. f. fswap f. f.  -0.491620 0.870810 0.991620  0.129190  ok
	FORTH> 0e 0e 1e  0.5e 0e   1e    2CIRCLES f2swap fswap f. f. fswap f. f.   0.250000 0.968246 0.250000 -0.968246  ok
	FORTH> 0e 0e 1e  0.5e 0e   0.25e 2CIRCLES f2swap fswap f. f. fswap f. f.
	**** RETURN STACK DUMP ****
		SOLUTION'                                                  (+$000000BE)
		2CIRCLES                                                   (+$000000C9)
	Error -2
	SOLUTION' :: the circles do not touch ?
	FORTH> 0e 0e   0.5e 1e    0e   0.5e 2CIRCLES f2swap fswap f. f. fswap f. f.   0.500000  0.000000  0.500000  0.000000  ok
	FORTH> 0e 0e   1e   0.5e  0e   1e   2CIRCLES f2swap fswap f. f. fswap f. f.   0.250000  0.968246  0.250000 -0.968246  ok
	FORTH> 0e 0e   1e  -0.5e  0e   1e   2CIRCLES f2swap fswap f. f. fswap f. f.  -0.250000 -0.968246 -0.250000  0.968246  ok
	FORTH> 0e 0e   1e  -0.5e  0.5e 1e   2CIRCLES f2swap fswap f. f. fswap f. f.  -0.911438 -0.411438  0.411438  0.911438  ok
	FORTH> 0e 0e   1e  -0.5e -0.5e 1e   2CIRCLES f2swap fswap f. f. fswap f. f.   0.411438 -0.911438 -0.911438  0.411438  ok
	FORTH> 0e 0e   1e   0.5e -0.5e 1e   2CIRCLES f2swap fswap f. f. fswap f. f.   0.911438  0.411438 -0.411438 -0.911438  ok
	FORTH> 0e 0.1e 1e   0.5e -0.5e 1e   2CIRCLES f2swap fswap f. f. fswap f. f.   0.957223  0.389352 -0.457223 -0.789352  ok

Back to comp.lang.forth | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

intersection of circles Krishna Myneni <krishna.myneni@ccreweb.org> - 2012-06-22 17:31 -0700
  Re: intersection of circles mhx@iae.nl (Marcel Hendrix) - 2012-06-23 12:26 +0200
    Re: intersection of circles Krishna Myneni <krishna.myneni@ccreweb.org> - 2012-06-23 04:24 -0700
  Re: intersection of circles Krishna Myneni <krishna.myneni@ccreweb.org> - 2012-06-23 04:28 -0700
  Re: intersection of circles Bernd Paysan <bernd.paysan@gmx.de> - 2012-06-23 22:12 +0200
    Re: intersection of circles Krishna Myneni <krishna.myneni@ccreweb.org> - 2012-06-23 16:06 -0700
      Re: intersection of circles Bernd Paysan <bernd.paysan@gmx.de> - 2012-06-24 02:11 +0200

csiph-web