青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

Point in triangle test

http://www.blackpawn.com/texts/pointinpoly/default.html

Same Side Technique

A common way to check if a point is in a triangle is to find the vectors connecting the point to each of the triangle's three vertices and sum the angles between those vectors. If the sum of the angles is 2*pi then the point is inside the triangle, otherwise it is not. It works, but it is very slow. This text explains a faster and much easier method.

First off, forgive the nasty coloring. I'm really sorry about it. Honest.

Okay, A B C forms a triangle and all the points inside it are yellow. Lines AB, BC, and CA each split space in half and one of those halves is entirely outside the triangle. This is what we'll take advantage of.

For a point to be inside the traingle A B C it must be below AB and left of BC and right of AC. If any one of these tests fails we can return early.

But, how do we tell if a point is on the correct side of a line? I'm glad you asked.


If you take the cross product of [B-A] and [p-A], you'll get a vector pointing out of the screen. On the other hand, if you take the cross product of [B-A] and [p'-A] you'll get a vector pointing into the screen. Ah ha! In fact if you cross [B-A] with the vector from A to any point above the line AB, the resulting vector points out of the screen while using any point below AB yields a vector pointing into the screen. So all we need to do to distinguish which side of a line a point lies on is take a cross product.

The only question remaining is: how do we know what direction the cross product should point in? Because the triangle can be oriented in any way in 3d-space, there isn't some set value we can compare with. Instead what we need is a reference point - a point that we know is on a certain side of the line. For our triangle, this is just the third point C.

So, any point p where [B-A] cross [p-A] does not point in the same direction as [B-A] cross [C-A] isn't inside the triangle. If the cross products do point in the same direction, then we need to test p with the other lines as well. If the point was on the same side of AB as C and is also on the same side of BC as A and on the same side of CA as B, then it is in the triangle.

Implementing this is a breeze. We'll make a function that tells us if two points are on the same side of a line and have the actual point-in-triangle function call this for each edge.

function SameSide(p1,p2, a,b)
            cp1 = CrossProduct(b-a, p1-a)
            cp2 = CrossProduct(b-a, p2-a)
            if DotProduct(cp1, cp2) >= 0 then return true
            else return false
            function PointInTriangle(p, a,b,c)
            if SameSide(p,a, b,c) and SameSide(p,b, a,c)
            and SameSide(p,c, a,b) then return true
            else return false
            

It's simple, effective and has no square roots, arc cosines, or strange projection axis determination nastiness.



Barycentric Technique

The advantage of the method above is that it's very simple to understand so that once you read it you should be able to remember it forever and code it up at any time without having to refer back to anything. It's just - hey the point has to be on the same side of each line as the triangle point that's not in the line. Cake.

Well, there's another method that is also as easy conceptually but executes faster. The downside is there's a little more math involved, but once you see it worked out it should be no problem.

So remember that the three points of the triangle define a plane in space. Pick one of the points and we can consider all other locations on the plane as relative to that point. Let's go with A -- it'll be our origin on the plane. Now what we need are basis vectors so we can give coordinate values to all the locations on the plane. We'll pick the two edges of the triangle that touch A, (C - A) and (B - A). Now we can get to any point on the plane just by starting at A and walking some distance along (C - A) and then from there walking some more in the direction (B - A).

With that in mind we can now describe any point on the plane as

    P = A + u * (C - A) + v * (B - A)

Notice now that if u or v < 0 then we've walked in the wrong direction and must be outside the triangle. Also if u or v > 1 then we've walked too far in a direction and are outside the triangle. Finally if u + v > 1 then we've crossed the edge BC again leaving the triangle.

Given u and v we can easily calculate the point P with the above equation, but how can we go in the reverse direction and calculate u and v from a given point P? Time for some math!

    P = A + u * (C - A) + v * (B - A)       // Original equation
(P - A) = u * (C - A) + v * (B - A)     // Subtract A from both sides
v2 = u * v0 + v * v1                    // Substitute v0, v1, v2 for less writing
// We have two unknowns (u and v) so we need two equations to solve
// for them.  Dot both sides by v0 to get one and dot both sides by
// v1 to get a second.
(v2) . v0 = (u * v0 + v * v1) . v0
(v2) . v1 = (u * v0 + v * v1) . v1
// Distribute v0 and v1
v2 . v0 = u * (v0 . v0) + v * (v1 . v0)
v2 . v1 = u * (v0 . v1) + v * (v1 . v1)
// Now we have two equations and two unknowns and can solve one
// equation for one variable and substitute into the other.  Or
// if you're lazy like me, fire up Mathematica and save yourself
// some handwriting.
Solve[v2.v0 == {u(v0.v0) + v(v1.v0), v2.v1 == u(v0.v1) + v(v1.v1)}, {u, v}]
u = ((v1.v1)(v2.v0)-(v1.v0)(v2.v1)) / ((v0.v0)(v1.v1) - (v0.v1)(v1.v0))
v = ((v0.v0)(v2.v1)-(v0.v1)(v2.v0)) / ((v0.v0)(v1.v1) - (v0.v1)(v1.v0))

