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

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 閱讀(2054) 評論(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.   回復(fù)  更多評論   

# 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ù)  更多評論   

# 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ù)  更多評論   

# 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ù)  更多評論   


只有注冊用戶登錄后才能發(fā)表評論。
網(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>
            亚洲一区二区伦理| 日韩午夜中文字幕| 久久久久88色偷偷免费| 国产综合久久久久久鬼色| 欧美一级片一区| 久久福利电影| 亚洲欧洲精品一区二区| 亚洲精品美女在线观看| 欧美日韩精品久久久| 亚洲欧美日本另类| 久久疯狂做爰流白浆xx| 日韩视频免费观看| 9人人澡人人爽人人精品| 国产亚洲激情| 久久中文精品| 欧美日韩国产成人在线观看| 欧美一区二区高清| 嫩模写真一区二区三区三州| 亚洲免费影视| 久久只精品国产| 亚洲欧美不卡| 免费欧美在线视频| 性欧美video另类hd性玩具| 巨乳诱惑日韩免费av| 亚洲欧美日韩另类| 母乳一区在线观看| 欧美在线影院在线视频| 欧美精品在线一区二区三区| 久久成人一区| 欧美久久久久久蜜桃| 久久婷婷国产综合尤物精品| 欧美日韩精品欧美日韩精品一| 久久精品视频免费| 欧美三区视频| 亚洲电影激情视频网站| 国产视频在线一区二区 | 亚洲第一在线视频| 亚洲综合三区| 一区二区日韩精品| 免费亚洲网站| 麻豆freexxxx性91精品| 国产精品欧美在线| 日韩一区二区电影网| 亚洲国产小视频| 久久久久久久久久久久久女国产乱 | 精久久久久久| 亚洲综合首页| 香蕉精品999视频一区二区| 欧美精品日韩一区| 欧美成人精品一区二区三区| 韩国av一区二区三区四区| 亚洲女女女同性video| 亚洲欧美日韩一区在线| 欧美四级伦理在线| 日韩一级不卡| 中文在线不卡| 国产精品v欧美精品v日韩精品| 亚洲精品一区二| 一本色道久久综合亚洲二区三区| 欧美国产日本高清在线| 欧美韩日视频| 亚洲精品日产精品乱码不卡| 欧美成人精品一区二区三区| 亚洲第一在线综合网站| 亚洲人妖在线| 欧美人成在线视频| 在线亚洲欧美专区二区| 亚洲欧美日韩中文播放| 国产欧美日韩精品a在线观看| 亚洲欧美综合网| 久久这里只精品最新地址| 亚洲国产高清高潮精品美女| 久久夜精品va视频免费观看| 亚洲第一毛片| 亚洲午夜精品福利| 国产视频久久久久久久| 久久久噜噜噜久久人人看| 亚洲电影免费观看高清| 亚洲视频成人| 国产日韩欧美夫妻视频在线观看| 久久成人一区二区| 亚洲高清av| 午夜精品久久| 在线观看久久av| 欧美日韩成人综合天天影院| 亚洲免费视频网站| 欧美11—12娇小xxxx| 一区二区三区成人精品| 国产亚洲福利一区| 欧美高清视频www夜色资源网| 一本一本久久a久久精品牛牛影视| 久久av老司机精品网站导航| 亚洲国产日韩一区| 欧美日韩综合另类| 久久精品国产久精国产爱| 亚洲三级免费| 久久全球大尺度高清视频| 一本久久青青| 精久久久久久| 国产精品国产三级国产aⅴ浪潮| 久久九九久精品国产免费直播| 亚洲国内高清视频| 久久久精品午夜少妇| 一本色道久久综合一区| 精品电影一区| 国产精品爽爽爽| 欧美精品在线网站| 久久综合一区二区三区| 亚洲影院色在线观看免费| 亚洲国产欧美一区二区三区久久| 欧美一区二区在线观看| 99这里只有精品| 在线观看亚洲一区| 国产午夜亚洲精品羞羞网站| 欧美色大人视频| 欧美高清免费| 麻豆精品网站| 久久久精品日韩| 香蕉久久夜色精品| 亚洲视频在线播放| 日韩视频不卡中文| 国产综合欧美| 欧美激情第8页| av成人国产| 女人香蕉久久**毛片精品| 欧美激情第三页| 久久精视频免费在线久久完整在线看| 91久久国产自产拍夜夜嗨| 国产欧美日韩综合| 欧美日本网站| 欧美区在线播放| 欧美大片免费观看| 欧美大片在线影院| 欧美成人免费大片| 欧美韩日一区二区三区| 久热精品视频在线观看| 久久久精品欧美丰满| 久久久综合网站| 久久天天综合| 蜜桃久久精品一区二区| 美日韩精品免费| 欧美二区视频| 欧美久色视频| 欧美性一区二区| 国产欧美精品xxxx另类| 国产一区二区在线观看免费播放| 国产精品婷婷| 国产一区自拍视频| 在线日本成人| 日韩午夜激情av| 亚洲欧美国产精品桃花| 欧美一区二区三区四区在线观看地址| 欧美一激情一区二区三区| 久久久精品国产免大香伊| 欧美v亚洲v综合ⅴ国产v| 亚洲黄色av| 日韩视频一区二区在线观看 | 一区二区三区高清| 亚洲午夜一二三区视频| 午夜亚洲激情| 美女精品在线| 国产精品qvod| 黄色成人av在线| 一本一本久久a久久精品综合麻豆| 国产精品99久久久久久有的能看| 午夜精品99久久免费| 久久亚洲精品伦理| 亚洲韩国青草视频| 亚洲欧美成人综合| 美女国内精品自产拍在线播放| 欧美日韩亚洲精品内裤| 国产日韩在线播放| 日韩系列在线| 午夜精品亚洲| 亚洲国产裸拍裸体视频在线观看乱了中文| 一本色道久久综合狠狠躁篇怎么玩| 午夜精彩视频在线观看不卡| 免费观看亚洲视频大全| 国产精品看片资源| 亚洲国产精品v| 欧美一区1区三区3区公司| 欧美激情91| 欧美一区二区三区男人的天堂| 欧美黄免费看| 黄色在线成人| 羞羞视频在线观看欧美| 亚洲狠狠丁香婷婷综合久久久| 午夜久久久久久久久久一区二区| 欧美电影在线免费观看网站| 国产一区二区无遮挡| 亚洲欧美日韩精品久久亚洲区| 亚洲第一区中文99精品| 欧美一区二区三区在线| 欧美性大战xxxxx久久久| 亚洲人成在线观看| 久久看片网站| 亚洲永久免费视频| 欧美深夜福利| 一区二区免费在线视频| 亚洲电影自拍|