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

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 閱讀(2053) 評論(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>
            国产精品xxxxx| 久久免费视频网站| 亚洲人体偷拍| 欧美成人免费全部观看天天性色| 午夜日本精品| 亚洲欧美卡通另类91av| 999亚洲国产精| 一本不卡影院| a4yy欧美一区二区三区| 亚洲日本va在线观看| 久久精品国产99国产精品| 性欧美暴力猛交另类hd| 亚洲免费一在线| 亚久久调教视频| 久久精品国产第一区二区三区| 亚洲午夜一区二区| 午夜精品久久久久影视 | 日韩视频永久免费观看| 欧美激情一区二区三区成人| 亚洲成色精品| 亚洲精品视频在线播放| 亚洲成色www8888| 亚洲丁香婷深爱综合| 欧美激情第3页| 亚洲一区二区三区午夜| 噜噜爱69成人精品| 欧美色欧美亚洲另类七区| 国产精品欧美日韩一区| 黄色精品一区二区| 一本色道久久99精品综合| 欧美在线国产精品| 91久久国产综合久久91精品网站| 亚洲视频一区在线观看| 久久国产精品高清| 欧美日韩美女| 亚洲欧洲精品一区二区| 欧美一区国产二区| 久久精品国产亚洲一区二区| 亚洲国产精彩中文乱码av在线播放| 亚洲国产小视频在线观看| 亚洲影视中文字幕| 蜜桃av一区二区| 国语自产精品视频在线看抢先版结局 | 久久爱www.| 欧美在线一级va免费观看| 欧美高清在线视频观看不卡| 亚洲一区二区视频| 欧美成人在线网站| 尤物yw午夜国产精品视频明星| 亚洲综合视频1区| 噜噜噜91成人网| 亚洲尤物在线| 欧美日韩中文字幕| 99在线热播精品免费| 亚洲女女女同性video| 久久久久欧美精品| 在线视频欧美一区| 欧美精品日韩| 亚洲国产精品精华液2区45| 亚洲影视在线| 亚洲精品一二三| 欧美日韩人人澡狠狠躁视频| 在线观看日韩av先锋影音电影院| 一区二区国产日产| 亚洲精品久久久蜜桃| 美女图片一区二区| 韩日精品视频一区| 久久精品国产一区二区三区免费看| 一区二区三区四区五区精品| 欧美日韩国产在线看| 日韩一区二区精品在线观看| 亚洲国产日韩一区二区| 免费观看日韩| 99热免费精品在线观看| 国产精品亚洲一区| 国产精品免费网站| 亚洲欧美日韩国产成人| 亚洲午夜视频在线| 国产精品自在线| 久久久www免费人成黑人精品 | 国产午夜精品久久久久久久| 欧美一区二区三区四区视频| 亚洲一级片在线观看| 国产精品视频网站| 巨胸喷奶水www久久久免费动漫| 性欧美办公室18xxxxhd| 亚洲成人在线视频播放| 亚洲精品一区二| 国产精品美女| 久久精品国产99精品国产亚洲性色| 性视频1819p久久| 亚洲乱码国产乱码精品精 | 免费在线观看一区二区| 亚洲免费av网站| 免费av成人在线| 国产精品亚洲欧美| 亚洲欧洲日本国产| 久久激情综合网| 日韩视频在线观看国产| 欧美日本视频在线| 欧美国产综合一区二区| 亚洲精品综合在线| 亚洲日本中文字幕区| 亚洲黄色尤物视频| 狠狠做深爱婷婷久久综合一区| 欧美视频在线观看视频极品| 欧美日韩亚洲一区二区三区在线| 久久精品二区亚洲w码| 欧美成人第一页| 国产精品色网| 国产欧美激情| 国产精品日韩一区二区三区| 99精品福利视频| av成人免费| 在线亚洲精品福利网址导航| 国产一区二区激情| 亚洲激情成人在线| 午夜精品久久一牛影视| 亚洲精品女人| 亚洲在线免费观看| 亚洲精品久久久久久久久久久久久| 国产精品久久久久一区二区| 老司机精品视频一区二区三区| 日韩亚洲精品在线| 美女图片一区二区| 亚洲午夜久久久久久久久电影院| 欧美freesex交免费视频| 国产精品久久久久久久午夜| 亚洲春色另类小说| 国产日韩精品一区| 亚洲欧美日韩区| 欧美成人精品在线视频| 亚洲国产毛片完整版| 亚洲国产欧美国产综合一区| 久久精品国产清自在天天线 | 亚洲午夜激情网页| 欧美日韩亚洲一区二区| 日韩五码在线| 日韩视频免费观看| 一区二区三欧美| 欧美日韩专区| 亚洲你懂的在线视频| 午夜视频一区在线观看| 一区精品在线播放| 久久夜色精品国产欧美乱极品 | 国产主播精品在线| 国产伦理一区| 亚洲老板91色精品久久| 国产精自产拍久久久久久蜜| 欧美在线www| 欧美小视频在线| 国模吧视频一区| 亚洲在线成人精品| 欧美成人一区二区三区在线观看 | 久久激情久久| 亚洲视频中文字幕| 欧美午夜免费| 91久久精品日日躁夜夜躁国产| 狠狠操狠狠色综合网| 久久亚洲一区二区| 欧美激情偷拍| 日韩视频不卡| 国产精品久久久久久久久免费| 亚洲精品专区| 最新热久久免费视频| 欧美波霸影院| 亚洲人久久久| 亚洲免费婷婷| 国产亚洲精品久久久| 久久久不卡网国产精品一区| 欧美本精品男人aⅴ天堂| 亚洲九九爱视频| 国产精品手机视频| 久久亚洲二区| 一级日韩一区在线观看| 欧美一区二区成人6969| 久久激情中文| 亚洲人午夜精品免费| 欧美中文字幕久久| 亚洲精品黄色| 国产欧美日韩在线视频| 亚洲高清123| 亚洲欧美日韩精品久久久久| 国产一区二区三区四区hd| 欧美国产视频日韩| 欧美专区在线播放| 99精品国产在热久久婷婷| 久久久久久久欧美精品| 一本色道婷婷久久欧美| 国产一区二区三区四区老人| 欧美精品乱人伦久久久久久| 欧美在线短视频| 这里只有精品视频| 亚洲国产精品电影在线观看| 久久精品日韩欧美| 中文日韩电影网站| 国产精品国产三级国产aⅴ无密码| 亚洲人在线视频| 国产精品第一页第二页第三页| 羞羞视频在线观看欧美|