Gamestudio Links
Zorro Links
Newest Posts
ZorroGPT
by TipmyPip. 08/26/26 22:38
Retrieve optimize() variables order (edited)
by NorbertSz. 08/25/26 13:24
Max Number of Strategies in /Strategy folder
by Martin_HH. 08/17/26 07:54
Pause button for evaluation shell?
by AndrewAMD. 08/13/26 17:16
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 08/10/26 12:46
phantom() not defined in indicators.c
by jcl. 08/07/26 11:45
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
3 registered members (TipmyPip, OptimusPrime, Quad), 6,509 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
riggi89, shuhari, KD1990, Student_64151, Koti
19230 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,133
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,133
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