Here's an implementation in Flash that you can play with. :)

// Compute vectors
                v0 = C - A
                v1 = B - A
                v2 = P - A
                // Compute dot products
                dot00 = dot(v0, v0)
                dot01 = dot(v0, v1)
                dot02 = dot(v0, v2)
                dot11 = dot(v1, v1)
                dot12 = dot(v1, v2)
                // Compute barycentric coordinates
                invDenom = 1 / (dot00 * dot11 - dot01 * dot01)
                u = (dot11 * dot02 - dot01 * dot12) * invDenom
                v = (dot00 * dot12 - dot01 * dot02) * invDenom
                // Check if point is in triangle
                return (u > 0) && (v > 0) && (u + v < 1)
                

The algorithm outlined here follows one of the techniques described in Realtime Collision Detection. You can also find more information about Barycentric Coordinates at Wikipedia and MathWorld.

posted on 2008-08-25 15:57 zmj 閱讀(2103) 評(píng)論(9)  編輯 收藏 引用

評(píng)論

# re: Point in triangle test 2012-03-12 19:19 Mccullough32Freda

No matter what kind of internet business you have, little or great, you will need your site to have got a good traffic. You will get that using the <a href="http://cheap-link-building.com/submit_to_directories.htm">submission directory</a> service with optimization options.   回復(fù)  更多評(píng)論   

# re: Point in triangle test 2013-04-13 17:45 OvernightEssay.com testimonials

Have a desire to know more about paper writing services? Hunting for trusty writing centre to obtain aid from? SpecialEssays rewiew will give you a listing of agencies from which pupils can choose the most qualified ones to buy term paper from.  回復(fù)  更多評(píng)論   

# re: Point in triangle test 2013-04-18 03:11 resume writing services

Are you hunting which service to choose for buying resume or where to receive sample of cover letter and help with resume writing? Or you simply want to buy resumes from best resume writers? Only contact Resume company "exclusiveresume.com".  回復(fù)  更多評(píng)論   

# re: Point in triangle test 2013-04-25 20:13 Resumesexpert.com

Need to write a resume? Do not know where to buy resume paper? View this Resumes Expert company resumesexpert.com where you can find professional resume writers review. Our expert resume writers will reassure you that buying resume can bring job seekers real success!  回復(fù)  更多評(píng)論   


只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲午夜精品视频| 久久精品中文字幕一区二区三区| 亚洲免费影视| 亚洲性人人天天夜夜摸| 亚洲中无吗在线| 欧美亚洲综合另类| 久久这里有精品视频| 欧美sm视频| 亚洲精品乱码久久久久久久久| 亚洲第一精品夜夜躁人人爽| 亚洲激情自拍| 亚洲视频欧美视频| 欧美一区二区视频观看视频| 久久久久国产精品厨房| 免费日韩av片| 国产精品一区二区三区四区| 很黄很黄激情成人| 99国产精品久久久久久久成人热 | 欧美绝品在线观看成人午夜影视| 欧美激情精品久久久久久| 欧美日韩直播| 国产在线观看精品一区二区三区| 亚洲日产国产精品| 亚洲欧美一区在线| 欧美大色视频| 亚洲香蕉网站| 欧美福利一区二区| 好吊妞这里只有精品| 久久精品国产清高在天天线| 久久视频在线视频| 国产精品露脸自拍| 亚洲国产日本| 久久久久久久尹人综合网亚洲| 亚洲欧洲在线一区| 久久九九国产精品| 国产老肥熟一区二区三区| 亚洲伦理精品| 快射av在线播放一区| 欧美国产日本| 亚洲高清视频的网址| 亚洲一区二区免费看| 欧美好骚综合网| 韩国三级电影久久久久久| 亚洲午夜久久久久久久久电影院| 欧美成人精品在线| 久久精品在线播放| 黄色成人av网| 久久精品九九| 亚洲欧美在线一区| 欧美午夜精品久久久久久孕妇| 亚洲人成毛片在线播放女女| 久久婷婷亚洲| 久久国产精品99精品国产| 国产精品日本欧美一区二区三区| 一区二区国产日产| 亚洲日本黄色| 欧美黄网免费在线观看| 亚洲精品中文字| 亚洲国产福利在线| 媚黑女一区二区| 亚洲国产99| 欧美成人亚洲| 美女日韩欧美| 亚洲精品1区2区| 欧美激情一区二区三区高清视频 | 亚洲综合色丁香婷婷六月图片| 亚洲国产一区二区三区青草影视| 老色鬼精品视频在线观看播放| 亚洲第一精品夜夜躁人人躁| 久久人人97超碰精品888| 欧美一区亚洲| 在线观看欧美一区| 亚洲国产日韩欧美| 欧美三级午夜理伦三级中视频| 亚洲一区二区三区在线观看视频| 亚洲高清视频在线观看| 久久最新视频| 欧美不卡一区| 午夜精品免费视频| 久久麻豆一区二区| 日韩午夜中文字幕| 亚洲视频图片小说| 国产日韩欧美精品一区| 久久综合九色综合欧美狠狠| 免费在线成人av| 亚洲网站在线看| 欧美一区二区精美| 亚洲精品一二| 亚洲欧美一区二区三区极速播放| 在线不卡中文字幕| 日韩视频国产视频| 国产自产高清不卡| 91久久精品一区二区三区| 国产精品色婷婷| 欧美大胆成人| 国产精品免费aⅴ片在线观看| 久久综合一区二区| 亚洲国产另类久久精品| 亚洲国产精品久久91精品| 国产精品v日韩精品| 久久婷婷蜜乳一本欲蜜臀| 欧美日韩第一区日日骚| 久久久久久一区二区| 欧美日韩国产美女| 久久亚洲综合网| 欧美日韩国内自拍| 免费av成人在线| 国产精品免费久久久久久| 欧美激情小视频| 国户精品久久久久久久久久久不卡| 亚洲精品视频在线播放| 国产亚洲欧美日韩一区二区| 99精品视频免费全部在线| 在线观看视频欧美| 欧美亚洲日本网站| 亚洲综合导航| 欧美日本国产一区| 六十路精品视频| 国产日韩欧美精品一区| 亚洲午夜电影网| 99在线观看免费视频精品观看| 久久精品国产清自在天天线| 午夜精品久久久久久久白皮肤| 欧美激情第六页| 亚洲丶国产丶欧美一区二区三区 | 国产精品综合| 亚洲精品国久久99热| 国内精品伊人久久久久av一坑| 亚洲精品免费一二三区| 午夜精品成人在线| 欧美一区二区三区成人| 欧美日本视频在线| 亚洲国产视频直播| 亚洲国产精品成人va在线观看| 久久精品国产2020观看福利| 欧美自拍偷拍| 国产一区二区三区网站| 午夜视频一区在线观看| 欧美在线免费观看| 国产人成精品一区二区三| 亚洲欧美中文字幕| 久久精品成人欧美大片古装| 国产视频在线一区二区| 欧美一区午夜视频在线观看| 裸体女人亚洲精品一区| 一区视频在线看| 久久中文字幕一区| 欧美成人精品h版在线观看| 在线观看日韩欧美| 免费在线观看日韩欧美| 亚洲黄色成人久久久| 一本色道**综合亚洲精品蜜桃冫| 欧美日韩精品三区| 一区二区三区欧美| 亚洲欧美日韩国产一区二区三区 | 国产亚洲毛片| 久久国产黑丝| 亚洲第一毛片| 亚洲午夜一区| 国产字幕视频一区二区| 蜜桃av久久久亚洲精品| 亚洲欧洲一级| 欧美日本国产在线| 久久久久久高潮国产精品视| 在线精品在线| 欧美日韩福利在线观看| 亚洲午夜免费福利视频| 久久亚洲一区| 一本色道久久综合精品竹菊| 国产日韩一区二区三区| 久久伊人免费视频| av不卡在线| 可以免费看不卡的av网站| 一区二区三区高清不卡| 韩曰欧美视频免费观看| 欧美日精品一区视频| 欧美在线一区二区| 99re热这里只有精品免费视频| 久久久国产一区二区| 一区二区欧美精品| 精久久久久久久久久久| 欧美日韩一区二区视频在线| 久久久久久久一区二区| 一区二区三区日韩| 亚洲电影欧美电影有声小说| 欧美一区二区三区在线观看| 日韩午夜中文字幕| 在线日韩中文字幕| 国产亚洲亚洲| 国产精品综合av一区二区国产馆| 欧美韩日视频| 麻豆成人在线播放| 午夜精品视频一区| 亚洲精品社区| 欧美激情一二三区| 免费一区二区三区| 久久一本综合频道| 欧美一区二区三区的| 亚洲欧美国产精品va在线观看| 亚洲美女在线视频|