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

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>
            欧美成人精品h版在线观看| 欧美高清hd18日本| 亚洲美女一区| 亚洲福利视频一区| 欧美日韩国产123区| 久久久国产精品一区二区三区| 久久午夜精品| 亚洲人成在线观看一区二区| 欧美成人一区二区三区| 一区二区三区免费网站| 久久精品视频99| 在线精品视频一区二区| 欧美寡妇偷汉性猛交| 伊人久久大香线蕉av超碰演员| 99re66热这里只有精品4 | 久久精品一区二区三区中文字幕| 欧美一区二区三区视频在线| 狠狠色伊人亚洲综合成人 | 免费成人在线观看视频| 一区二区三区视频观看| 国产精品卡一卡二卡三| 久久夜色精品国产欧美乱| 国产免费观看久久黄| 久久人体大胆视频| 中文久久精品| 亚洲一区二区三区精品视频| 亚洲精品亚洲人成人网| 巨胸喷奶水www久久久免费动漫| 一二三区精品福利视频| 国产精品福利网站| 久久精品国产欧美亚洲人人爽| 亚洲视频综合| 一本色道久久综合亚洲精品小说| 亚洲国产另类 国产精品国产免费| 一区二区精品国产| 国产精自产拍久久久久久蜜| 国产精品毛片| 国产日韩欧美综合精品| 国产精品欧美在线| 国产欧美精品国产国产专区| 国产精品久久久一区二区三区| 亚洲欧美一区二区三区久久 | 久久精品国产免费观看| 亚洲一区二区在线免费观看| 亚洲视频在线观看三级| 欧美激情精品久久久久久黑人| 国产精品久久久久久久久| 老色批av在线精品| 亚洲一区黄色| 久久久国产亚洲精品| 久热精品视频在线观看| 欧美一区二区三区婷婷月色| 久久一区欧美| 国产精品极品美女粉嫩高清在线 | 国产日韩欧美麻豆| 一本色道久久99精品综合| 亚洲免费av电影| 亚洲免费影院| 欧美国产精品中文字幕| 狠狠综合久久| 性色av一区二区三区红粉影视| 久久久免费精品视频| 亚洲国产成人精品女人久久久| 一本一本久久a久久精品综合妖精| 亚洲免费中文字幕| 欧美日韩国语| 亚洲高清影视| 欧美成人精品1314www| 在线午夜精品自拍| 欧美午夜电影一区| 亚洲欧美激情诱惑| 一本色道久久综合亚洲91| 欧美顶级少妇做爰| 国内外成人免费激情在线视频| 亚洲日韩成人| 亚洲综合色丁香婷婷六月图片| 欧美日韩一区综合| 国产一区二区成人久久免费影院| 国外成人在线视频网站| 亚洲精品美女久久7777777| 亚洲综合首页| 久久精品国产v日韩v亚洲| 欧美成人免费全部观看天天性色| 亚洲天堂av综合网| 国产精品久久久久aaaa九色| 亚洲国产美女| 亚洲高清自拍| 亚洲国产综合在线看不卡| 在线精品国精品国产尤物884a| 久久久91精品| 亚洲成在人线av| 久久久久久网站| 在线国产精品一区| 亚洲欧美高清| 亚洲黄色在线观看| 国产精品国产三级国产专播精品人 | 亚洲午夜性刺激影院| 91久久夜色精品国产网站| 久久精品亚洲一区二区三区浴池| 美国十次成人| 亚洲精品一区二区在线观看| 亚洲精品九九| 久久色在线播放| 国产精品视频午夜| 在线观看成人av电影| 久久综合中文字幕| 亚洲欧美日韩在线高清直播| 国产精品久久久亚洲一区| 欧美性开放视频| 夜夜嗨av一区二区三区| 亚洲国产一区视频| 欧美国产视频一区二区| 亚洲一区三区电影在线观看| 亚洲精品小视频| 国产精品久久久久久久久久妞妞 | 亚洲一区二区三区成人在线视频精品| 久久精品视频导航| 国产精品久久久久秋霞鲁丝 | 亚洲免费观看| 欧美韩日一区二区| 免费成人黄色| 一本久久青青| 亚洲自拍三区| 亚洲精品你懂的| 日韩视频一区二区三区在线播放免费观看| 久久久一区二区三区| ●精品国产综合乱码久久久久| 久久久亚洲综合| 欧美精品免费在线| 午夜免费日韩视频| 嫩草影视亚洲| 亚洲欧洲偷拍精品| 亚洲精品色婷婷福利天堂| 欧美三日本三级少妇三99| 欧美理论电影在线观看| 国产一区二区精品久久91| 欧美国产日韩在线| 欧美自拍偷拍| 亚洲欧美在线磁力| 美脚丝袜一区二区三区在线观看| 亚洲国产精品黑人久久久 | 精品动漫3d一区二区三区| 一区二区三区四区精品| 国产亚洲一区在线播放| 亚洲国产精品久久91精品| 国产精品一区视频| 老司机免费视频久久| 国产精品五月天| 夜夜精品视频| 亚洲综合第一页| 免费看精品久久片| 欧美成人精品激情在线观看 | 国外成人在线视频网站| 国产精品99久久久久久久久久久久 | 亚洲免费精品| 欧美日韩一区二区三区视频| 久久精品国产综合| 亚洲人www| 亚洲人成啪啪网站| 亚洲激情另类| 激情丁香综合| 在线综合亚洲欧美在线视频| 在线亚洲一区| 在线观看亚洲视频啊啊啊啊| 最新成人av网站| 欧美日韩成人一区二区| 欧美一区二区三区四区在线| 久久综合婷婷| 日韩一区二区高清| 日韩亚洲欧美精品| 欧美成人精品影院| 国产一区二区三区免费观看| 麻豆精品精华液| 影音先锋国产精品| 亚洲黄页一区| 国产精品www网站| 亚洲老板91色精品久久| 亚洲激情视频网| 国产精品久久久久久av福利软件 | 欧美天天在线| 一区二区激情小说| 久久久免费精品| 亚洲一区二区网站| 国产精品99一区| 极品少妇一区二区三区| 国产色综合久久| 亚洲欧美精品在线观看| 久久国产精品亚洲77777| 激情五月婷婷综合| 欧美日韩一区二区三区四区在线观看 | 欧美成人免费在线观看| 久久激情网站| 亚洲高清视频的网址| 亚洲影音一区| 国产亚洲欧美中文| 欧美日韩成人精品| 性做久久久久久| 99精品欧美一区二区三区综合在线| 久久男人资源视频| 久久精品国产亚洲5555|