Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > General > Chit Chat
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Chit Chat The place for open discussions.


Point Inside A triangle


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-21-2009, 05:12 PM
ceaser's Avatar
Basic4ppc Veteran
 
Join Date: May 2008
Location: Paarl, South Africa
Posts: 278
Default Point Inside A triangle

Iwonder if somebody can help me please

I have a triangle defined by three vertices(X, Y, Z). Inside this triangle I have another point (X, Y). Now, I need a formula to calculate the height (Z) of the point inside the triangle using the coordinates (X,Y,Z) of the vertices.

I have been using least squares adjustment, but have found that the bigger the triangle is, the less accurate the Z coordinate becomes.

Anybody?

Thanks
Michael
Reply With Quote
  #2 (permalink)  
Old 08-22-2009, 01:51 PM
Ariel_Z's Avatar
Basic4ppc Veteran
 
Join Date: May 2009
Posts: 246
Default

I'm afraid I could not understand your request. The third point is marked (X,Y) with regard to the vertices (X,Y) or is independent? And what do you mean exactly by "Height" of that point?
Reply With Quote
  #3 (permalink)  
Old 08-22-2009, 02:25 PM
ceaser's Avatar
Basic4ppc Veteran
 
Join Date: May 2008
Location: Paarl, South Africa
Posts: 278
Default

Hi Ariel

I have a lot of points (topographical survey points) and these points are defined by X, Y and Z coordinates. These points then get triangulated with the help of Agraham's Delauney dll

Now, when I tap with my stylus inside any triangle, the program will return the X and Y position where I tapped on the screen. The program then uses these X and Y values to find out in which triangle I have tapped.

Now comes the difficult part. Using the X, Y and Z coordinates of the triangle in which I have tapped, the program needs to calculate a "Z" (height) value of the point where I have tapped, using the values of the 3 corners of the triangle.

Like I have said previously, it works with least squares adjustment, but only to a certain point.

Hope you can help

Thanks
Michael
Reply With Quote
  #4 (permalink)  
Old 08-22-2009, 03:44 PM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Switzerland
Posts: 1,797
Awards Showcase
Forum Contributer Beta Tester Competition Winner 
Total Awards: 3
Default

Hi Michael,
Here you are.
Attached a test program.
The program doesn't check if the point is inside the triangle.

Best regards.
Attached Images
File Type: jpg Triangle_Z.jpg (10.2 KB, 10 views)
Attached Files
File Type: sbp Triangle.sbp (2.8 KB, 14 views)
__________________
Klaus
Switzerland
Reply With Quote
  #5 (permalink)  
Old 08-22-2009, 05:58 PM
ceaser's Avatar
Basic4ppc Veteran
 
Join Date: May 2008
Location: Paarl, South Africa
Posts: 278
Default

Hi Klaus

Thank you very much I don't know what I would have done without the help in this forum.

Something that has struck me with your routine is that one could "extrapolate" heights outside your Tin Model. Where this would be helpful is say controlling the earthworks operation on a golfcourse. What I do is to take the coordinates from the Landscaper (Golfcourse Designer!) as he\she has designed it, convert it to a Tin Model and download it to my controller (Workabout_pro)

Then in the field I hold the Prism Pole (Robotic Total Station) or the Rover Pole (GPS) anywhere on the site and the program will tell me how much up or down the groundlevel must go, to tie in with that of the designer. The design height gets calculated from the respective vertexes from the triangle in which the Pole is held.

What I will do is to change the program that it will also give me a height outside the Tin Model, but warn me (or the user) once the Prism Pole is outside the Tin Model limits.

On another note. I am busy changing the storage format of the CAD program and will post it as soon as it is finished.

Thanks
Michael
Reply With Quote
  #6 (permalink)  
Old 08-23-2009, 07:06 AM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Switzerland
Posts: 1,797
Awards Showcase
Forum Contributer Beta Tester Competition Winner 
Total Awards: 3
Post

Hi Michael,

