Bestand:Closest pair of points.svg

Oorspronkelijk bestand(SVG-bestand, nominaal 256 × 256 pixels, bestandsgrootte: 1 kB)

Beschrijving

Beschrijving
English: Closest pair of points shown in red.
Datum
Bron Eigen werk
Auteur Qef
Andere versies Bitmap version: file:ClosestPair.png

Licentie

Creative Commons CC-Zero Dit bestand is beschikbaar onder Creative Commons CC0 1.0 Universele Public Domain Dedication.
De persoon die een werk voorziet van deze licentie stelt dit werk beschikbaar aan het publieke domein door, voor zover dit wettelijk is toegestaan, afstand te doen van alle rechten op het werk in de zin van het auteursrecht, met inbegrip van alle aanverwante of naburige rechten. U kunt het werk kopiëren, aanpassen, distribueren en uitvoeren, ook voor commerciële doeleinden, zonder dat u daarvoor toestemming hoeft te vragen.

Source code

The SVG was generated by running the Lua program given below. It deliberately fails if the closest points would be overlapping in the image, because that would be confusing.

local WD, HT, NUM_POINTS = 256, 256, 16
local COLOR = { normal = '#000', closest = '#f00' }
local RADIUS = 5

math.randomseed(os.time())
local P = {}
for _ = 1, NUM_POINTS do
    P[#P+1] = { x = RADIUS + (WD - 2*RADIUS) * math.random(),
                y = RADIUS + (HT - 2*RADIUS) * math.random() }
end

-- Find closest pair, using naive algorithm.
local closest_a, closest_b
local min_dist
for i, p in ipairs(P) do
    for j, q in ipairs(P) do
        if i ~= j then
            local dist = math.sqrt((p.x - q.x)^2 + (p.y - q.y)^2)
            if not min_dist or dist < min_dist then
                min_dist = dist
                closest_a, closest_b = i, j
            end
        end
    end
end

if min_dist < RADIUS then
    error("points on top of each other, run me again")
end

io.write('<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n',
         '<svg svg="http://www.w3.org/2000/svg" version="1.0"',
         ' width="', WD, '" height="', HT, '">\n')
for i, p in ipairs(P) do
    local color = COLOR.normal
    if i == closest_a or i == closest_b then color = COLOR.closest end
    io.write(' <circle cx="', RADIUS + p.x, '" cy="', RADIUS + p.y,
             '" r="', RADIUS, '" style="fill:', color, '"/>\n')
end
io.write('</svg>\n')

Bijschriften

Beschrijf in één regel wat dit bestand voorstelt

Items getoond in dit bestand

beeldt af

image/svg+xml

120742ed70c3028e512f55d9b9e19453b4a7df2f

1.365 byte

256 pixel

256 pixel

Bestandsgeschiedenis

Klik op een datum/tijd om het bestand te zien zoals het destijds was.

Datum/tijdMiniatuurAfmetingenGebruikerOpmerking
huidige versie22 jun 2009 06:03Miniatuurafbeelding voor de versie van 22 jun 2009 06:03256 × 256 (1 kB)Qef{{Information |Description={{en|1=Closest pair of points shown in red.}} |Source=Own work by uploader |Author=Qef |Date=2009-06-22 |Permission= |other_versions=Bitmap version: file:ClosestPair.png }} <!--{{ImageUpload|full}}--> [[Catego

Dit bestand wordt op de volgende pagina gebruikt:

Globaal bestandsgebruik

De volgende andere wiki's gebruiken dit bestand: