Trying to get draw a triangle

closed account (E3h7X9L8)
I'm trying to draw a triangle using SDL library
Basically I have the function to draw a line between two points x,y and x1,y2 , the problem is how do I find all coordinates of the triangle knowing all sides lengths . I managed to get the formulas for finding the angles of the triangle but I don't know what to do . Here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#undef main
#include <iostream>
using std::cin;
using std::endl;
using std::cout;

#include <cmath>
#include <SDL.h>

const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;

void drawTriangle(int a, int b, int c, SDL_Renderer *renderer);

int main(int argc, char *args[])
{
	SDL_Window *gWindow = NULL;
	SDL_Renderer *gRenderer = NULL;

	int a, b, c;

	cin >> a >> b >> c;

	if (SDL_Init(SDL_INIT_EVERYTHING) >= 0)
	{
		gWindow = SDL_CreateWindow("tesT", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
		if (gWindow != NULL)
		{
			gRenderer = SDL_CreateRenderer(gWindow, -1, SDL_RENDERER_ACCELERATED);
			if (gRenderer != NULL)
			{
				bool bRunning = true;
				SDL_Event e;
				while (bRunning)
				{
					SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 255);
					SDL_RenderClear(gRenderer);

					while (SDL_PollEvent(&e) != 0)
					if (e.type == SDL_QUIT)
						bRunning = false;

					SDL_SetRenderDrawColor(gRenderer, 122, 134, 212, 255);
					drawTriangle(a, b, c, gRenderer);
					SDL_RenderPresent(gRenderer);
				}
				SDL_DestroyWindow(gWindow);
				SDL_DestroyRenderer(gRenderer);

				gWindow = NULL;
				gRenderer = NULL;

				SDL_Quit();
			}
		}
	}


	return 0;
}

void drawTriangle(int a, int b, int c, SDL_Renderer *renderer)
{
	double angA = 1 / cos((a*a - b*b - c*c) / 2 * b * c);
	double angB = 1 / cos((b*b - a*a - c*c) / 2 * a * c);
	double angC = 1 / cos((c*c - a*a - b*b) / 2 * a * b);

	// ?
}
Having the lengths of the sides does not define a unique triangle on a plane, since you are told nothing about its position. If you don't care about orientation, you can:
- pick some arbitrary point (say, the origin)
- draw one of the sides in an arbitrary direction (say, along the x-axis)
- draw another side offset by the appropriate angle (e.g., if you drew side a and are planning to draw b, the appropriate angle between them is angle C)
- connect the free end points; this should be the final side
Topic archived. No new replies allowed.