Preskočiť na hlavný obsah

Ako umiestniť body na kružnicu

Problém ako umiestniť body po na kružnici som riešil nedávno a vôbec to nie je zložité. Potrebujeme k tomu 3 údaje a to počet bodov, šírku a výšku plátna na ktoré ideme body umiestňovať. Prvú vec ktorú si spočítame sú okraje kružnice. V mojom uvedenom príklade je to veľkosť plátna mínus 10%. Ďalej si určíme uhol alfa ktorý vypočítame ako 2 × π a to celé deleno počet vrcholov. Ako ďalšiu vec si určíme stred kružnice a polomer. A na koniec už len prechádzame počtom vrcholov a jednoduchou matematickou operáciou pre x-ovú súradnicu je to stred + (polomer × cos(poradie vrchola × uhol alfa)) a pre y-ovú je postup rovnaký avšak zmeníme funkciu cos() na funkciu sin() počítame už konkrétne body.

Realizácia v Jave

/**
 * placePointsOnCircle - Regular distribution of points on a circle
 * 
 * @author Tomas Adamjak <thomas @ adamjak.net>
 *
 * @see http://thomas.adamjak.net/2014/03/27/ako-umiestnit-body-na-kruznicu/
 * 
 * @param numberOfPoint (Integer) - Number of points that we want to place the circle (must be at least 1)
 * @param width (Integer) - canvas width
 * @param height (Integer) - canvas height
 * 
 * @return List<Point> - List of points
 * 
 * @throws Exception If number of points is less than 1
 * @throws Exception If width of canvas is less than 1
 * @throws Exception If height of canvas is less than 1
 */
public List<Point> placePointsOnCircle(Integer numberOfPoint, Integer width, Integer height) throws Exception
{
	if (width < 0)
	{
		throw new Exception("Width must be more than 0.");
	}
	else if (height < 0)
	{
		throw new Exception("Height must be more than 0.");
	}
	else if (numberOfPoint < 0)
	{
		throw new Exception("Number of points must be more than 0.");
	}
	
	Integer minWidth = width / 100 * 10;
	Integer maxWidth = width - minWidth;
	Integer minHeight = height / 100 * 10;
	Integer maxHeight = height - minHeight;
	
	Double angleAlfa = (2 * Math.PI) / numberOfPoint;

	Point center = new Point((maxWidth + minWidth) / 2, (maxHeight + minHeight) / 2);
	
	Integer radius = null;
	
	if ((maxWidth - center.x) > (maxHeight - center.y))
	{
		radius = maxHeight - center.y;
	}
	else
	{
		radius = maxWidth - center.x;
	}
	
	List<Point> points = new ArrayList<Point>();
	
	for (int i = 0; i < numberOfPoint; i++)
	{
		Double x = center.x + (radius * Math.cos(i * angleAlfa));
		Double y = center.y + (radius * Math.sin(i * angleAlfa));
		
		points.add(new Point(x.intValue(), y.intValue()));
	}
	
	return points;
}

Komentáre

Obľúbené príspevky z tohto blogu

Java - Súčet Listu s objektami BigDecimal

Pri používaní typu BigDecimal som narazil na zaujímavú úlohu a to sčítanie všetkých hodnôt v Liste. Majmä nasledovne definovaný list: List < BigDecimal > listOfBigDecimals = new LinkedList (); 1. spôsob je klasicke preiterovanie celého listu: BigDecimal sum = BigDecimal . ZERO ; for ( BigDecimal number : listOfBigDecimals ) { sum = sum . add ( number ); } 2. spôsobom je využitie stream.reduce() : BigDecimal sum = listOfBigDecimals . stream () . reduce ( BigDecimal . ZERO , BigDecimal :: add ); BONUS: spôsob s použitím reduce() v Kotline : val sum : BigDecimal = listOfBigDecimal . reduce { a , n -> a . add ( n ) }

Obnova vymazaných suborov

Mnohokrát som sa stretol s otázkou či je možné obnoviť vymazané súbory na disku, na USB kľúči či na pamäťovej karte. Moja odpoveď je vždy rovnaká: NIE! Áno, ja viem klamať sa nemá ale je to lepšie pre obe strany. Ja sa s tým nemusím hrať a prehľadávať kadejaké staré USB disky a na druhej strane ľudia nie sú sklamaný keď sa mi to nepodarí. Teraz keď vieme, že to ide tak si poďme ukázať jednoduchý spôsob ako sa to dá robiť. Počas ukážky si stiahnem logo softvéru TestDisk ktoré následne vymažem a pokúsim sa ho opäť obnoviť. Použijem na to softvér TestDisk . user@pc:/media/user/USB $ wget http://www.cgsecurity.org/mw/images/Testdisklogo_clear_100.png --2017-02-10 23:03:29-- http://www.cgsecurity.org/mw/images/Testdisklogo_clear_100.png Prevádza sa www.cgsecurity.org (www.cgsecurity.org) na IP adresu... 193.168.50.236 Pripájanie k www.cgsecurity.org (www.cgsecurity.org)|193.168.50.236|:80... pripojené. HTTP požiadavka odoslaná, čakám na odpoveď... 200 OK Dĺžka: 1726 (1,7K) [imag...

Formátovanie poznámok pod čiarov v LaTeXe

Najjednoduchšou cestou je použitie hand nastavení z balíčka footmisc . Pre nastavenie odsadenie použijeme voľbu \fotnotemargin nasledovne: \documentclass{article} \usepackage{lipsum} \usepackage[hang]{footmisc} \setlength\footnotemargin{10pt} \begin{document} \null\vfill % iba pre príklad \lipsum*[4]Test\footnote{\lipsum[4]} \end{document} Citované z : http://tex.stackexchange.com/questions/126877/how-can-i-align-a-multiple-line-footnote-text-right-to-the-footnote-mark#126878