Ang

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 42

Ang Sumerya o Sumer (mula sa wikang Akkadian umeru; Sumerian ki-en-ir15, tinatayang

"lupain ng mga sibilisadong hari" o "katutubong lupain" [note 1])[1] ay isang sinaunang kabihasnan at
historikal na rehiyon sa Mesopotamiasa modernong Iraq noong mga panahong Chalcolithic at
maagang panahong Tanso. Bagaman ang mga pinakamaagang historikal rekord sa rehiyong ito ay
hindi mas maaga sa ca. 2900 BCE, ang mga modernong historyan ay nagsasaad na ang Sumerya
ay unang tinirhan ng mga taong hindi-Semitiko na maaring nagsalita ng wikang Sumeryosa pagitan
ng ca. 4500 BCE at 4000 BCE dahil sa mga ebidensiya ng mga pangalan ng siyudad, mga ilog at
iba pa.[2]Ang mga pinagpapalagay na prehistorikong mga taong ito ay tinatawag ngayon ng mga
skolar na mga "proto-Euphratean" o mga "Ubaidian",[3] na pinaniniwalaang nagebolb mula
sa kulturang Samarra ng Hilagaang Mesopotomia (Assyria).[4][5][6][7] Ang mga Ubaidian ang mga
unang nagpaunlad ng kabihasnan sa rehiyon sa pamamagitan ng pagpapaunlad ng irigasyon,
pagpapaunlad ng kalakalan, pagtatatag ng mga industriya kabilang ang paghahabi, pagkakatad,
pagmemetal, masonriya at pagpapalayok.[3] Ang kabihasnang Sumeryo ay nagkaanyo sa panahong
Uruk (ika-4 milenyo BCE) na nagpatuloy hanggang sa Jemdat Nasr at mga panahong Maagang
Dinastiko. Noong ika-3 milenyo BCE, ang isang malapit na simbiosis na kultural ay nabuo sa pagitan
ng mga Sumeryo (na nagsasalita ng Hiwalay na wika) at mga tagapagsalitang Semitikong
Akkadiano na kinabibilangan ng malawakang bilingualismo. [8] Ang impluwensiya ng wikang
Sumerian sa wikang Akkadian at bise bersa ay ebidente sa lahat ng mga sakop mula sa
malawakang panghihiram naleksikal hanggang sa
pagtatagpong sintaktiko, morpolohikal at ponolohikal.[8] Ito ay nagtulak sa mga skolar na tukuyin ang
wikang Sumerian at Akkadian noong ikatlong milenyo BCE bilang isang sprachbund.[8] Ang Sumerya
ay sinakop ng mga nagsasalita ng Semitikong mga hari ng Imperyong Akkadian noong mga 2270
BCE (maikling kronolohiya) ngunit ang wikang Sumeryo ay nagptuloy bilang isang sagradong wika.
Ang katutubong pamumunong Sumeryo ay muling umahon sa loob ng isang siglo ng Ikatlong
Dinastiya ng Ur (Renasimiyentong Sumeryo) ng ika-21 hanggang ika-20 siglo BCE ngunit ang
wikang Akkadian ay nanatiling ginagamit sa panahong ito. Ang siyudad na Sumeryong Eridu sa
baybayin ng Golpong Persiko(Persian Gulf) ang kauna-unahang siyudad sa mundo kung saan ang
tatlong magkakahiwalay na mga kultura ay nagsama-ng mga magsasakang Ubaidiano na
nabubuhay sa mga kubong putik at brick at nagsasanay ng irigasyon, mga nomadikong Semitikong
mga magpapastol na nabubuhay sa mga itim na told at nagpapastol ng mga tupa at kambing, at
mga mangingisda na nabubuhay sa mga kubong reed na maaaring mga ninuno ng mga Sumeryo. [9]
Ang labis na maiimbak na mga pagkain na nalikha ng ekonomiyang ito ay pumayag sa populasyon
ng rehiyong ito na tumira sa isang lugar sa halip na magpagala-gala bilang mga mangangaso. Ang
Sumerya ay lugar rin ng maagang pag-unlad ng pagsusulat na sumulong mula sa isang yugto
ng proto-pagsusulat noong gitnang ika-4 milenyo BCE hanggang sa kuneipormang Sumeryo sa
ikatlong milenyo BCE.

Kasaysayan[baguhin | baguhin ang batayan]

Ang kasaysayan ng Sumerya na kinabibilangan ng prehistorikong mga panahong


Ubaid at panahong Uruk ay sumasaklaw mula ika-5 hanggang ika-3 milenyo BCE na nagtapos
sa Ikatlong Dinastiya ng Ur noong 20471940 BCE na sinundan ng transisyonal na panahon ng mga
estadong Amoreo.
Ang unang lugar na tinirhan ng mga tao sa katimugang Mesopotamia ang Eridu. Inangkin ng mga
Sumeryo na ang kanilang kabihasnan ay dinala sa siyudad ng Eridu ng kanilang Diyos na si Enki o
kanyang tagapayong si Adapa. Dinala ng mga unang tao ng Eridu ang kulturang Samarran mula sa
hilagaang Mesopotamia na kinikilalang panahong Ubaid ngunit hindi pa matiyak kung ang mga ito
ay mga Sumeryo na nauugnay sa kalaunang panahong Uruk.
Ang mga siyudad-estado o lungsod-estado na Sumeryo ay umakyat sa kapangyarihan noong
prehistorikal na panahong Ubaid at panahong Uruk. Ang Klasikong Sumeryo ay nagwakas sa pagakyat sa kapangyarihan ng Imperyong Akkadiano noong ika-23 siglo BCE Pagkatapos ng panahong
Gutian, may isang maiklingRenasimiyentong Sumeryo noong ika-21 siglo BCE na pinatigil noong
ika-20 siglo BCE ng mga pananakop ng mga Amoreong Semitiko. Ang "dinastiyang Isin" ng Amoreo
ay nagpatuloy hanggang ca. 1700 BCE nang ang Mesopotamia ay pinag-isa sa ilalim ng pamumuno
ng Babilonia. Ang mga Sumeryo ay kalaunang isinama sa populasyong Akkadian (AssyroBabylonian).

Panahong Ubaid: 5300 4100 BCE (Palayukang Neolitiko hanggang Chalcolithic)

Panahong Uruk: 4100 2900 BCE (Huling Chalcolithic hanggang Maagang Panahong
Tanso I)

Uruk XIV-V: 4100 3300 BCE

Panahong Uruk IV : 3300 3000 BCE

Panahong Jemdet Nasr (Uruk III): 3000 2900 BCE

Maagang panahong Dinastiko (Maagang panahong Tanso II-IV)

Panahong Maagang Dinastiko I: 29002800 BCE

Panahong Maagang Dinastiko II : 28002600 BCE (Gilgamesh)

Panahong Maagang Dinastiko IIIa: 26002500 BCE

Panahong Maagang Dinastiko IIIb : ca. 25002334 BCE

Panahong Imperyong Akkadian : ca. 23342218 BCE (Sargon)

