Line circle intersection: Difference between revisions
Content added Content deleted
(→{{header|Go}}: Doh, messed up my own examples! Minor output tidying whilst we're here.) |
|||
Line 36: | Line 36: | ||
func (p point) String() string { |
func (p point) String() string { |
||
// hack to get rid of negative zero |
|||
⚫ | |||
// compiler treats 0 and -0 as being same |
|||
if p.x == 0 { |
|||
p.x = 0 |
|||
} |
|||
if p.y == 0 { |
|||
p.y = 0 |
|||
} |
|||
⚫ | |||
} |
} |
||
Line 125: | Line 133: | ||
fmt.Println("The intersection points (if any) between:") |
fmt.Println("The intersection points (if any) between:") |
||
fmt.Println("\n A circle, center (3, -5) with radius 3, and:") |
fmt.Println("\n A circle, center (3, -5) with radius 3, and:") |
||
fmt.Println("\n a line containing the points (-10, 11) and (10, 9) is/are:") |
fmt.Println("\n a line containing the points (-10, 11) and (10, -9) is/are:") |
||
fmt.Println(" ", intersects(point{-10, 11}, point{10, -9}, cp, r, false)) |
fmt.Println(" ", intersects(point{-10, 11}, point{10, -9}, cp, r, false)) |
||
fmt.Println("\n a segment starting at (10, |
fmt.Println("\n a segment starting at (-10, 11) and ending at (-11, 12) is/are") |
||
fmt.Println(" ", intersects(point{-10, 11}, point{-11, 12}, cp, r, true)) |
fmt.Println(" ", intersects(point{-10, 11}, point{-11, 12}, cp, r, true)) |
||
fmt.Println("\n a horizontal line containing the points (3, -2) and (7, -2) is/are:") |
fmt.Println("\n a horizontal line containing the points (3, -2) and (7, -2) is/are:") |
||
Line 146: | Line 154: | ||
fmt.Println(" ", intersects(point{7, 4}, point{11, 8}, cp, r, true)) |
fmt.Println(" ", intersects(point{7, 4}, point{11, 8}, cp, r, true)) |
||
}</lang> |
}</lang> |
||
{{incorrect|Go|In main(), the output text and numbers differ, twice!!}} |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 153: | Line 161: | ||
A circle, center (3, -5) with radius 3, and: |
A circle, center (3, -5) with radius 3, and: |
||
a line containing the points (-10, 11) and (10, 9) is/are: |
a line containing the points (-10, 11) and (10, -9) is/are: |
||
[(6 |
[(6, -5) (3, -2)] |
||
a segment starting at (10, |
a segment starting at (-10, 11) and ending at (-11, 12) is/are |
||
[] |
[] |
||
a horizontal line containing the points (3, -2) and (7, -2) is/are: |
a horizontal line containing the points (3, -2) and (7, -2) is/are: |
||
[(3 |
[(3, -2)] |
||
A circle, center (0, 0) with radius 4, and: |
A circle, center (0, 0) with radius 4, and: |
||
a vertical line containing the points (0, -3) and (0, 6) is/are: |
a vertical line containing the points (0, -3) and (0, 6) is/are: |
||
[( |
[(0, 4) (0, -4)] |
||
a vertical segment starting at (0, -3) and ending at (0, 6) is/are: |
a vertical segment starting at (0, -3) and ending at (0, 6) is/are: |
||
[( |
[(0, 4)] |
||
A circle, center (4, 2) with radius 5, and: |
A circle, center (4, 2) with radius 5, and: |
||
a line containing the points (6, 3) and (10, 7) is/are: |
a line containing the points (6, 3) and (10, 7) is/are: |
||
[(8 |
[(8, 5) (1, -2)] |
||
a segment starting at (7, 4) and ending at (11, 8) is/are: |
a segment starting at (7, 4) and ending at (11, 8) is/are: |
||
[(8 |
[(8, 5)] |
||
</pre> |
</pre> |
||