Gamestudio Links
Zorro Links
Newest Posts
Lapsa's very own thread
by Lapsa. 06/26/24 12:45
Executing Trades on Next Bar Open
by Zheka. 06/20/24 14:26
A simple game ...
by VoroneTZ. 06/18/24 10:50
Face player all the time ...
by bbn1982. 06/18/24 10:25
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,248 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mino, squik, AemStones, LucasJoshua, Baklazhan
19061 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: 27,987
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,987
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 | 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