-
Path: news-archive.icm.edu.pl!news.icm.edu.pl!news.onet.pl!.POSTED!not-for-mail
From: Radoslaw Jocz <r...@p...onet.pl>
Newsgroups: pl.comp.programming
Subject: Re: jak szacowac dokladnosc obliczen
Date: Sat, 18 Jun 2011 21:30:12 +0100
Organization: http://onet.pl
Lines: 105
Message-ID: <itj1sg$3lr$1@news.onet.pl>
References: <itiucm$n4v$1@news.onet.pl>
NNTP-Posting-Host: cpc1-hawk1-0-0-cust398.aztw.cable.virginmedia.com
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.onet.pl 1308429008 3771 82.46.25.143 (18 Jun 2011 20:30:08 GMT)
X-Complaints-To: n...@o...pl
NNTP-Posting-Date: Sat, 18 Jun 2011 20:30:08 +0000 (UTC)
User-Agent: Thunderbird 2.0.0.23 (Windows/20090812)
In-Reply-To: <itiucm$n4v$1@news.onet.pl>
Xref: news-archive.icm.edu.pl pl.comp.programming:191036
[ ukryj nagłówki ]
spojrzcie na ten kod nie rozumiem zbytno po co ktos
robil takie sztuczki z przesunieciami bitowymi << 14 >> 14
typedef struct point {
int x;
int y;
} point;
typedef struct line {
point p1;
point p2;
} line;
/*
* check_lines:
* This is based off an explanation and expanded math presented by Paul
Bourke:
*
* It takes two lines as inputs and returns 1 if they intersect, 0 if
they do
* not. hitp returns the point where the two lines intersected.
*
* This function expects integer value inputs and stores an integer value
* in hitp if the two lines interesect. The internal calculations are
fixed
* point with a 14 bit fractional precision for processors without floating
* point units.
*/
int check_lines(line *line1, line *line2, point *hitp)
{
/* Introduction:
* This code is based on the solution of these two input equations:
* Pa = P1 + ua (P2-P1)
* Pb = P3 + ub (P4-P3)
*
* Where line one is composed of points P1 and P2 and line two is
composed
* of points P3 and P4.
*
* ua/b is the fractional value you can multiple the x and y legs
of the
* triangle formed by each line to find a point on the line.
*
* The two equations can be expanded to their x/y components:
* Pa.x = p1.x + ua(p2.x - p1.x)
* Pa.y = p1.y + ua(p2.y - p1.y)
*
* Pb.x = p3.x + ub(p4.x - p3.x)
* Pb.y = p3.y + ub(p4.y - p3.y)
*
* When Pa.x == Pb.x and Pa.y == Pb.y the lines intersect so you
can come
* up with two equations (one for x and one for y):
*
* p1.x + ua(p2.x - p1.x) = p3.x + ub(p4.x - p3.x)
* p1.y + ua(p2.y - p1.y) = p3.y + ub(p4.y - p3.y)
*
* ua and ub can then be individually solved for. This results in the
* equations used in the following code.
*/
/* Denominator for ua and ub are the same so store this calculation */
int d = (line2->p2.y - line2->p1.y)*(line1->p2.x-line1->p1.x) -
(line2->p2.x - line2->p1.x)*(line1->p2.y-line1->p1.y);
/* n_a and n_b are calculated as seperate values for readability */
int n_a = (line2->p2.x - line2->p1.x)*(line1->p1.y-line2->p1.y) -
(line2->p2.y - line2->p1.y)*(line1->p1.x-line2->p1.x);
int n_b = (line1->p2.x - line1->p1.x)*(line1->p1.y - line2->p1.y) -
(line1->p2.y - line1->p1.y)*(line1->p1.x - line2->p1.x);
/* Make sure there is not a division by zero - this also indicates that
* the lines are parallel.
*
* If n_a and n_b were both equal to zero the lines would be on top
of each
* other (coincidental). This check is not done because it is not
* necessary for this implementation (the parallel check accounts
for this).
*/
if(d == 0)
return 0;
/* Calculate the intermediate fractional point that the lines
potentially
* intersect.
*/
int ua = (n_a << 14)/d;
int ub = (n_b << 14)/d;
/* The fractional point will be between 0 and 1 inclusive if the lines
* intersect. If the fractional calculation is larger than 1 or
smaller
* than 0 the lines would need to be longer to intersect.
*/
if(ua >=0 && ua <= (1<<14) && ub >= 0 && ub <= (1<<14))
{
hitp->x = line1->p1.x + ((ua * (line1->p2.x - line1->p1.x))>>14);
hitp->y = line1->p1.y + ((ua * (line1->p2.y - line1->p1.y))>>14);
return 1;
}
return 0;
}
Następne wpisy z tego wątku
- 18.06.11 20:33 Radoslaw Jocz
- 18.06.11 20:36 Jacek Czerwinski
- 18.06.11 20:40 slawek
- 18.06.11 20:47 Jacek Czerwinski
- 18.06.11 21:20 qwak
- 18.06.11 22:49 Michoo
- 19.06.11 08:17 Radoslaw Jocz
- 19.06.11 08:49 Radoslaw Jocz
- 19.06.11 10:59 slawek
- 19.06.11 21:30 Artur Muszyński
- 20.06.11 08:03 Paweł Kierski
- 27.06.11 06:53 Tomasz Kaczanowski
Najnowsze wątki z tej grupy
- 7. Raport Totaliztyczny: Sprawa Qt Group wer. 424
- TCL - problem z escape ostatniego \ w nawiasach {}
- Nauka i Praca Programisty C++ w III Rzeczy (pospolitej)
- testy-wyd-sort - Podsumowanie
- Tworzenie Programów Nieuprzywilejowanych Opartych Na Wtyczkach
- Do czego nadaje się QDockWidget z bibl. Qt?
- Bibl. Qt jest sztucznie ograniczona - jest nieprzydatna do celów komercyjnych
- Co sciaga kretynow
- AEiC 2024 - Ada-Europe conference - Deadlines Approaching
- Jakie są dobre zasady programowania programów opartych na wtyczkach?
- sprawdzanie słów kluczowych dot. zła
- Re: W czym sie teraz pisze programy??
- Re: (PDF) Surgical Pathology of Non-neoplastic Gastrointestinal Diseases by Lizhi Zhang
- CfC 28th Ada-Europe Int. Conf. Reliable Software Technologies
- Młodzi programiści i tajna policja
Najnowsze wątki
- 2024-11-24 Aby WKOOOORWIĆ ekofaszystów ;-)
- 2024-11-22 OC - podwyżka
- 2024-11-22 wyszedł z domu bez buta
- 2024-11-22 Bieda hud.
- 2024-11-24 DS1813-10 się psuje
- 2024-11-23 Białystok => Inżynier bezpieczeństwa aplikacji <=
- 2024-11-23 Szczecin => QA Engineer <=
- 2024-11-23 Warszawa => SEO Specialist (15-20h tygodniowo) <=
- 2024-11-22 Warszawa => Kierownik Działu Spedycji Międzynarodowej <=
- 2024-11-22 Warszawa => Senior Account Manager <=
- 2024-11-22 Warszawa => Key Account Manager <=
- 2024-11-22 Warszawa => DevOps Specialist <=
- 2024-11-22 Kraków => IT Expert (Network Systems area) <=
- 2024-11-22 Warszawa => Infrastructure Automation Engineer <=
- 2024-11-22 Warszawa => Presales / Inżynier Wsparcia Technicznego IT <=