The fact that the user can extrapolate outsides the triangle has 2 reasons.
- mathematically the 3 vertices of the triangle define a plane, this one is defied inside and outside the triangle.
- in the demo program there is only ONE triangle, the coordinates of the 3 vertices are known when strating the program that means that the plane is already defined. So you can click elsewhere you get an answer.
In your program you must first search in what triangle the point is located and then define the plane.

I didn't include a test if the point is inside the triangle because as you wrote in a previous post:
- that you click on a point
- the program searches the triangle where the point is in
- the program should calculate the altitude of that point.
In this case the point is by definition in a known triangle.
If the point is out of the tin model, the triangle search routine will return no triangle so you already have the warning information.

You could also change the Calc_Z routine as follows.
Instead of transmitting the vertex coordinates
Code:
Sub Calc_Z(x1,y1,z1,x2,y2,z2,x3,y3,z3,x,y)
you could transmit the triangle index and extract the vertex coordinates in the routine.
Code:
Sub Calc_Z(ti,x,y)
 Dim x1,x2,x3,y1,y2,y3,z1,z2,z3

 
 x1=Point(Triangle(ti).V1).X
 y1=Point(Triangle(ti).V1).Y
 z1=Point(Triangle(ti).V1).Z
 
 x2=Point(Triangle(ti).V2).X
 y2=Point(Triangle(ti).V2).Y
 z2=Point(Triangle(ti).V2).Z
' etc

Best regards.
__________________
Klaus
Switzerland
Reply With Quote
  #7 (permalink)  
Old 09-12-2009, 04:30 AM
Newbie
 
Join Date: Aug 2007
Posts: 8
Default

As mentioned, the three points define a plane, so you can also find the equation of the plane in 3d and use that to find the Z of any X, Y point. A good way to find a plane equation is discussed at the following site:

Equation of a plane


I am working on a similar program and would be interested in knowing if you have an optimized routine to find the triangle holding the point. Do you just brute force search and test each triangle, or do you have a better way?
Reply With Quote
  #8 (permalink)  
Old 09-12-2009, 05:19 AM
ceaser's Avatar
Basic4ppc Veteran
 
Join Date: May 2008
Location: Paarl, South Africa
Posts: 278
Default

Hi DeeCee

I use what you call the "brute force" method Firstly I calculate the area of the triangle using the 3 vertexes and then I calculate the area from the prism point (X & Y) to the respective triangle. If the 2 areas are the same, then the point is inside the triangle, but if the area from the prism point is larger than the triangle, then the point is outside the triangle, then the program tests the next triangle.

You are right, I test each triangle until the program finds the triangle where the point is inside the respective triangle.

I am sure there is a faster way. Maybe we should ask Klaus

Thanks
Michael
Reply With Quote
  #9 (permalink)  
Old 09-12-2009, 06:52 AM
Knows the basics
 
Join Date: Apr 2007
Location: Steinheim, Germany
Posts: 88
Default Point Inside A triangle

Hi,
have a look at this: Point in triangle test
__________________
Thanks for all
wolfgang
___________________
Desktop: Dual Core 3.0 GHz, Win7
Device: IPAQ 3970 WM 2003, Asus 632N WM5, HTC 3650 Cruise
GPS: iblue 747
Reply With Quote
  #10 (permalink)  
Old 09-12-2009, 12:58 PM
Newbie
 
Join Date: Aug 2007
Posts: 8
Default

Thanks Michael,

That is what I do also, just test each triangle. Of course, if you have 10,000 triangles and your point is in the last one tested, that takes a while. I would think a way to do it faster would be to sort the triangle array by X or Y, then do some type of binary search, but I'm not really sure how to do that.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
dllToDate stating point Cableguy Open Source Projects 90 03-01-2009 06:46 PM
Array inside Struct fjsantos Questions & Help Needed 2 06-17-2008 04:28 PM
Fixed Point Math im4retro Questions & Help Needed 3 05-31-2008 06:13 AM
3 Point Arc ceaser Questions & Help Needed 38 05-27-2008 03:23 PM
Ticks as a floating point value on XP (not 2000) lancaster Questions & Help Needed 4 04-09-2008 10:38 AM


All times are GMT. The time now is 11:45 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0