Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Revisions

4 of 5
added 6 characters in body
Rosario
  • 1.7k
  • 5
  • 9

APL(NARS), 153 chars

{M←⊃{⍵,(×ばつ/⍵),⍵*2} ̈q←⍵∼⊂0 0⋄v←5⍴1⋄(M v)←{q≡⍵:M v⋄(0 1↓M)M[;1]}⍵⋄(b c a)← ×ばつ1x⋄(b=0)∧a=c:'circle'⋄0>t←(b*2)×ばつa×ばつc:'ellipse'⋄0<t:'hyperbola'⋄'parabola'}
 

Input should be choosen in the way matrix coefficients is square and its determinat is different of 0.

For me there are 2 cases, case 1 there is no (0 0) in the argument data points, case 2 there is 1 (0 0) in argument data points. The book formula for general conic is below, but I modify something in the hope that not change the determinant (b*2)×ばつa×ばつc.

Ax^2+Cy^2+Bxy+Dx+Ey+F=0

For case 1 for build the matrix M I use this formula below, where v=(1 1 1 1 1)

Ax^2+Cy^2+Bxy+Dx+Ey=1

For case 2 for build the matrix M I use this formula below, where v=(y)=(the second coordinate 4 points)

Ax^2+Cy^2+Bxy+Dx =y

For find "A C B" I use ̄3↑v⌹M. I use rationals for the hope of not have round errors, multiply the matrix M for rational 1 1x, in ×ばつ1x.

test:

 f←{M←⊃{⍵,(×ばつ/⍵),⍵*2} ̈q←⍵∼⊂0 0⋄v←5⍴1⋄(M v)←{q≡⍵:M v⋄(0 1↓M)M[;1]}⍵⋄(b c a)← ×ばつ1x⋄(b=0)∧a=c:'circle'⋄0>t←(b*2)×ばつa×ばつc:'ellipse'⋄0<t:'hyperbola'⋄'parabola'}
 
 f (1 0)(0 1)(0.5 0.5)(0.3 0.7)(4 9)
hyperbola
 f (1.2 5.3)(4.1 5.6)(9.1 2.5)(0 1)(4.2 0)
ellipse
 f (5 0)(4 3)(3 4)(0 5)(0 ̄5)
circle
 f (1 0)(0 1)(2 1)(3 4)(4 9)
parabola
 f ( ̄1 4)(2 2)(6 4)( ̄3 2)(2 5)
ellipse
 f (0 0)(1 5)(2 3)(4 8)(9 2) 
hyperbola
 f (5 9)( ̄4 ̄3)(2 4)(8 13)( ̄1 1)
DOMAIN ERROR
 f (5 9)( ̄4 ̄3)(2 4)(8 13)( ̄1 1)
 ∧
Rosario
  • 1.7k
  • 5
  • 9

AltStyle によって変換されたページ (->オリジナル) /