?
Solved

Calculate Normal  Vector for given triangle in Managed DirectX C#

Posted on 2007-08-10
6
Medium Priority
?
3,035 Views
Last Modified: 2013-12-17
In Managed DirectX C#, I am creating a custome triangle list.

What I want to know, is how to easily (or do it at all i guess) calculate the normal for a given face (triangle). This is sure easy when you have a fave which all to verticies rest on the same X,Y, or Z plane, but how can you calaculate it if you have a face which could be facing any direction?

I am sure it can be calculated from the 3 verticies, but I am not seeing how. I am hoping there is a simple method which returns a normal vector for a given triangle but that's probably hoping for to much.

Thanks,
Matt
0
Comment
Question by:mattososky
  • 4
  • 2
6 Comments
 
LVL 22

Expert Comment

by:JimBrandley
ID: 19672495
You can use the vector coross procuct.
Assume triangles have vertices at p1 (x1, y1, z1), p2 (x2, y2, z2) p3 (x3, y3, z3).
Build two vectors:
A = (x2 - x1)i + (y2 - y1)j + (z2 - z1)k = A1i + A2j + A3k
B = (x3 - x1)i + (y3 - y1)j + (z3 - z1)k = B1i + B2j + B3k

C = A X B = (A2B3 - A3B2)i + (A3B1 - A1B3)j + (A1B2 - A2B1)k

C is perpendicular (normal)  to the plane of the triangle.
0
 

Author Comment

by:mattososky
ID: 19673523
As I'm reading your comment I don't understand what the variables i,j,k are suppose to represent.
0
 
LVL 22

Expert Comment

by:JimBrandley
ID: 19673556
They identify the components of the vector. i is component parallel to x axis, j is parallel to y, and k is parallel to z. They are not really variables. So if you think of a vector as a 3-tuple, then the "i" value is the first, j the second, and k the third.

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:JimBrandley
ID: 19673603
Just to clarify, in case you are new to vectors, it's kind of like the general equation of a line:
aX + bY +cZ + D = 0

Where x, y and z just identify the use of the variables.
0
 

Author Comment

by:mattososky
ID: 19673860
perhaps just the language and syntax are the difference. I'm using c# managed directX 9. you can define a Vector3 like Vector3(float x, float y, float z) and access the members by vector.position.x , y , & z;



So if I'm understanding you right. what your saying is i can do this: Create 2 new vectors. NewVectory1 will have x,y,z componets that are the difference of the x,y,z of Triangle points 2 & 1. NewVector2 will have x,y,z, components that are the difference of the x,y,z of Triangle points 3 & 1. Then, multiply the two new vectors together and i will get a vector perpendicular to the face of the Triangle.

Yes?

0
 
LVL 22

Accepted Solution

by:
JimBrandley earned 1500 total points
ID: 19673940
Correct, but the components need the operations shown here for the multiplication;
say your vectors are called A and B, then:
C = A X B = new Vector( (AYBZ - AZBY),  (AZBX - AXBZ),  (AXBY - AYBX));

Make sense now?

0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question