How to resolve the algorithm Circles of given radius through two points step by step in the J programming language

Published on 12 May 2024 09:40 PM
#J

How to resolve the algorithm Circles of given radius through two points step by step in the J programming language

Table of Contents

Problem Statement

Given two points on a plane and a radius, usually two circles of given radius can be drawn through the points.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Circles of given radius through two points step by step in the J programming language

Source code in the j programming language

average =: +/ % #

circles =: verb define"1
 'P0 P1 R' =. (j./"1)_2[\y NB. Use complex plane
 C =. P0 average@:, P1
 BAD =: ":@:+. C
 SEPARATION =. P0 |@- P1
 if. 0 = SEPARATION do.
  if. 0 = R do. 'Degenerate point at ' , BAD
  else. 'Any center at a distance ' , (":R) , ' from ' , BAD , ' works.'
  end.
 elseif. SEPARATION (> +:) R do. 'No solutions.'
 elseif. SEPARATION (= +:) R do. 'Duplicate solutions with center at ' , BAD
 elseif. 1 do.
  ORTHOGONAL_DISTANCE =. R * 1 o. _2 o. R %~ | C - P0
  UNIT =: P1 *@:- P0
  OFFSETS =: ORTHOGONAL_DISTANCE * UNIT * j. _1 1
  C +.@:+ OFFSETS
 end.
)

INPUT=: ".;._2]0 :0
 0.1234 0.9876 0.8765 0.2345   2
      0      2      0      0   1
 0.1234 0.9876 0.1234 0.9876   2
 0.1234 0.9876 0.8765 0.2345 0.5
 0.1234 0.9876 0.1234 0.9876   0
)

   ('x0 y0 x1 y1 r' ; 'center'),(;circles)"1 INPUT
┌───────────────────────────────┬────────────────────────────────────────────────────┐
│x0 y0 x1 y1 r                  │center                                              │
├───────────────────────────────┼────────────────────────────────────────────────────┤
0.1234 0.9876 0.8765 0.2345 2_0.863212 _0.752112
│                               │  1.86311   1.97421
├───────────────────────────────┼────────────────────────────────────────────────────┤
0 2 0 0 1                      │Duplicate solutions with center at 0 1
├───────────────────────────────┼────────────────────────────────────────────────────┤
0.1234 0.9876 0.1234 0.9876 2  │Any center at a distance 2 from 0.1234 0.9876 works.
├───────────────────────────────┼────────────────────────────────────────────────────┤
0.1234 0.9876 0.8765 0.2345 0.5│No solutions.
├───────────────────────────────┼────────────────────────────────────────────────────┤
0.1234 0.9876 0.1234 0.9876 0  │Degenerate point at 0.1234 0.9876
└───────────────────────────────┴────────────────────────────────────────────────────┘


  

You may also check:How to resolve the algorithm Fibonacci n-step number sequences step by step in the PHP programming language
You may also check:How to resolve the algorithm Password generator step by step in the Java programming language
You may also check:How to resolve the algorithm Fairshare between two and more step by step in the Go programming language
You may also check:How to resolve the algorithm SEDOLs step by step in the COBOL programming language
You may also check:How to resolve the algorithm Collections step by step in the Forth programming language