Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 14:22
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
1 registered members (AndrewAMD), 599 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
[SOLVED] Triangle height math problem? #386420
11/02/11 16:54
11/02/11 16:54
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
I have a problem with some triangle math, I was recommended a couple of functions to use to solve it (vec_lerp for its height and vec_dot for its angle).

Diagram of the problem:

I have been reading both functions and am trying to come up with a clever way to implement it but I have to admit I have absolutely no idea what to do...

Here is my problem:

lets say this is a 16x16 square formed by these 4 vectors:
A=(0,15,6)
B=(15,0,7)
C=(15,15,0)
D=(0,0,-1)
the coords are (x,y,height)
How would I calculate the height of H1 and H2 if I only have their xy coordinates to work with?
H1=(3,11,?)
H2=(13,3,?)


I assume the first step would be to calculate which triangle H1 or H2 are on?
How could I calculate if H1 is inside triangle ACD or BCD?
How could I calculate if H2 is inside triangle ACD or BCD?



"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: Triangle height math problem? [Re: Carlos3DGS] #386421
11/02/11 17:10
11/02/11 17:10
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
There may be an easier way but that is what I can think of right now:

Quote:
How could I calculate if H1 is inside triangle ACD

if(H1 is inside the square ACBD)
{
// calculate direction vector C->D
vec_diff(temp,C.x,D.x);
// calculate normal that points outside (in direction of B)
normal.x = temp.y;
normal.y = -temp.x;
normal.z = 0;
vec_normalize(normal,1);
// the normal may be pointing towards A, depending on where C and D are
if(vec_dot(A.x,normal) - vec_dot(C.x,normal) > 0) vec_inverse(normal); // or < 0, I'm not sure right now
// now check if H1 is on the same side of the direction vector temp
if(vec_dot(H1.x,normal) - vec_dot(C.x,normal) < 0) return 1;
}
return 0;


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Triangle height math problem? [Re: Superku] #386423
11/02/11 17:33
11/02/11 17:33
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
While you were answering I think I got a solution for knowing what triangle it is in another way:
Code:
vec_set (temp_vec, vector(H1.x,H1.y,0));
vec_sub (temp_vec,vector(D.x,D.y,0));
vec_to_angle (temp_ang.pan,temp_vec);

if(temp_ang.pan>45)
{
   //Resolve H1.z for triangle ACD
}
else
{
   //Resolve H1.z for triangle BCD
}


Would that also work?

Now I just need to know what to do to figure out H1.z (the height) calculated on triangle ACD's surface...
Any ideas?

EDIT:
I got it working. For anyone that needs something similar, I posted the solution in this thread:
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=386444#Post386444

Last edited by Carlos3DGS; 11/03/11 03:53.

"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1