# Calculating the normal of a triangle

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

## Recommended Posts

Hi, im having a few problems with my implementation of this (well im sure im doing all the right things, just not quite in the right order) and was wondering if anyone could spot where i was going wrong? Ok, when i initialise my triangles I calculate the surface normal in local space void TRIANGLE_3D::calculate_normal() { m_normal = m_points[0].cross(m_points[1]); m_normal.normalise(); } im not certain if the 2 points of the triangle I cross are really that important or if the ordering makes a difference? I dont think it should though. Ive carefully checked the maths for the normalise and cross calculations to ensure these are correct. then, my various triangles are translates / rotated in world space during the update loop and i decide to draw a line on each triangle representing the direction of the normal (for debug purposes) //get the triangles world matrix MATRIX_4 world = tris[j]->get_world(); get the centre of each triangle in world space in order for the lines starting point to be the middle of the triangle VECTOR_3 start= tris[j]->centre_world(); then it comes to drawing the line.... //translate the local space normal into world space //multiply by 10 to give the end point a small distance VECTOR_3 end = world * tris[j]->normal() *10; draw_line(start,end); how exactly can i translate this end point so it is proportional to the start point?, ive tried many different ways (all obviously wrong), but need to make sure the rest of what i have done is correct first any advice would be greatfully appreceated. thanks

##### Share on other sites
Are you crossing the position of the vertices of the triangle? If you do, its wrong. You should cross two of the edge vectors of the triangle, like (v1-v0)X(v2-v0). I think everything else is ok except if you are translating the vector in the world*normal.

##### Share on other sites
Ah yes that does appear to be a problem, i was crossing 2 of the points. ok now im crossing 2 of the edges(which also uncovered a nasty divide by zero issue). now I just need to determine the end point of the line as currently it is rendering the lines inside of the shapes, which is obviously wrong

any idea how I should approach calculating an end point for a line as an offset of say 10 magnitude from the start in the direction of the normal?

cheers

##### Share on other sites
Its going inside but it is perpendicular(normal) to the triangle plane? The order in which you cross the vectors determine the direction of the result. I mean uXv = -vXu. Thats why triangle vertices must be ordered clock-wisely or counter clock-wisely because if you establish a standard vertex ordering the normals will always point to the correct direction.

The direction of the normal in the cross is determined by the right-hand rule.

If its is not perpendicular ti the triangle plane there's something else wrong there..

##### Share on other sites
ah ok yes that makes a lot of sense, makes me wish i hadnt hard coded all my verts now, and actually bothered to make a flexible way i can reorder things. thanks for your help!

1. 1
2. 2
3. 3
4. 4
Rutin
12
5. 5

• 12
• 18
• 10
• 14
• 10
• ### Forum Statistics

• Total Topics
632662
• Total Posts
3007702
• ### Who's Online (See full list)

There are no registered users currently online

×