超急!!跪求˙FORTRAN高手大人解題!!小弟我痛哭流涕!

利用這三個點算出圓的公式。

圖片參考:http://2.bp.blogspot.com/_rl4Ib9jDesQ/SRt1YrYS-aI/...

假設讀取點為 P1、P2、P3,在這裡的算法是求出兩條分別垂直於P1P2連線與P1P3連線的直線方程式,L12與L13,如上圖所示。

求L12時,先求出P1P2連線的中點,再求出L12的斜率。

中點座標分別為 C12x = (P1x+P2x)/2, C12y = (P1y+P2y)/2,

斜率為 m12 = -(P2x-P1x)/(P2y-P1y)。

所以 L12 的直線公式為 y = m12 * (x - C12x) + C12y

L13 的計算方式類似,L13 的直線公式為 y = m13 * (x - C13x) + C13y

這時就可以求L12與L13兩條線的交點,這個交點 C 就是圓心。

求解L12與L13 聯立方程式,得圓心座標(x, y)

x = (C13y-C12y-m13*C13x+m12*C12x) / (m12-m13)

y = m12 * (x-C12x) + C12y

http://using-c.blogspot.com/2008/11/problem-190-ci... <----原始題目

搞了很久~打不出來QQ~~拜託大大解惑><(有詳解佳)

1 個解答

評分
  • Jack
    Lv 5
    10 年前
    最佳解答

    程式如下: program main

    implicit none

    character*1 signx, signy

    real*4 x1, y1, x2, y2, x3, y3, m12, m13, temp, c12x, c12y, c13x, c13y, cx, cy, r2

    1 write (*, "(/' Enter x1, y1: ', $)")

    read (*, *) x1, y1

    write (*, "(' Enter x2, y2: ', $)")

    read (*, *) x2, y2

    write (*, "(' Enter x3, y3: ', $)")

    read (*, *) x3, y3

    if (y2 == y1) then

    temp = x1

    x1 = x3

    x3 = temp

    temp = y1

    y1 = y3

    y3 = temp

    else if (y3 == y1) then

    temp = x1

    x1 = x2

    x2 = temp

    temp = y1

    y1 = y2

    y2 = temp

    end if

    m12 = -(x2-x1)/(y2-y1)

    m13 = -(x3-x1)/(y3-y1)

    c12x = (x1+x2)/2.

    c12y = (y1+y2)/2.

    c13x = (x1+x3)/2.

    c13y = (y1+y3)/2.

    cx = (c13y-c12y-m13*c13x+m12*c12x)/(m12-m13)

    cy = m12*(cx-c12x)+c12y

    r2 = (cx-x1)**2 + (cy-y1)**2

    if (cx >= 0.) then

    signx = '-'

    else

    signx = '+'

    end if

    if (cy >= 0.) then

    signy = '-'

    else

    signy = '+'

    end if

    write (*, *) '方程式: ( x ', signx, abs(cx), ')^2 + ( y ', signy, abs(cy), ')^2 =', r2

    write (*, "(' 驗算:')")

    write (*, *), 'x1, y1:', (x1-cx)**2 + (y1-cy)**2

    write (*, *), 'x2, y2:', (x2-cx)**2 + (y2-cy)**2

    write (*, *), 'x3, y3:', (x3-cx)**2 + (y3-cy)**2

    go to 1

    end執行結果: Enter x1, y1: 1 0

    Enter x2, y2: -1 0

    Enter x3, y3: 0 1

    方程式: ( x - 0. )^2 + ( y - 0. )^2 = 1.

    驗算:

    x1, y1: 1.

    x2, y2: 1.

    x3, y3: 1. Enter x1, y1: -7 4

    Enter x2, y2: 1 8

    Enter x3, y3: 3 4

    方程式: ( x + 2. )^2 + ( y - 4. )^2 = 25.

    驗算:

    x1, y1: 25.

    x2, y2: 25.

    x3, y3: 25. Enter x1, y1: 1 2

    Enter x2, y2: -3 4

    Enter x3, y3: 0 8

    方程式: ( x + 0.045454547 )^2 + ( y - 4.909091 )^2 = 9.555785

    驗算:

    x1, y1: 9.555785

    x2, y2: 9.555785

    x3, y3: 9.555784 Enter x1, y1: 1 2

    Enter x2, y2: 5 2

    Enter x3, y3: 6 0

    方程式: ( x - 3. )^2 + ( y + 0.25 )^2 = 9.0625

    驗算:

    x1, y1: 9.0625

    x2, y2: 9.0625

    x3, y3: 9.0625 Enter x1, y1: ^C

    (打 Ctrl/C 結束程式執行)

還有問題?馬上發問,尋求解答。