Panahong Gutian: ca. 22182047 BCE (Maagang panahong Tanso IV)

Panahong Ur III: ca. 20471940 BCE

Ang talaan ng mga haring Sumeryo ay nagtatala ng mga hari ng Sumerya. Bagaman ang mga
dinastiyang namuno ay itinalang magkakasunod dito, ang ilan sa mga pinunong ito ay aktuwal na
namuno ng sabay sa mga magkaibang lugar.

Panahong Predinastiko[baguhin | baguhin ang batayan]


Ang panahong pre-dinastiko sa talaan ng mga haring Sumeryo ay nagpapakita ng pagpasa ng
kapangyarihan mula sa Eridu tungo sa Shuruppak bago ang isangmalaking baha . Ayon sa talaan
ng mga haring Sumeryo, ang paghahari ay bumaba mula sa langit sa Eridu at si Alulim ang unang
haring nanamuno ng 28,000 taon. Ang Eridu ay bumagsak at ang paghahari ay inilipat sa Bad-tibira.
Ang Bad-tibira ay bumagsak at ang paghahari ay inilipat sa Larag. Ang Larag ay bumagsak at ang
paghahari ay inilipat sa Zimbir. Ang Zimbir ay bumagsak at ang paghahari ay inilipat sa Shuruppak.
Pagkatapos nito ay nagkaroon ng malaking baha sa Shuruppak. Ang mga ebidensiya ng
paghuhukay sa Iraq ay nagpapakita ng isang lokal na baha sa Shuruppak. Nakumpirma ng mga
arkeologo ang presensiya ng isang malawakang patong ng mga depositong silt sa mga bangko ng
ilog sa Shuruppak na pinetsahan ng radio carbon na nangyari noong ca. 2900 BCE sa sandaling
pagkatapos ng osilasyong Piora na gumambala sa pagkakasunod ng pagtira ng tao na nag-iwan ng
ilang talampakan ng dilaw na sedimento sa mga siyudad ng Shuruppak at Uruk at hanggang
sa Kish sa hilaga. Ang mga palayukang polychrome mula sa panahong Jemdet Nasr (30002900
BCE) ay natuklasan ng agaran sa ilalim ng stratum o patong ng baha sa Shuruppak. Ang panahong
Jemdet Nasr ay sinundan ng mga artipakto ng panahong Maagang Dinastiko I sa itaas ng patong na
sedimento ng baha. Ayon sa resensiyong WB-62 ng talaan ng mga haring Sumeryo,
si Ziusudra ng Shuruppak ang huling hari ng Sumerya bago ang baha. Ang mito ng paglikha ng
Sumerya ay nagsasalaysay rin ng pagkakalikha ng mga tao, pagbaba ng paghahari mula sa langit at
pagkakatag ng unang limang mga siyudad na Eridu, Bad-tibira, Larsa (Larag), Sippar (Zimbir), at
Shuruppak, ang bahang ipinadala ng mga Diyos na sina An, Enlil, Enki at Ninhursanga at paggawa
ng isang bangka ni Ziusudra at pagbibigay kay Ziusudra ng buhay na walang hanggan ng mga
Diyos. Pagkatapos ng baha sa Sumerya, ang hegemonyaay muling lumitaw sa hilagaang siyudad
ng Kish sa pasimula ng panahong Maagang Dinastiko.

Panahong Maagang Dinastiko[baguhin | baguhin ang batayan]


Ang panahong Maagang Dinastiko ay nagsimula pagkatapos ng isang patid sa kultura dahil sa isang
baha sa mas naunang panahong Jemdet Nasr na pinetsahan ng radio carbon noong mga 2900
BCE. Ang panahong Maagang Dinastiko II ang panahon na ang hari ng Uruk na si Gilgamesh ay
namuno. Ang hegemonya na ipinagkakaloob ng saserdote ng Nippur ay naghalili sa isang bilang ng
mga magkakatunggaling dinastiya mula sa siyudad-estado ng sumerya kabilang ang Kish, Uruk, Ur,
Adab at Akshak gayundin mula sa labas ng katimugang Mesopotamia gaya ng Awan, Hamazi, at
Mari, hanggang sakupin ni Sargon ng Akkad ang mga sakop nito.
Unang Dinastiya ng Kish[baguhin | baguhin ang batayan]
Pagkatapos ng malaking baha sa Sumerya, ang paghahari ay nagpatuloy sa Kish. Ang pinuno
ng Kish na si Enmebaragesi (ca. 2600 BCE) ang unang pinunong satalaan ng mga haring
Sumeryo na pinatunayan ng arkeolohiya. Tinalo ni Enmebaragesi ang Elam at itinayo ang templo ng
Diyos na si Enlil sa Nippur. Ang kahalili ni Enmebaragesi na si Aga ng Kish ay nakipaglaban
kay Gilgamesh na hari ng Uruk. Pagkatapos na matalo ang Kish sa labanan, ang paghahari ay
inilipat sa E-ana.
Unang Dinastiya ng Uruk[baguhin | baguhin ang batayan]
Si Mesh-ki-ang-gasher ang unang hari ng Uruk. Siya ay sinundan ni Enmerkar. Ang
epikong Enmerkar at ang Panginoon ng Aratta ay nagsasalaysay ng kanyang paglalakbay sa Aratta.
Ang epiko ni Enmerkar at ang Panginoon ng Aratta ay posibleng nakaimpluwensiya sa mas
kalaunang kuwento ng Tore ng Babel sa Tanakhng Hudaismo. Hiniling ni Enmerkar sa Diyos na
si Inanna na ipailalim sa kanya ang Aratta at paghatirin ang mga tao ng Aratta ng isang tributo ng
mga mahahalagang metal at hiyas para sa pagtatayo ng isang matayog na Abzu ziggurat ni Enki sa
Eridu gayundin para sa pagpapalamuti ng sariling santuwaryo niInanna sa Uruk. Pinayuhan ng
Diyos na si Inanna si Enmerkar na magpadala ng isang sugo sa mga kabundukan ng Susin at
Anshan sa panginoon ng Aratta upang hilingin ang kanyang pagpapailalim at ang kanyang tributo. Si
Enmerkar ay pumayag at nagpadala ng sugo kasama ng mga spesipikong banta na wawasakin ang
Aratta at papakalatin ang mga tao kung hindi sila magpapadala sa kanya ng tributo. Sa karagdagan,
siya ay bibigkas ng isang "Inkantasyon ng Nudimmud" na isang himnong nagsusumamo kay Enki na
ibalik ang pagkakaisa sa wika ng mga tinatahanang rehiyon na pinangalanang Shubur, Hamazi,
Sumerya, Uri-ki (ang rehiyon sa palibot ng Akkad) at ang lupaing Martu: "Ang buong uniberso, ang
mahusay na nabantayang mga tao nawa'y kanilang magkakasamang pagsalitaan si Enlil sa isang
wika." Si Enmerkar ay sindundan ni Lugalbanda at ni Dumuzid ang Mangingisda. Si Dumuzid ay
sinundan ni haring Gilgamesh na bida sa Epiko ni Gilgameshna nakaimpluwensiya sa
kuwentong Arko ni Noe sa Bibliya.
Ang Uruk ay natalo at ang paghahari ay dinala sa Ur.
Unang Dinastiya ng Ur[baguhin | baguhin ang batayan]

