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

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>
            国产自产v一区二区三区c| 中文有码久久| 欧美不卡一卡二卡免费版| 欧美一区综合| 久久一区二区三区四区五区| 卡一卡二国产精品| 欧美高清在线精品一区| 欧美久久久久| 国产日产精品一区二区三区四区的观看方式 | 久久日韩精品| 欧美成人有码| 欧美日韩在线精品| 国产九区一区在线| 影音先锋亚洲电影| 一区二区三区视频在线播放| 久久福利电影| 最近中文字幕mv在线一区二区三区四区| 久久夜色精品国产欧美乱| 国产精品毛片a∨一区二区三区|国 | 亚洲国产成人av| a4yy欧美一区二区三区| 午夜精品福利视频| 欧美 日韩 国产 一区| 国产精品扒开腿做爽爽爽软件 | 欧美激情精品久久久久久蜜臀| 国产精品成人aaaaa网站 | 狠久久av成人天堂| 一区二区电影免费在线观看| 久久国产精品久久久久久| 亚洲大片av| 欧美综合77777色婷婷| 欧美精品一区在线发布| 狠狠色丁香婷综合久久| 亚洲综合电影| 最新日韩中文字幕| 欧美中文字幕第一页| 欧美日韩精品二区| 亚洲第一区在线观看| 欧美在线啊v| 宅男噜噜噜66国产日韩在线观看| 美女网站久久| 国产一区av在线| 性色一区二区三区| 亚洲视频高清| 国产精品高潮呻吟久久av无限| 亚洲黄色影院| 欧美成人免费观看| 欧美专区福利在线| 国产午夜一区二区三区| 亚洲影院色在线观看免费| 亚洲精品乱码久久久久久久久 | 一区二区三区你懂的| 欧美成人激情在线| 久久久久久一区| 在线成人激情黄色| 久久夜色精品亚洲噜噜国产mv| 午夜精品久久久久久久男人的天堂| 欧美视频在线观看一区| 一区二区三区高清不卡| 亚洲裸体俱乐部裸体舞表演av| 麻豆精品视频在线观看| 亚洲激情小视频| 欧美激情一区二区三区| 欧美不卡激情三级在线观看| 亚洲精品日韩综合观看成人91| 欧美激情四色| 亚洲欧洲日韩综合二区| 蜜臀av在线播放一区二区三区| 在线观看视频一区| 免费观看日韩av| 美女尤物久久精品| 99re成人精品视频| 中文一区二区| 国产亚洲aⅴaaaaaa毛片| 久久精品三级| 久久尤物视频| 一区二区三区国产在线观看| 亚洲一区二区三区四区五区午夜| 国产日韩在线看| 欧美高潮视频| 欧美精品国产精品| 亚洲欧美日韩国产成人精品影院| 亚洲欧美日韩视频一区| 黄色成人小视频| 亚洲七七久久综合桃花剧情介绍| 欧美日韩另类国产亚洲欧美一级| 亚洲欧美高清| 亚洲女人天堂av| 激情成人av在线| 亚洲激情婷婷| 国产精品一区二区在线| 欧美r片在线| 欧美三级午夜理伦三级中视频| 欧美在线视频一区二区| 欧美777四色影视在线| 亚洲免费综合| 久久综合成人精品亚洲另类欧美| 在线视频欧美日韩| 久久久不卡网国产精品一区| 在线中文字幕不卡| 久久免费视频网站| 亚洲一区在线直播| 久久亚洲精品一区| 久久av一区二区| 欧美69wwwcom| 老妇喷水一区二区三区| 欧美日韩国产在线一区| 久热爱精品视频线路一| 欧美三级网页| 亚洲黑丝在线| 在线观看亚洲精品| 性做久久久久久久久| 在线视频欧美日韩| 欧美电影在线| 欧美暴力喷水在线| 欧美体内she精视频| 亚洲国产成人久久综合| 国内精品一区二区三区| 亚洲网站视频| 一卡二卡3卡四卡高清精品视频| 久久久午夜精品| 久久久久九九视频| 国产麻豆午夜三级精品| 这里只有精品丝袜| 99在线精品观看| 欧美刺激性大交免费视频 | 亚洲乱码国产乱码精品精| 国语自产精品视频在线看8查询8 | 亚洲国产高清视频| 久久精品国产免费看久久精品| 亚洲男人第一av网站| 欧美日韩精品免费观看视频完整 | 欧美日韩免费网站| 亚洲人午夜精品| 91久久精品美女| 欧美r片在线| 亚洲激情视频网| 在线视频欧美日韩| 国产精品国产精品| 中文亚洲免费| 亚洲一区网站| 欧美特黄一级大片| 亚洲制服丝袜在线| 欧美一区二区在线观看| 国产欧美日本| 欧美在线3区| 蜜臀久久久99精品久久久久久| 激情欧美国产欧美| 欧美jizzhd精品欧美巨大免费| 亚洲国产一二三| 一本大道av伊人久久综合| 欧美大片一区二区| 亚洲精品国产无天堂网2021| 中文久久乱码一区二区| 国产精品免费网站在线观看| 欧美一级久久久| 美女脱光内衣内裤视频久久影院| 一区在线视频| 欧美精品日韩三级| 亚洲午夜免费视频| 久久久久久久一区二区| 亚洲国产精品久久久久秋霞蜜臀 | 午夜在线视频观看日韩17c| 国产精品日韩二区| 欧美在线欧美在线| 亚洲激情视频在线观看| 欧美一级片一区| 在线欧美影院| 欧美日韩在线视频一区| 欧美在线播放视频| 亚洲国产日韩欧美综合久久| 亚洲影院高清在线| 亚洲第一精品影视| 国产精品日日摸夜夜添夜夜av| 久久久久久网| 亚洲在线观看视频网站| 亚洲第一在线视频| 亚洲欧美在线x视频| 亚洲国产成人av| 国产精品午夜在线观看| 免费日韩精品中文字幕视频在线| 亚洲一级在线观看| 亚洲国产另类久久精品| 欧美中文在线免费| 日韩午夜精品视频| 国产真实乱偷精品视频免| 欧美日韩午夜在线视频| 久久激情婷婷| 亚洲香蕉视频| 亚洲精品婷婷| 欧美激情四色| 欧美成人激情在线| 久久精品水蜜桃av综合天堂| 亚洲视频在线免费观看| 在线日韩欧美| 国产视频综合在线| 99re视频这里只有精品| 美女主播一区| 久久精品理论片| 午夜久久资源|