Java-Gaming.org Hi !
 Featured games (91) games approved by the League of Dukes Games in Showcase (757) Games in Android Showcase (229) games submitted by our members Games in WIP (844) 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 2759 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

JGO Kernel

Medals: 517

 « 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

 EgonOlsen (77 views) 2018-06-10 19:43:48 EgonOlsen (57 views) 2018-06-10 19:43:44 EgonOlsen (77 views) 2018-06-10 19:43:20 DesertCoockie (259 views) 2018-05-13 18:23:11 nelsongames (157 views) 2018-04-24 18:15:36 nelsongames (156 views) 2018-04-24 18:14:32 ivj94 (897 views) 2018-03-24 14:47:39 ivj94 (161 views) 2018-03-24 14:46:31 ivj94 (810 views) 2018-03-24 14:43:53 Solater (174 views) 2018-03-17 05:04:08
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05
 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