Ang dinastiyang ito ay umiral noong mga ika-26 siglo BCE. Si Meskalamdug ang unang hari ng Ur
na pinatayunan ng arkeolohiya.
Mga sumunod pang dinastiya[baguhin | baguhin ang batayan]
Ang Ur ay natalo at ang pahahari ay dinala sa Awan. Ang dinastiyang Awan ay umiral noong mga
ika-26 siglo BCE. Ang Awan ay natalo at ang paghahari ay dinala sa Kish. Ang Ikalawang Dinastiya
ng Kish ay pinamunuan ng 8 pinuno. Pagkatapo sna matalo ang Kish, ang paghahari ay dinala
sa Hamazi. Ang Hamazi ay pinamunuan ng isang 1 pinuno. Ang Hamazi ay natalo at ang paghahari
ay dinala sa Uruk. Ang Ikalawang Dinastiya ng Uruk ay pinamunuan ng 3 pinuno. Ang Uruk ay
natalo at ang paghahari ay dinala sa Ur. Ang Ur ay natalo at ang paghahari ay dinala sa Adab. Ang
Adab ay natalo at ang paghahari ay dinala sa Mari. Ang Mari ay natalo at ang paghahari ay dinala
sa Kish. Ang Ikatlong Dinastiya ng Kish ay natalo at ang paghahari ay dinala sa Akshak. Ang Akshak
ay natalo at ang paghahari ay dinala sa Kish. Ang Ikaapat na Dinastiya ng Kish ay natalo at ang
paghahari ay dinala sa Uruk. Ang Unang Dinastiya ng Lagash ay umiral noong ika-25 siglo BCE at si
En-hegal ang unang pinuno nito bilang isang tributaryo ng Uruk. Si Urukagina (ca. 23592335 BCE
maikling kronolohiya) ay pinabagsak at ang kanyang siyudad na Lagash ay nabihag ng dakilang
saserdote ng Umma na si Lugal-zage-si. Sinakop ni Lugal-zage-si ang Uruk at Ur at ginawa niyang
kabisera ang Uruk. Gumawa siya ng mga mahabang inskripsiyon sa mga batong base na inalay sa
Diyos na Enlil ng Nippur. Siya ay pinabagsak ni Sargon ng Akkad at ang paghahari ay dinala sa
Akkad na tumagal ng ca. 2334 hanggang 2218 BCE (maikling kronolohiya). Ang Akkad ay natalo ng
mga Gutian na namuno ng mga isangsiglo. Ang ikalawang Dinastiya ng Lagash ay tumagal ng ca.
2260 hanggang 2110 BCE. Ang mga Gutian ay pinalayas ng mga Sumeryo sa ilalim ni Utuhengal ng Uruk. Si Utu-hegal ay natalo ni Ur-Nammu na nagtatag ng Ikatlong Dinastiya ng Ur na
tumagal ng ca. 2047 hanggang 1940 BCE sa maikling kronolohiya.

Pagbagsak[baguhin | baguhin ang batayan]


Ang Sumeria ay hindi nagkaisa noong sinasalakay sila ng mga Akkadiano kaya ang lungsod-estado
na ito ay naging bahagi ng Imperyong Akkadiano. Nilusob din ito ng mga Elamita. Sinasabing
humina ang agrikultura kaya lumisan ang ibang tao.[10]. Sa huli, naging bahagi ito ng
Imperyong Babilonya.

Kultura[baguhin | baguhin ang batayan]


Pagsulat[baguhin | baguhin ang batayan]

Pagsulat na Sumeryo na nagtatala ng alokasyon ng serbesa, 31003000 BCE

Ang pagsulat sa Sumerya ang pinakamatandang halimbawa ng pagsulat sa mundo. Ang malaking
bilang ng mga libo libong kasulatan sa wikang Sumeryo ay nakaligtas gaya ng mga liham na
personal o pangnegosyo, mga resibo, mga talaang leksikal, mga batas, mga imno, mga panalangin,
mga kuwento, mga talaang pang-araw araw at mga aklatang puno ng mga tabletang putik. Ang
sistema ng kanilang pagsulat ay tinatawag na Cuneiform.

Relihiyon[baguhin | baguhin ang batayan]


Walang malawakang pangimperyong hanay ng mga Diyos. Ang bawat siyudad-estado ay may sarili
nitong patrong-Diyos, mga templo, mga saserdote-hari. Ang mga Sumeryo ang pinaniniwalaang ang
unang sumulat ng kanilang mga paniniwala na kalaunang naging inspirasyon ng mitolohiyang
Mesopotamiano na naging impluwensiya naman sa mga mas kalaunangrelihiyon gaya ng Hudaismo
at Kristiyanismo.

Matematika[baguhin | baguhin ang batayan]


Ang mga Sumeryo ay bumuo ng isang masalimuot na sistema ng metrolohiya noong mga 4000
BCE. Ito ay nagresulta sa paglikha ng aritmetika, heometriya at alhebra. Mula c. 2600 BCE, ang
mga Sumeryo ay sumulat ng mga tabla ng multiplikasyon sa mga tabletang putik at mga
pagsasanay na heometrikal at mga problema sa dibisyon. Ang pinakamaagang mga bakas ng mga
numeral na Babilonyo ay mula sa panahong ito. Ang panahong 27002300 BCE ay nakakita ng
unang paglitaw ng abacus at isang tabla ng mga sunod sunod na column na nagdelimita ng mga
sunod sunod na orden ng magnitudo ng sistemang seksahesimal ng bilang. Ang mga Sumeryo ang
unang gumamit ng isang halagang lugar na sistemang numeral. Maaari ring ang mga Sumeryo ay
gumamit ng isang uri ng slide rule sa pagkukuwentang astronomikal. Sila ang unang nakahanap
ng area ng isang tatsulok at bolyum ng isang cube.

Agrikultura[baguhin | baguhin ang batayan]


Ang mga Sumeryo ay nagsanay ng mga pamamaraang agrikultural kabilang ang
organisadong irigasyon, malawakang kultibasyon ng lupain, pang isahang pagtatanim, paggamit ng
araro at paggamit ng espesyalisadong mga manggagawa sa ilalim ng burokratikong kontrol. Ang
pangangailangan na mangasiwa ng mga salaysay ng templo sa organisasyong ito ay nagresulta sa
pagbuo ng pagsulat sa Sumerya noong ca. 3500 BCE.

Mga teknolohiya[baguhin | baguhin ang batayan]

Maagang karwahe sa Pamantayan ng Ur, ca. 2600 BCE.

Kabilang sa mga teknolohiyang inimbento o ginamit ng mga Sumeryo


