# [SOLVED]Constructing triangles from a single line

This topic is 3837 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all. I've made a minimap of some 3D game map that shows where the camera is located(point) and the direction in which it is looking(line). But I've changed my mind about this. Now I want to use a triangle to represent the frustum. Point A is the focus position. I need to find points B and C. The field of view is 90. Can someone explain/demonstrate the trig involved in solving this problem? BTW, I want to avoid using matrices until someone can show me something that uses fewer calculations. [Edited by - hollis on July 23, 2008 6:46:39 AM]

##### Share on other sites
1) Let "right" be 0º, "up" be 90º, "left" be 180º and "down" be 270º
2) Convert the vector A into an angle
3) Convert A's angle+90º to the vector B
4) Convert A's angle-90º to the vector C

I remember trig with the mnemonic SohCahToa.
Sin(angle) = opposite/hypotenuse.

In the case of your vector 'A' the hypotenuse is the black line in your pic, the opposite side is a vertical line from the end-point of A down to the x-axis, and the adjacent side is a horizontal line from the end-point of A across to the y-axis.

To find A's angle, SohCahToa tells me that the Tangent of the angle is equal to the opposite side (A.y) divided by the adjacent side (A.x). Then the real angle is the arc-tangent of the tangent.
Use the atan2 function to do these steps for you.

To convert an angle back into a vector, SohCahToa tells me that the opposite edge is equal to the sine of the angle divided by the hypotenuse. The adjacent adge is equal to the cosine of the angle divided by the hypotenuse.
To begin with, just use a hypotenuse value of 1 to create a vector with a length of 1 (i.e. a "unit vector"). Then scale the resulting unit vector by the desired length.

I think this is right, but it's off the top of my head:
struct Vector2D {  float x, y;}Vector2D A, B, C;A = ...;float angle_A = atan2( A.y, A.x );float angle_B = angle_A + M_PI;float angle_C = angle_A - M_PI;B.x = cos(angle_B);B.y = sin(angle_B);B *= A.length();C.x = cos(angle_C);C.y = sin(angle_C);C *= A.length();

##### Share on other sites
The vector (B-A) is perpendicular to A=(ax, ay), so it’s parallel to (-ay, ax). The length of (B-A) is length(A) (the triangle ABO is isosceles in fact the angle in B is 180°-90°-45°=45°) so it’s exactly (-ay,ax) (length((-ay,ax))=sqrt((-ay)2 + ax2)=sqrt(ax2 + ay2)=length(A)). So B = (ax - ay, ay + ax) and C = (ax + ay, ay - ax).

EDIT: You can further reduce the number of operations because B is perpendicular to C and they have the same length, so (bx,by) = (-cy,cx) or (cx,cy) = (by,-bx). Using one of these relations you can easily obtain one vertex from the other.

##### Share on other sites
Wow! That made perfect sense! I'll admit that I hadn't analyzed the problem thoroughly. Now I feel Like knucklehead. Thanks for the feedback guys

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 11
• 11
• 15
• 11
• 11
• ### Forum Statistics

• Total Topics
634149
• Total Posts
3015834
×