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

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

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

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            一区二区欧美精品| 亚洲精品视频免费观看| 性欧美超级视频| 亚洲一区视频在线观看视频| 欧美午夜免费电影| 欧美一区二区三区四区夜夜大片| 午夜精品99久久免费| 国产综合久久| 欧美岛国激情| 欧美日韩成人综合在线一区二区| 亚洲精品你懂的| 9l视频自拍蝌蚪9l视频成人| 国产精品国产三级国产aⅴ入口| 欧美一区二区三区在线播放| 久久久久久有精品国产| 亚洲美女在线视频| 亚洲一区二区精品在线观看| 黄色一区二区三区四区| 欧美激情一级片一区二区| 欧美日韩亚洲一区三区| 久久久久久午夜| 欧美日韩亚洲一区二区三区| 久久久综合香蕉尹人综合网| 欧美激情久久久| 欧美有码在线观看视频| 欧美岛国在线观看| 久久久www| 欧美日韩高清一区| 免费在线看一区| 国产精品久久久久久福利一牛影视| 久久野战av| 欧美午夜视频在线观看| 欧美福利视频在线| 国产亚洲欧美在线| 宅男精品视频| 日韩手机在线导航| 久热精品视频在线| 久久精品九九| 国产精品日韩高清| 亚洲美女在线看| 亚洲国产精品第一区二区| 亚洲欧美第一页| 亚洲天堂男人| 欧美日韩播放| 亚洲国产成人不卡| 国产精品午夜在线| 中文网丁香综合网| 一区二区av在线| 模特精品在线| 欧美黄色大片网站| 亚洲高清不卡在线| 久久精品视频导航| 久久久水蜜桃| 国产在线不卡视频| 欧美在线观看视频在线 | 国产一区二区三区无遮挡| 一区二区三区日韩在线观看| 日韩网站在线| 欧美激情第五页| 亚洲精品1区2区| 日韩视频一区| 欧美日韩国产色站一区二区三区| 亚洲国产高清aⅴ视频| 樱桃国产成人精品视频| 久久精品国产清高在天天线| 久久久久中文| 激情欧美一区二区三区在线观看| 久久国产主播| 欧美+日本+国产+在线a∨观看| 在线观看av一区| 老巨人导航500精品| 亚洲成人资源| 一区二区三区精品| 欧美婷婷久久| 亚洲一区视频在线| 裸体丰满少妇做受久久99精品| 经典三级久久| 欧美国产精品久久| 一区二区三区日韩精品| 欧美一级网站| 影音先锋日韩有码| 欧美日本国产一区| 亚洲专区一二三| 玖玖在线精品| 日韩午夜在线电影| 国产精品自在在线| 久久深夜福利免费观看| 亚洲伦理中文字幕| 久久精品国产亚洲一区二区| 在线观看国产日韩| 欧美日韩一区精品| 久久av红桃一区二区小说| 欧美aaa级| 亚洲综合欧美| 亚洲高清免费| 国产精品久久久久久久浪潮网站 | 国产精品日韩欧美一区二区三区| 欧美国产精品中文字幕| 极品少妇一区二区| 欧美精品一区二区三区在线播放| 夜色激情一区二区| 美女成人午夜| 亚洲一区二区三区四区视频| 国产一区二区三区在线观看免费| 欧美18av| 欧美在线黄色| 一区二区日韩| 亚洲国产高清自拍| 久久精品二区亚洲w码| 亚洲精选一区| 影音先锋久久| 国产美女精品视频免费观看| 欧美国产精品久久| 久久免费国产精品| 亚洲永久免费观看| 亚洲精品久久久久久久久久久久| 久久av在线| 亚洲尤物视频网| 亚洲精品日韩在线观看| 精品动漫一区| 国产精品色网| 国产精品xnxxcom| 欧美激情女人20p| 久久一日本道色综合久久| 亚洲欧美中文在线视频| 一区二区三区回区在观看免费视频| 欧美高清一区| 欧美 日韩 国产 一区| 久久久视频精品| 久久本道综合色狠狠五月| 亚洲一区影院| 亚洲色图自拍| 中日韩美女免费视频网址在线观看 | 久久久久久午夜| 欧美在线播放一区| 亚洲综合三区| 亚洲欧美激情在线视频| 亚洲一区二区免费| 亚洲欧美另类在线| 午夜影院日韩| 欧美一区二视频| 欧美在线日韩精品| 久久精品九九| 久久色在线观看| 欧美暴力喷水在线| 欧美精品v日韩精品v国产精品| 免费人成网站在线观看欧美高清| 鲁大师成人一区二区三区| 久久夜精品va视频免费观看| 美女国内精品自产拍在线播放| 久久久亚洲高清| 麻豆精品一区二区综合av| 裸体女人亚洲精品一区| 欧美高清视频www夜色资源网| 欧美成人精精品一区二区频| 欧美极品影院| 国产精品久久久一区麻豆最新章节| 国产精品理论片| 国精品一区二区| 91久久久久久久久久久久久| 亚洲伦理久久| 亚洲欧美日韩在线一区| 久久精品国亚洲| 欧美国产日韩亚洲一区| 亚洲伦理在线免费看| 亚洲欧美国产va在线影院| 久久久91精品国产| 欧美精品一区二区三区视频| 国产精品日韩欧美大师| 精品成人乱色一区二区| 日韩一级片网址| 性做久久久久久久久| 蜜桃久久av| 亚洲麻豆视频| 欧美一区二区免费观在线| 蜜臀av在线播放一区二区三区| 欧美日韩亚洲一区二区三区在线观看| 国产精品美女久久久| 在线不卡中文字幕播放| 一区二区三区国产盗摄| 久久久综合网站| 一本大道久久a久久综合婷婷| 久久国产精品99国产精| 欧美日韩国产探花| 一区二区视频免费完整版观看| 一区二区三区精品视频| 麻豆精品在线视频| 亚洲视频在线观看一区| 你懂的视频一区二区| 国产精品尤物福利片在线观看| 亚洲全部视频| 久久九九热免费视频| 在线亚洲精品福利网址导航| 久久夜色精品一区| 国产精品视频男人的天堂| 日韩视频一区二区三区在线播放| 久久九九久精品国产免费直播| 亚洲免费福利视频| 欧美成人综合| 亚洲国产老妈|