ang gulong,kuneiporma, aritmetika, heometriya, mga sistemang irigasyon,
mga bangka,kalendaryong lunisolar, bronse, kuwero, mga lagari, mga pait, mga martilyo, mga pako,
mga pin, mga bit, balat ng tubig, mga singsing, mga pala, mga palakol, mga kutsilyo, mga espada,
pandikit, balaraw, mga bag, mga harness, mga baluti, mga karwaheng pandigma, mga bota, mga
sandalyas, mga arpon, at serbesa.

Points, lines, and planes


In what follows are various notes and algorithms dealing
with points, lines, and planes.

Minimum Distance between


a Point and a Line
Written by Paul Bourke
October 1988
This note describes the technique and gives the solution to finding the shortest
distance from a point to a line or line segment. The equation of a line defined through
two points P1 (x1,y1) and P2 (x2,y2) is

P = P1 + u (P2 - P1)

The point P3 (x3,y3) is closest to the line at the tangent to the line which passes
through P3, that is, the dot product of the tangent and line is 0, thus
(P3 - P) dot (P2 - P1) = 0
Substituting the equation of the line gives
[P3 - P1 - u(P2 - P1)] dot (P2 - P1) = 0
Solving this gives the value of u

Substituting this into the equation of the line gives the point of intersection (x,y) of the
tangent as
x = x1 + u (x2 - x1)
y = y1 + u (y2 - y1)
The distance therefore between the point P3 and the line is the distance between (x,y)
above and P3.
Notes

The only special testing for a software implementation is to


ensure that P1 and P2 are not coincident (denominator in the
equation for u is 0)

If the distance of the point to a line segment is required then it


is only necessary to test that u lies between 0 and 1.

The solution is similar in higher dimensions.

Contributed implementations
C source from Damian Coventry: C source code

VBA from Brandon Crosby: VBA source code


Dephi from Graham O'Brien: Delphi version
"R" version from Gregoire Thomas: pointline.r
JAVA version from Pieter Iserbyt: DistancePoint.java
LabView implementation from Chris Dancer: Pointlinesegment.vi.zip
Right side distance by Orion Elenzil: rightside
VBA VB6 by Thomas Ludewig: vbavb6.txt

Minimum Distance between


a Point and a Plane
Written by Paul Bourke
March 1996
Let Pa = (xa, ya, za) be the point in question.
A plane can be defined by its normal n = (A, B, C) and any point on the plane Pb =
(xb, yb, zb)
Any point P = (x,y,z) lies on the plane if it satisfies the following
Ax+By+Cz+D=0

The minimum distance between Pa and the plane is given by the absolute value of
(A xa + B ya + C za + D) / sqrt(A2 + B2 + C2)

...1

To derive this result consider the projection of the line (Pa - Pb) onto the normal of the
plane n, that is just ||Pa - Pb|| cos(theta), where theta is the angle between (Pa - Pb) and
the normal n. This projection is the minimum distance of Pa to the plane.
This can be written in terms of the dot product as
minimum distance = (Pa - Pb) dot n / ||n||
That is
minimum distance = (A (xa - xb) + B (ya - yb) + C (za - zb)) / sqrt(A2 + B2 + C2)

...2

Since point (xb, yb, zb) is a point on the plane


A xb + B y b + C z b + D = 0

...3

Substituting equation 3 into equation 2 gives the result shown in equation 1.

Intersection point of two line segments in 2


dimensions
Written by Paul Bourke
April 1989
This note describes the technique and algorithm for determining the intersection point
of two lines (or line segments) in 2 dimensions.

The equations of the lines are


Pa = P1 + ua ( P2 - P1 )
Pb = P3 + ub ( P4 - P3 )
Solving for the point where Pa = Pb gives the following two equations in two
unknowns (ua and ub)
x1 + ua (x2 - x1) = x3 + ub (x4 - x3)
and
y1 + ua (y2 - y1) = y3 + ub (y4 - y3)
Solving gives the following expressions for ua and ub

Substituting either of these into the corresponding equation for the line gives the
intersection point. For example the intersection point (x,y) is
x = x1 + ua (x2 - x1)
y = y1 + ua (y2 - y1)
Notes:

The denominators for the equations for ua and ub are the same.

If the denominator for the equations for ua and ub is 0 then the


two lines are parallel.

If the denominator and numerator for the equations for u a and


ub are 0 then the two lines are coincident.


The equations apply to lines, if the intersection of line
segments is required then it is only necessary to test if ua and ub lie
between 0 and 1. Whichever one lies within that range then the
corresponding line segment contains the intersection point. If both
lie within the range of 0 to 1 then the intersection point is within
both line segments.
Source code
Original C code by Paul Bourke.
C++ contribution by Damian Coventry.
LISP implementation by Paul Reiners.
C version for Rockbox firmware by Karl Kurbjun.
C# version by Olaf Rabbachin.
VB.net version by Olaf Rabbachin.
VBA implementation by Giuseppe Iaria.

The shortest line between two lines in 3D


Written by Paul Bourke
April 1998
Two lines in 3 dimensions generally don't intersect at a point, they may be parallel (no
intersections) or they may be coincident (infinite intersections) but most often only
their projection onto a plane intersect.. When they don't exactly intersect at a point
they can be connected by a line segment, the shortest line segment is unique and is
often considered to be their intersection in 3D.

The following will show how to compute this


shortest line segment that joins two lines in 3D,
it will as a bi-product identify parallel lines. In
what follows a line will be defined by two
points lying on it, a point on line "a" defined by
points P1 and P2 has an equation.
Pa = P1 + mua (P2 - P1)

similarly a point on a second line "b" defined by


points P4and P4 will be written as
Pb = P3 + mub (P4 - P3)

The values of mua and mub range from negative


to positive infinity. The line segments between
P1 P2 and P3 P4 have their corresponding mu
between 0 and 1.

There are two approaches to finding the shortest line segment between lines "a" and
"b". The first is to write down the length of the line segment joining the two lines and
then find the minimum. That is, minimise the following
|| Pb - Pa ||2
Substituting the equations of the lines gives
|| P1 - P3 + mua (P2 - P1) - mub (P4 - P3) ||2
The above can then be expanded out in the (x,y,z) components. There are conditions
to be met at the minimum, the derivative with respect to mu a and mub must be zero.
Note: it is easy to convince oneself that the above function only has one minima and
no other minima or maxima. These two equations can then be solved for mu a and mub,
the actual intersection points found by substituting the values of mu into the original
equations of the line.
An alternative approach but one that gives the exact same equations is to realise that
the shortest line segment between the two lines will be perpendicular to the two lines.
This allows us to write two equations for the dot product as

(Pa - Pb) dot (P2 - P1) = 0


