Gamestudio Links
Zorro Links
Newest Posts
ZorroGPT
by TipmyPip. 02/26/26 21:35
WFO Training with parallel cores Zorro64
by Martin_HH. 02/26/26 16:03
Zorro version 3.0 prerelease!
by TipmyPip. 02/25/26 16:38
Camera always moves upwards?
by clonman. 02/21/26 09:29
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 02/19/26 13:22
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
1 registered members (TipmyPip), 5,771 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
the1, alx, ApprenticeInMuc, PatrickH90, USER0328
19200 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
get hight of a triangle #325173
05/25/10 08:17
05/25/10 08:17
Joined: Mar 2009
Posts: 5
P
peonytele Offline OP
Newbie
peonytele  Offline OP
Newbie
P

Joined: Mar 2009
Posts: 5
hi 3DGS.
i don`t know if it is a bug or some thing...
when i want to get hight of a triangle,i use the method in the manual:
VECTOR pointA;
VECTOR pointB;
VECTOR pointC;
//these 3 points define a triangle(of course their Z is all the same)
VECTOR vec_A_to_B;
VECTOR vec_A_to_C;
VECTOR vec_B_to_C;
//these 3 vectors means 3 lines of the triangle
var angle_A = acos(vec_dot(vec_A_to_B,vec_A_to_C)/(vec_length(vec_A_to_B)*vec_length(vec_A_to_C)));
var hight_B = vec_length(vec_A_to_B) * sinv(angle_A);
and i found that the value of hight_B is bigger than the right value
then i use Cosine Theorem:
var cos_A=(vec_A_to_B^2 + vec_A_to_C^2 - vec_B_to_C^2)/(2 * vec_A_to_B * vec_A_to_C);
angle_A = acos(A);
hight_B = vec_length(vec_A_to_B) * sinv(angle_A);
i found that the value of hight_B is smaller than the right value
only when i don`t use acos() function:
hight_B = sqrt(vec_A_to_B^2 - (vec_A_to_B * cosA)^2);
this value of hight_B is the right value...and i really don`t know why..
thanks for read this,hope to get your answers!

Re: get hight of a triangle [Re: peonytele] #325200
05/25/10 12:10
05/25/10 12:10
Joined: Jul 2000
Posts: 28,077
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,077
Frankfurt
As far as I see, your formulae are correct. But for large or acute triangle you're possibly outside the precision range of var variables. Better use float for trigonometry.

If a formula does not give the desired result, split it in sub-steps and check in which of the steps the result becomes wrong. You must do this yourself - find the reason and fix it. This does not belong to the bug forum. Blaming the programming language for wrong results of your script won't help.

Re: get hight of a triangle [Re: jcl] #325389
05/26/10 11:58
05/26/10 11:58
Joined: Mar 2009
Posts: 5
P
peonytele Offline OP
Newbie
peonytele  Offline OP
Newbie
P

Joined: Mar 2009
Posts: 5
ok,thank you!
indeed,my triangle is relly big,around 1000 per line...maybe it`s the reason.
after cos() and sinv(),the hight`s value goes wrong i think


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | 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