View Single Post
  #6 (permalink)  
Old 08-23-2009, 08:06 AM
klaus's Avatar
klaus klaus is offline
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Fully, Switzerland
Posts: 3,807
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:
<font face="Courier New"><font size="2"><font color="#0000ff"><font face="Courier New"><font size="2"><font color="#0000ff"><font face="Courier New"><font size="2"><font color="#0000ff">Sub </font></font></font></font></font></font></font></font></font><font face="Courier New"><font size="2"><font face="Courier New"><font size="2">Calc_Z(x1,y1,z1,x2,y2,z2,x3,y3,z3,x,y)</font></font></font></font>
you could transmit the triangle index and extract the vertex coordinates in the routine.
Code:
<font face="Courier New"><font size="2"><font color="#0000ff"><font face="Courier New"><font size="2"><font color="#0000ff"><font face="Courier New"><font size="2"><font color="#0000ff"><font face="Courier New"><font size="2"><font color="#0000ff"><font face="Courier New"><font size="2"><font color="#0000ff"><font face="Courier New"><font size="2"><font color="#0000ff"><font face="Courier New"><font size="2"><font color="#0000ff"><font face="Courier New"><font size="2"><font color="#0000ff"><font face="Courier New"><font size="2"><font color="#0000ff">Sub </font></font></font></font></font></font></font></font></font><font face="Courier New"><font size="2"><font face="Courier New"><font size="2"><font color="#000000">Calc_Z(ti,x,y)</font></font></font>
</font></font><font face=
"Courier New"><font size="2"><font color="#0000ff"><font face="Courier New"><font size="2"><font color="#0000ff"><font face="Courier New"><font size="2"><font color="#0000ff"Dim</font></font></font></font></font></font></font></font></font><font face="Courier New"><font size="2"><font face="Courier New"><font size="2"> x1,x2,x3,y1,y2,y3,z1,z2,z3</font></font></font></font>
<font face=
"Courier New"><font size="2">
 
<font size=
"2"><font face="Courier New"> x1=Point(Triangle(ti).V1).X</font></font>
<font size=
"2"><font face="Courier New"> y1=Point(Triangle(ti).V1).Y</font></font>
<font size=
"2"><font face="Courier New"> z1=Point(Triangle(ti).V1).Z</font></font>
 
<font size=
"2"><font face="Courier New"> x2=Point(Triangle(ti).V2).X</font></font>
<font size=
"2"><font face="Courier New"> y2=Point(Triangle(ti).V2).Y</font></font>
<font size=
"2"><font face="Courier New"> z2=Point(Triangle(ti).V2).Z</font></font>
</font></font><font face=
"Courier New"><font size="2"><font color="#008000"><font face="Courier New"><font size="2"><font color="#008000"><font face="Courier New"><font size="2"><font color="#008000">' etc</font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font>

Best regards.
__________________
Klaus
Switzerland
Reply With Quote