(Pa - Pb) dot (P4 - P3) = 0
Expanding these given the equation of the lines
( P1 - P3 + mua (P2 - P1) - mub (P4 - P3) ) dot (P2 - P1) = 0
( P1 - P3 + mua (P2 - P1) - mub (P4 - P3) ) dot (P4 - P3) = 0
Expanding these in terms of the coordinates (x,y,z) is a nightmare but the result is as
follows
d1321 + mua d2121 - mub d4321 = 0
d1343 + mua d4321 - mub d4343 = 0
where
dmnop = (xm - xn)(xo - xp) + (ym - yn)(yo - yp) + (zm - zn)(zo - zp)
Note that dmnop = dopmn
Finally, solving for mua gives
mua = ( d1343 d4321 - d1321 d4343 ) / ( d2121 d4343 - d4321 d4321 )
and back-substituting gives mub
mub = ( d1343 + mua d4321 ) / d4343
Source Code
Original C source code from the author: lineline.c
Contribution by Dan Wills in MEL (Maya Embedded Language): source.mel.
A Matlab version by Cristian Dima: linelineintersect.m.
A Maxscript function by Chris Johnson: LineLineIntersect.ms
LISP version for AutoCAD (and Intellicad) by Andrew Bennett: int1.lsp and int2.lsp
A contribution by Bruce Vaughan in the form of a Python script for the SDS/2 design
software: L3D.py

C# version by Ronald Holthuizen: calclineline.cs


VBA VB6 version by Thomas Ludewig: vbavb6.txt

Intersection of a plane and a line


Written by Paul Bourke
August 1991
Contribution by Bryan Hanson: Implementation in R
This note will illustrate the algorithm for finding the intersection of a line and a plane
using two possible formulations for a plane.

Solution 1
The equation of a plane (points P are on the plane with
normal N and point P3 on the plane) can be written as
N dot (P - P3) = 0
The equation of the line (points P on the line passing through
points P1 and P2) can be written as
P = P1 + u (P2 - P1)
The intersection of these two occurs when
N dot (P1 + u (P2 - P1)) = N dot P3
Solving for u gives

Note

If the denominator is 0 then the normal to the plane is


perpendicular to the line. Thus the line is either parallel to the plane
and there are no solutions or the line is on the plane in which case
there are an infinite number of solutions

If it is necessary to determine the intersection of the line


segment between P1 and P2 then just check that u is between 0
and 1.

Solution 2
A plane can also be represented by the equation
Ax+By+Cz+D=0
where all points (x,y,z) lie on the plane.
Substituting in the equation of the line through points P1 (x1,y1,z1) and P2 (x2,y2,z2)
P = P1 + u (P2 - P1)
gives
A (x1 + u (x2 - x1)) + B (y1 + u (y2 - y1)) + C (z1 + u (z2 - z1)) + D
=0
Solving for u

Note

the denominator is 0 then the normal to the plane is


perpendicular to the line. Thus the line is either parallel to the plane

and there are no solutions or the line is on the plane in which case
are infinite solutions

if it is necessary to determine the intersection of the line


segment between P1 and P2 then just check that u is between 0 and
1.

Equation of a plane
Written by Paul Bourke
March 1989

The standard equation of a plane in 3


space is
Ax + By + Cz + D = 0

The normal to the plane is the vector (A,B,C).

Given three points in space (x1,y1,z1), (x2,y2,z2), (x3,y3,z3) the equation of the plane
through these points is given by the following determinants.

Expanding the above gives


A = y1 (z2 - z3) + y2 (z3 - z1) + y3 (z1 - z2)
B = z1 (x2 - x3) + z2 (x3 - x1) + z3 (x1 - x2)
C = x1 (y2 - y3) + x2 (y3 - y1) + x3 (y1 - y2)
- D = x1 (y2 z3 - y3 z2) + x2 (y3 z1 - y1 z3) + x3 (y1 z2 - y2 z1)
Note that if the points are colinear then the normal (A,B,C) as calculated above will
be (0,0,0).

The sign of s = Ax + By + Cz + D determines which side the point (x,y,z) lies with
respect to the plane. If s > 0 then the point lies on the same side as the normal
(A,B,C). If s < 0 then it lies on the opposite side, if s = 0 then the point (x,y,z) lies on
the plane.
Alternatively
If vector N is the normal to the plane then all points p on the plane satisfy the
following
N.p=k
where . is the dot product between the two vectors.
ie: a . b = (ax,ay,az) . (bx,by,bz) = ax bx + ay by + az bz
Given any point a on the plane
N . (p - a) = 0

The intersection of two planes


Written by Paul Bourke
February 2000
The intersection of two planes (if they are not parallel) is a line.
Define the two planes with normals N as
N1 . p = d1
N2 . p = d2
The equation of the line can be written as
p = c1 N1 + c2 N2 + u N1 * N2

Where "*" is the cross product, "." is the dot product, and u is the parameter of the
line.
Taking the dot product of the above with each normal gives two equations with
unknowns c1 and c2.
N1 . p = d1 = c1 N1 . N1 + c2 N1 . N2
N2 . p = d2 = c1 N1 . N2 + c2 N2 . N2
Solving for c1 and c2
c1 = ( d1 N2 . N2 - d2 N1 . N2 ) / determinant
c2 = ( d2 N1 . N1 - d1 N1 . N2) / determinant
determinant = ( N1 . N1 ) ( N2 . N2 ) - ( N1 . N2 )2
Note that a test should first be performed to check that the planes aren't parallel or
coincident (also parallel), this is most easily achieved by checking that the cross
product of the two normals isn't zero. The planes are parallel if
N1 * N2 = 0

Intersection of three planes


Written by Paul Bourke
October 2001
A contribution by Bruce Vaughan in the form of a Python script for the SDS/2 design
software: P3D.py.
The intersection of three planes is either a point, a line, or there is no intersection (any
two of the planes are parallel).
The three planes can be written as

N1 . p = d1
N2 . p = d2
N3 . p = d3
In the above and what follows, "." signifies the dot product and "*" is the cross
product. The intersection point P is given by:
d 1 ( N2 * N3 ) + d 2 ( N3 * N1 ) + d 3 ( N1 * N2 )
P=

------------------------------------------------------------------------N1 . ( N2 * N3 )

The denominator is zero if N2 * N3 = 0, in other words the planes are parallel. Or


if N1 is a linear combination of N2 andN3.

Equation of a line in polar coordinates


Written by Paul Bourke
March 2013
How might one represent a line in polar coordinates?
In cartesian coordinates it can be represented as:

The derivation is quite straightforward once one realises that for a point (r, theta) the x
axis is simply r cos(theta) and the y axis is r sin(theta). Substituting those into the
equation for the line gives the following result.

Example from the Graphing Calculator.

Question

Given a line defined by two points L1 L2, a point P1 and angle z (bearing from north)
find the intersection point between the direction vector from P1 to the line.

Short answer: choose a second point P2 along the direction vector from P1, say P2 =
(xP1+sin(z),yP1+cos(z)). Apply the algorthm here for the intersection of two line
segments. Perform the additional test that ub must be greater than 0, the solution where
ub is less than 0 is the solution in the direction z+180 degrees.

Plane-Plane Intersection
Two planes always intersect in a line as long as they are not parallel. Let the planes be specified in Hessian normal
form, then the line of intersection must be perpendicular to both

and

, which means it is parallel to

