Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (595) Games in Android Showcase (168) games submitted by our members Games in WIP (647) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 figureing out the x,y, and z rotation of a right triangle?  (Read 1755 times) 0 Members and 1 Guest are viewing this topic.
CyanPrime
 « Posted 2010-12-06 20:54:34 »

I have a triangle made of 3 vertices. I need to know what the angle of the triangle is.

How would I go about it?
pjt33

« JGO Spiffy Duke »

Medals: 40
Projects: 4
Exp: 7 years

 « Reply #1 - Posted 2010-12-06 21:41:42 »

Cos rule. a^2 = b^2 + c^2 - 2 b c cos A

Edit: although if you're talking about a situation where numerical analysis matters then read http://www.cs.berkeley.edu/~wkahan/Triangle.pdf
SimonH
 « Reply #2 - Posted 2010-12-06 21:44:47 »

or the dot product would do it.

People make games and games make people
CyanPrime
 « Reply #3 - Posted 2010-12-07 03:09:56 »

My bad. It's 2 points, not a triangle

Alright, so I got two vectors that each contain a x y and z. We'll call them a and b.

I create a new point in the middle of the two points.

Vector3 middle = new Vector3(//order x,y,z
(max.getX() - min.getX())/2,
(max.getY() - min.getY())/2,
(max.getZ() - min.getZ())/2
);

To get the y angle I use the formula Math.toDegrees(Math.atan2(middle.getX(), middle.getZ()))
pjt33

« JGO Spiffy Duke »

Medals: 40
Projects: 4
Exp: 7 years

 « Reply #4 - Posted 2010-12-07 09:57:44 »

I create a new point in the middle of the two points.

Vector3 middle = new Vector3(//order x,y,z
(max.getX() - min.getX())/2,
(max.getY() - min.getY())/2,
(max.getZ() - min.getZ())/2
);
That's not in the middle, except in some special cases. It's half the vector from one to the other. The division by 2 is pretty pointless if the only thing you're going to do is call atan2.

I'm still not quite sure what you're trying to do. Compute Euler angles for a look vector?
Roquen
 « Reply #5 - Posted 2010-12-07 11:46:07 »

I'm still not understanding the question.  If it is "What's the angle between 'A' & 'B'", then like SimonH's reply - use the dot product (SEE: Geometric interpretation).
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 deepthought (49 views) 2015-06-30 15:39:44 deepthought (56 views) 2015-06-30 15:39:09 deepthought (65 views) 2015-06-30 15:36:52 Za\'Anzabar (43 views) 2015-06-29 05:44:54 TritonDreyja (49 views) 2015-06-24 17:10:40 CopyableCougar4 (49 views) 2015-06-23 00:34:45 BurntPizza (58 views) 2015-06-21 20:36:46 cookiecompiler (98 views) 2015-06-11 15:42:53 cookiecompiler (58 views) 2015-06-11 15:41:14 NegativeZero (82 views) 2015-06-11 09:49:18
 princec 31x wessles 23x orangepascal 22x CopyableCougar4 19x EgonOlsen 17x opiop65 17x BurntPizza 17x ags1 15x nsigma 15x theagentd 13x Riven 13x KaiHH 12x SauronWatchesYou 11x KevinWorkman 11x sunburn 11x Jesse 11x
 How Do I Expand My Game?by bashfrog2015-06-14 11:34:43List of Learning Resources2015-05-31 05:37:30Intersection Methodsby Roquen2015-05-29 08:19:33List of Learning Resources2015-05-05 10:20:32How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org