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

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) 評論(9)  編輯 收藏 引用

評論

# 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.   回復  更多評論   

# 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.  回復  更多評論   

# 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".  回復  更多評論   

# 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!  回復  更多評論   


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   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>
            欧美xxx成人| 蜜桃av一区| 亚洲欧美中文字幕| 久久综合九色综合欧美就去吻| 亚洲三级免费电影| 亚洲视频视频在线| 久久久久成人精品| 国产精品免费观看在线| 亚洲精品乱码久久久久久日本蜜臀| 亚洲性视频网址| 亚洲人成毛片在线播放女女| 久久久午夜电影| 国语自产精品视频在线看抢先版结局 | 国产精品久久久久久妇女6080 | 欧美精品一区二区蜜臀亚洲 | 久久久久青草大香线综合精品| 中日韩美女免费视频网站在线观看| 欧美激情亚洲精品| 亚洲国产mv| 亚洲福利视频一区| 欧美fxxxxxx另类| 最近中文字幕日韩精品| 亚洲第一成人在线| 欧美国产第一页| 在线一区二区三区做爰视频网站 | 亚洲激情黄色| 蜜臀久久久99精品久久久久久| 亚洲欧美综合精品久久成人| 国产欧美精品日韩区二区麻豆天美| 欧美影视一区| 久久精品国产91精品亚洲| 韩国精品久久久999| 蜜桃av一区二区三区| 欧美不卡视频一区发布| 99国产精品自拍| 在线午夜精品自拍| 国产日韩亚洲欧美| 欧美成人高清视频| 欧美日韩国产电影| 小黄鸭精品aⅴ导航网站入口| 欧美在线一二三| 亚洲另类自拍| 亚洲欧美第一页| 国内外成人在线| 欧美福利视频一区| 欧美视频免费在线| 久久手机精品视频| 欧美伦理视频网站| 欧美资源在线观看| 免播放器亚洲一区| 亚洲影院色在线观看免费| 午夜精品久久一牛影视| 亚洲国产1区| 亚洲综合不卡| 亚洲人屁股眼子交8| 一区二区三区不卡视频在线观看 | 亚洲你懂的在线视频| 午夜精品久久久久久久99热浪潮| 亚洲国产综合在线| 亚洲欧美日韩国产中文在线| 136国产福利精品导航| 9国产精品视频| 一区久久精品| 亚洲在线观看免费| 日韩亚洲精品电影| 欧美在线视频观看| 亚洲小说欧美另类婷婷| 久久精品在线免费观看| 国产精品99久久久久久www| 久久久水蜜桃av免费网站| 午夜视频精品| 欧美午夜三级| 亚洲精品久久久久久一区二区| 黄色av成人| 性色av一区二区三区| 亚洲一区二区久久| 欧美日韩成人一区二区| 亚洲国产91色在线| 亚洲国产美女| 六十路精品视频| 免费不卡视频| 在线看欧美视频| 久久久久国产一区二区三区四区| 欧美一区二区三区的| 国产精品久久久久久久久久免费| 亚洲国产欧洲综合997久久| 狠色狠色综合久久| 久久久人成影片一区二区三区| 久久精品91| 国产一区二区三区网站| 亚洲欧美一区二区原创| 国产精品女人久久久久久| 日韩视频亚洲视频| 日韩一区二区精品葵司在线| 免费在线亚洲| 亚洲第一狼人社区| 亚洲精品黄色| 欧美精品日韩一区| 亚洲精品在线视频观看| 亚洲视频精品| 国产精品国产成人国产三级| 在线一区视频| 欧美一级在线播放| 国产在线视频不卡二| 久久国产婷婷国产香蕉| 免费久久99精品国产| 亚洲人成网站777色婷婷| 欧美高清免费| 中日韩美女免费视频网址在线观看 | 久久久久久夜精品精品免费| 久久综合久久综合久久综合| 精品不卡一区二区三区| 久久这里有精品视频| 亚洲高清视频在线| 中日韩视频在线观看| 国产精品久久久久久妇女6080| 欧美一级电影久久| 欧美国产日韩在线| 亚洲精选一区| 国产精品久久久久91| 久久精品卡一| 亚洲精品色图| 久久久久久9| 亚洲精品免费网站| 国产精品日韩在线观看| 欧美一级片一区| 亚洲国产精品一区二区第四页av | 欧美大片va欧美在线播放| 91久久精品国产91久久| 欧美性天天影院| 久久久国产午夜精品| 最新高清无码专区| 久久成人精品电影| 亚洲九九九在线观看| 国产精品一区二区久久精品| 美女露胸一区二区三区| 亚洲一区二区三区久久| 欧美大片在线观看| 午夜激情综合网| 亚洲精品一区中文| 国产欧美一区二区三区沐欲| 麻豆成人综合网| 亚洲欧美日本日韩| 亚洲精品一区二区三区av| 久久久久久成人| 亚洲一区二区三区777| 亚洲电影免费观看高清完整版在线| 欧美亚州在线观看| 欧美激情精品久久久久久大尺度 | 国产精品视频精品| 欧美激情自拍| 久久久亚洲精品一区二区三区 | 亚洲激情欧美激情| 国产精品色一区二区三区| 欧美成人有码| 性欧美8khd高清极品| 亚洲美女黄色| 亚洲国产精品女人久久久| 久久最新视频| 久久精品久久综合| 亚洲视频免费在线| 亚洲激情视频在线| 合欧美一区二区三区| 国产精品视频精品| 欧美午夜精品久久久久久超碰| 欧美激情女人20p| 久久综合婷婷| 久久青草欧美一区二区三区| 亚洲综合首页| 亚洲综合国产| 一区二区三区欧美视频| 亚洲激情偷拍| 亚洲黄网站在线观看| 欧美激情导航| 欧美大片在线观看一区二区| 美女黄毛**国产精品啪啪| 久久久999精品免费| 久久精品国产亚洲一区二区三区| 欧美一区二区三区久久精品| 亚洲一区二区高清视频| 亚洲综合电影一区二区三区| 亚洲制服欧美中文字幕中文字幕| 亚洲性夜色噜噜噜7777| 亚洲女性裸体视频| 欧美专区在线观看| 久久精品在线播放| 久久久久99精品国产片| 久久免费视频网站| 美女网站在线免费欧美精品| 免费一区二区三区| 亚洲福利视频三区| 99伊人成综合| 午夜精品视频在线观看一区二区| 午夜精品久久久久影视| 久久婷婷人人澡人人喊人人爽| 久久综合电影| 欧美精品一二三| 国产精品久久久久久一区二区三区| 国产精品欧美日韩一区| 国产婷婷色综合av蜜臀av|