(1
)
To uniquely specify the line, it is necessary to also find a particular point on it. This can be determined by finding a
point that is simultaneously on both planes, i.e., a point

that satisfies
(2)

(3)
In general, this system is underdetermined, but a particular solution can be found by setting

(assuming the -

component of is not 0; or another analogous condition otherwise) and solving. The equation of the line of
intersection is then

(4
)
(Gellert et al. 1989, p. 542). A general approach avoiding the special treatment needed above is to define
(5)
(6)

Then use a linear solving technique to find a particular solution


by the null spaceof

to

, and the direction vector will be given

Let three planes be specified by a triple of points

where

, 2, 3, denotes the plane number

and denotes the th point of the th plane. The point of concurrence


can be obtained straightforwardly (if
laboriously) by simultaneously solving the three equations arising from the coplanarity of each of the planes
with

, i.e.,

(7
)

for

, 2, 3 using Cramer's rule.

If the three planes are each specified by a point


intersection

and a unit normal vector

, then the unique point of

is given by

(8
)
where
is the determinant of the matrix formed by writing the vectors
are parallel, then

side-by-side. If two of the planes

(9
)
and there is no intersection (Gellert et al. 1989, p. 542; Goldman 1990). This condition can be checked easily for
planes in Hessian normal form.
A set of planes sharing a common line is called a sheaf of planes, while a set of planes sharing a common point is
called a bundle of planes.

Different Angles have different names:

Names of Angles
As the Angle Increases, the Name Changes:

Type of Angle

Description

Acute Angle

an angle that is less than 90

Right Angle

an angle that is 90 exactly

Obtuse Angle

an angle that is greater than 90 but

less than 180


Straight Angle

an angle that is 180 exactly

Reflex Angle

an angle that is greater than 180

Try It Yourself:

In One Diagram
This diagram might make it easier to remember:
Also: Acute, Obtuse and Reflex are in alphabetical order.

Be Careful What You Measure

This is an Obtuse Angle

And this is a Reflex Angle

But the lines are the same ... so when naming the angles make sure
that you know which angle is being asked for!

Positive and Negative Angles


When measuring from a line:

a positive angle goes counterclockwise (opposite direction that clocks


go)

a negative angle goes clockwise

Example: 67

Parts of an Angle
The corner point of an angle is called the vertex
And the two straight sides are called arms
The angle is the amount of turn between each arm.

Linear Pair of Angles


A pair of adjacent angles formed by intersecting lines. Angles 1 and 2 below are a
linear pair. So are angles 2 and 4, angles 3 and 4, and angles 1 and 3. Linear pairs of
angles are supplementary.

Vertical Angles (also "opposite angles")


From Latin: verticalis "overhead"

Definition: A pair of non-adjacent angles formed by the intersection of two


straight lines
The intersection of geometric primitives is a fundamental construct in many
computer graphics and modeling applications ([Foley et al, 1996], [O'Rourke,
1998]). Here we look at the algorithms for the simplest 2D and 3D linear
primitives: lines, segments and planes.

Line and Segment Intersections


For computing intersections of lines and segments in 2D and 3D, it is best to use
the parametric equation representation for lines. Other representations are
discussed in Algorithm 2 about the Distance of a Point to a Line. It is shown there
how to convert from other representations to the parametric one.
In any dimension, the parametric equation of a line defined by two
points P0 and P1 can be represented as:
,
where the parameter s is a real number and

is a line direction vector.

Using this representation


,
, and when
, P(s) is a point
on the finite segment P0P1 where s is the fraction ofP(s)'s distance along the

segment. That is, s = d(P0,P(s)) / d(P0,P1). Further, if s < 0 then P(s) is outside the
segment on the P0 side, and if s > 1 then P(s) is outside the segment on
the P1 side.

Let two lines be given by:


and
ray, or a finite segment.

, either or both of which could be infinite, a

Parallel Lines
These lines are parallel when and only when their directions are collinear, namely
when the two vectors

and

some real number a. For

and

the value a, or that


all

. In 2D, with

are linearly related as u = av for


, this means that all ratios

have

for all i. This is equivalent to the conditions that


and

, this is the perp

product [Hill, 1994] condition that


where
,
the perp operator, is perpendicular to u. This condition says that two vectors in the
Euclidean plane are parallel when they are both perpendicular to the same direction
vector
. When true, the two associated lines are either coincident or do not
intersect at all.
Coincidence is easily checked by testing if a point on one line, say P0, also lies on
the other line Q(t). That is, there exists a number t such that: P0 = Q(t ) = Q0 + t0v.
If w = (wi) = P0 Q0, then this is equivalent to the condition that w = t0v for
0

some t0 which is the same as

for all i. In 2D, this is another perp

product condition:

. If this condition holds, one

has
, and the infinite lines are coincident. And if one line (but not the
other) is a finite segment, then it is the coincident intersection. However, if both
lines are finite segments, then they may (or may not) overlap. In this case, solve
for t0 and t1such that P0 = Q(t0) and P1 = Q(t1). If the segment intervals [t ,t ] and
[0,1] are disjoint, there is no intersection. Otherwise, intersect the intervals (using
0

max and min operations) to get


segment is

. Then the intersection


. This works in any dimension.

Non-Parallel Lines
When the two lines or segments are not parallel, they might intersect in a unique
point. In 2D Euclidean space, infinite lines always intersect. In higher dimensions
they usually miss each other and do not intersect. But if they intersect, then their
linear projections onto a 2D plane will also intersect. So, one can simply restrict to
two coordinates, for which u and v are not parallel, compute the 2D intersection
point I at P(sI) andQ(tI) for those two coordinates, and then test if P(sI) = Q(tI) for
all coordinates. To compute the 2D intersection point, consider the two lines and
the associated vectors in the diagram:

To determine sI, we have the vector equality


. At the intersection, the vector

is perpendicular to

equivalent to the perp product condition that


equation, we get:

where
, and this is
. Solving this

Note that the denominator


only when the lines are parallel as previously
discussed. Similarly, solving for Q(tI), we get:

The denominators are the same up to sign, since


, and should only
be computed once if we want to know both sI and tI. However, knowing either is
enough to get the intersection point I = P(sI) = Q(tI).
Further, if one of the two lines is a finite segment (or a ray), say P0P1, then the
intersect point is in the segment only when
(or
for a ray). If both
lines are segments, then both solution parameters, sIand tI, must be in the [0,1]
interval for the segments to intersect. Although this sounds simple enough, the
code for the intersection of two segments is a bit delicate since many special cases
need to be checked (see our implementation intersect2D_2Segments()).

Plane Intersections
Planes are represented as described in Algorithm 4, see Planes.

Line-Plane Intersection
In 3D, a line L is either parallel to a plane P or intersects it in a single point.
Let L be given by the parametric equation:
the plane P be given by a point V0 on it and a normal vector

, and
. We first

check if L is parallel to P by testing if


, which means that the line
direction vector u is perpendicular to the plane normal n. If this is true,
then L and P are parallel and either never intersect or else L lies totally in the
plane P . Disjointness or coincidence can be determined by testing whether any

one specific point of L, say P0, is contained in P , that is whether it satisfies the
implicit line equation:

If the line and plane are not parallel, then L and P intersect in a unique point P(sI)
which is computed using a method similar to the one for the intersection of two
lines in 2D. Consider the diagram:

At the intersect point, the vector


to n, where
condition:

is perpendicular

. This is equivalent to the dot product


. Solving we get:

If the line L is a finite segment from P0 to P1, then one just has to check
that

to verify that there is an intersection between the segment and the

plane. For a positive ray, there is an intersection with the plane when

Intersection of 2 Planes
In 3D, two planes P1 and P2 are either parallel or they intersect in a single straight
line L. Let P i (i = 1,2) be given by a point Vi and a normal vector ni, and have an

implicit equation: ni P + di = 0, where P = (x, y, z). The planes P1 and P2 are


parallel whenever their normal vectors n1 and n2 are parallel, and this is equivalent
to the condition that: n1 x n2 = 0. In software, one would test if
where
division by
would cause overflow, and uses this as the robust condition
for n1 and n2 to be parallel in practice. When not parallel,
is a direction
vector for the intersection line L since u is perpendicular to both n1 and n2, and
thus is parallel to both planes as shown in the following diagram. If |u| is small, it
is best to scale it so that|u| = 1, making u a unit direction vector.

After computing
(3 adds + 6 multiplies), to fully determine the intersection
line, we still need to find a specific point on it. That is, we need to find a
point
that lies in both planes. We can do this by finding a common
solution of the implicit equations for P1 and P2. But there are only two equations in
the 3 unknowns since the point P0 can lie anywhere on the 1-dimensional line L.
So we need another constraint to solve for a specific P0. There are a number of
ways this could be done:
(A) Direct Linear Equation. One could set one coordinate to zero, say z0 = 0, and
then solve for the other two. But this will only work when L intersects the
plane z0 = 0. This is will be true when the z-coordinate uzof
is
nonzero. So, one must first select a nonzero coordinate of u, and then set the
corresponding coordinate of P0 to 0. Further, one should choose the coordinate
with the largest absolute value, as this will give the most robust computations.

Suppose that
equations:

, then

lies on L. Solving the two


and

, one gets:

and the parametric equation of L is:

The denominator here is equal to the non-zero 3rd coordinate of u. So, ignoring the
test for a large nonzero coordinate, and counting division as a multiplication, the
total number of operations for this solution = 5 adds + 13 multiplies.
(B) Line Intersect Point. If one knows a specific line in one plane (for example,
two points in the plane), and this line intersects the other plane, then its point of
intersection, I, will lie in both planes. Thus, it is on the line of intersection for the
two planes, and the parametric equation of L is: P(s) = I + s (n1 x n2). To compute
and the intersection point (given the line), the total number of operations =
11 adds + 19 multiplies.
One way of constructing a line in one plane that must intersect the other plane is to
project one plane's normal vector onto the other plane. This gives a line that must
always be orthogonal to the line of the planes' intersection. So, the projection
of n2 on P1 defines a line that intersects P2 in the sought for point P0 on L. More
specifically, project the two points 0 = (0,0,0) and n2 = (nx2, ny2, nz2) to P1(0)
and P1(n2) respectively. Then the projected line in P1 is L1: Q(t) = P1(0) + t (P1(n2)
P1(0)), and intersection of it with P2 can be computed. In the most efficient case,
where both n1 and n2 are unit normal vectors and the constant P1(0) is pre-stored,
the total operations = 17 adds + 22 multiplies.
(C) 3 Plane Intersect Point. Another method selects a third plane P3 with an
implicit equation n3 P = 0 where n3 = n1 x n2 and d3 = 0 (meaning it passes through
the origin). This always works since: (1) L is perpendicular to P3 and thus

intersects it, and (2) the vectors n1, n2, and n3 are linearly independent. Thus the
planes P1, P2 and P3 intersect in a unique point P0 which must be on L. Using the
formula for the intersection of 3 planes (see the next section), where d3 = 0 for P3,
we get:

and the parametric equation of L is:

The number of operations for this solution = 11 adds + 23 multiplies.


The bottom line is that the most efficient method is the direct solution (A) that
uses only 5 adds + 13 multiplies to compute the equation of the intersection line.

Intersection of 3 Planes
In 3D, three planes P1, P2 and P3 can intersect (or not) in the following ways:

Geometric Relation

Intersection

Algebraic Condition

All 3 planes are parallel


They coincide
They are disjoint

Only two planes are parallel, and


the 3rd plane cuts each in a line
[Note: the 2 parallel planes may coincide]

for all
A plane
None
2 parallel lines
[planes coincide
=> 1 line]

No two planes are parallel, so pairwise they


intersect in 3 lines

Only one

for

for all

intersect lines are parallel


They all coincide

1 line

They are disjoint

3 parallel lines

intersect lines are parallel

As shown in the illustrations:

A unique point

Test a point of one line with another


line
Same test, but fails => do not
coincide

One should first test for the most frequent case of a unique intersect point, namely
that
, since this excludes all the other cases. When the intersection
is a unique point, it is given by the formula:

which can verified by showing that this P0 satisfies the parametric equations for all
planes P1, P2 and P3.
However, there can be a problem with the robustness of this computation when the
denominator
is very small. In that case, it would be best to get a
robust line of intersection for two of the planes, and then compute the point where
this line intersects the third plane.

Implementations
Here are some sample "C++" implementations of these algorithms.
// Copyright 2001 softSurfer, 2012 Dan Sunday
// This code may be freely used, distributed and modified for any
purpose
// providing that this copyright notice is included with it.
// SoftSurfer makes no warranty for this code, and cannot be held
// liable for any real or imagined damage resulting from its use.
// Users of this code must verify correctness for their
application.
// Assume that classes are already given for the objects:
//
Point and Vector with
//
coordinates {float x, y, z;}
//
operators for:
//
== to test equality
//
!= to test inequality
//
Point
= Point Vector
//
Vector = Point - Point
//
Vector = Scalar * Vector
(scalar product)
//
Vector = Vector * Vector
(3D cross product)
//
Line and Ray and Segment with defining points {Point P0,

P1;}
//
(a Line is infinite, Rays and Segments start at P0)
//
(a Ray extends beyond P1, but a Segment ends at P1)
//
Plane with a point and a normal {Point V0; Vector n;}
//===============================================================
====
#define SMALL_NUM
0.00000001 // anything that avoids division
overflow
// dot product (3D) which allows vector operations in arguments
#define dot(u,v)
((u).x * (v).x + (u).y * (v).y + (u).z *
(v).z)
#define perp(u,v) ((u).x * (v).y - (u).y * (v).x) // perp
product (2D)

// intersect2D_2Segments(): find the 2D intersection of 2 finite


segments
//
Input: two finite segments S1 and S2
//
Output: *I0 = intersect point (when it exists)
//
*I1 = endpoint of intersect segment [I0,I1] (when
it exists)
//
Return: 0=disjoint (no intersect)
//
1=intersect in unique point I0
//
2=overlap in segment from I0 to I1
int
intersect2D_2Segments( Segment S1, Segment S2, Point* I0, Point*
I1 )
{
Vector
u = S1.P1 - S1.P0;
Vector
v = S2.P1 - S2.P0;
Vector
w = S1.P0 - S2.P0;
float
D = perp(u,v);
// test if they are parallel (includes either being a point)
if (fabs(D) < SMALL_NUM) {
// S1 and S2 are
parallel
if (perp(u,w) != 0 || perp(v,w) != 0) {
return 0;
// they are NOT
collinear
}
// they are collinear or degenerate
// check if they are degenerate points
float du = dot(u,u);
float dv = dot(v,v);

if (du==0 && dv==0) {

// both segments are

if (S1.P0 !=

// they are distinct

points
S2.P0)

points
return 0;
*I0 = S1.P0;

// they are the same

point
return 1;
}
if (du==0) {
// S1 is a single point
if (inSegment(S1.P0, S2) == 0) // but is not in S2
return 0;
*I0 = S1.P0;
return 1;
}
if (dv==0) {
// S2 a single point
if (inSegment(S2.P0, S1) == 0) // but is not in S1
return 0;
*I0 = S2.P0;
return 1;
}
// they are collinear segments - get overlap (or not)
float t0, t1;
// endpoints of S1 in
eqn for S2
Vector w2 = S1.P1 - S2.P0;
if (v.x != 0) {
t0 = w.x / v.x;
t1 = w2.x / v.x;
}
else {
t0 = w.y / v.y;
t1 = w2.y / v.y;
}
if (t0 > t1) {
// must have t0 smaller
than t1
float t=t0; t0=t1; t1=t;
// swap if not
}
if (t0 > 1 || t1 < 0) {
return 0;
// NO overlap
}
t0 = t0<0? 0 : t0;
// clip to min 0
t1 = t1>1? 1 : t1;
// clip to max 1
if (t0 == t1) {
// intersect is a point
*I0 = S2.P0 + t0 * v;
return 1;
}

// they overlap in a valid subsegment


*I0 = S2.P0 + t0 * v;
*I1 = S2.P0 + t1 * v;
return 2;
}
// the segments are skew and may intersect in a point
// get the intersect parameter for S1
float
sI = perp(v,w) / D;
if (sI < 0 || sI > 1)
// no intersect with S1
return 0;
// get the intersect parameter for S2
float
tI = perp(u,w) / D;
if (tI < 0 || tI > 1)
// no intersect with S2
return 0;
*I0 = S1.P0 + sI * u;
// compute S1 intersect
point
return 1;
}
//===============================================================
====

// inSegment(): determine if a point is inside a segment


//
Input: a point P, and a collinear segment S
//
Return: 1 = P is inside S
//
0 = P is not inside S
int
inSegment( Point P, Segment S)
{
if (S.P0.x != S.P1.x) {
// S is not vertical
if (S.P0.x <= P.x && P.x <= S.P1.x)
return 1;
if (S.P0.x >= P.x && P.x >= S.P1.x)
return 1;
}
else {
// S is vertical, so test y coordinate
if (S.P0.y <= P.y && P.y <= S.P1.y)
return 1;
if (S.P0.y >= P.y && P.y >= S.P1.y)
return 1;
}
return 0;
}

//===============================================================
====

// intersect3D_SegmentPlane(): find the 3D intersection of a


segment and a plane
//
Input: S = a segment, and Pn = a plane = {Point V0;
Vector n;}
//
Output: *I0 = the intersect point (when it exists)
//
Return: 0 = disjoint (no intersection)
//
1 = intersection in the unique point *I0
//
2 = the segment lies in the plane
int
intersect3D_SegmentPlane( Segment S, Plane Pn, Point* I )
{
Vector
u = S.P1 - S.P0;
Vector
w = S.P0 - Pn.V0;
float
float

D = dot(Pn.n, u);
N = -dot(Pn.n, w);

if (fabs(D) < SMALL_NUM) {


to plane
if (N == 0)
return 2;
else
return 0;
}
// they are not parallel
// compute intersect param
float sI = N / D;
if (sI < 0 || sI > 1)
return 0;

// segment is parallel
// segment lies in plane
// no intersection

// no intersection

*I = S.P0 + sI * u;
// compute segment
intersect point
return 1;
}
//===============================================================
====

// intersect3D_2Planes(): find the 3D intersection of two planes


//
Input: two planes Pn1 and Pn2
//
Output: *L = the intersection line (when it exists)

//
Return: 0 = disjoint (no intersection)
//
1 = the two planes coincide
//
2 = intersection in the unique line *L
int
intersect3D_2Planes( Plane Pn1, Plane Pn2, Line* L )
{
Vector
u = Pn1.n * Pn2.n;
// cross product
float
ax = (u.x >= 0 ? u.x : -u.x);
float
ay = (u.y >= 0 ? u.y : -u.y);
float
az = (u.z >= 0 ? u.z : -u.z);
// test if the two planes are parallel
if ((ax+ay+az) < SMALL_NUM) {
//
parallel
// test if disjoint or coincide
Vector
v = Pn2.V0 - Pn1.V0;
if (dot(Pn1.n, v) == 0)
//
return 1;
//
else
return 0;
//
disjoint
}

Pn1 and Pn2 are near

Pn2.V0 lies in Pn1


Pn1 and Pn2 coincide
Pn1 and Pn2 are

// Pn1 and Pn2 intersect in a line


// first determine max abs coordinate of cross product
int
maxc;
// max coordinate
if (ax > ay) {
if (ax > az)
maxc = 1;
else maxc = 3;
}
else {
if (ay > az)
maxc = 2;
else maxc = 3;
}
// next, to get a point on
// zero the max coord, and
Point
iP;
float
d1, d2;
equations
d1 = -dot(Pn1.n, Pn1.V0);
plane
d2 = -dot(Pn2.n, Pn2.V0);
switch (maxc) {

the intersect line


solve for the other two
// intersect point
// the constants in the 2 plane
// note: could be pre-stored
// ditto
// select max coordinate

with

case 1:
iP.x = 0;
iP.y = (d2*Pn1.n.z
iP.z = (d1*Pn2.n.y
break;
case 2:
iP.x = (d1*Pn2.n.z
iP.y = 0;
iP.z = (d2*Pn1.n.x
break;
case 3:
iP.x = (d2*Pn1.n.y
iP.y = (d1*Pn2.n.x
iP.z = 0;
}
L->P0 = iP;
L->P1 = iP + u;
return 2;

// intersect with x=0


- d1*Pn2.n.z) /
- d2*Pn1.n.y) /

u.x;
u.x;

// intersect with y=0


- d2*Pn1.n.z) / u.y;
- d1*Pn2.n.x) /

u.y;

// intersect with z=0


- d1*Pn2.n.y) / u.z;
- d2*Pn1.n.x) / u.z;

You might also like