Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1050345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:45:25+00:00 2026-05-16T16:45:25+00:00

Given a triangle vertex defined with three 3D points, how do you calculate the

  • 0

Given a triangle vertex defined with three 3D points, how do you calculate the angle between it and a given point.

class Point3D
{
    double x, y, z;
}

class Vertex
{
     Point3D P1, P2, P3;
}

Point3D LightPoint;

http://www.ianquigley.com/iq/RandomImages/vextor.png

Light point in Red. Blue points – triangle with the surface normal shown.

I need to calculate the surface normal, and the angle between that and the LightPoint. I’ve found a few bits a pieces but nothing which puts it together.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T16:45:26+00:00Added an answer on May 16, 2026 at 4:45 pm

    OK, here goes…

    You have points A, B, and C, each of which has coordinates x, y, and z. You want the length of the normal, as Matias said, so that you can calculate the angle that a vector between your point and the origin of the normal makes with the normal itself. It may help you to realize that your image is misleading for the purposes of our calculations; the normal (blue line) should be emanating from one of the vertices of the triangle. To turn your point into a vector it has to go somewhere, and you only know the points of the vertices (while you can interpolate any point within the triangle, the whole point of vertex shading is to not have to).

    Anyway, first step is to turn your Point3Ds into Vector3Ds. This is accomplished simply by taking the difference between each of the origin and destination points’ coordinates. Use one point as the origin for both vectors, and the other two points as the destination of each. So if A is your origin, subtract A from B, then A from C. You now have a vector that describes the magnitude of the movement in X, Y, and Z axes to go from Point A to point B, and likewise from A to C. It is worth noting that a theoretical vector has no start point of its own; to get to point B, you have to start at A and apply the vector.

    The System.Windows.Media.Media3D namespace has a Vector3D struct you can use, and handily enough, the Point3D in the same namespace has a Subtract() function that returns a Vector3D:

    Vector3D vectorAB = pointB.Subtract(pointA);
    Vector3D vectorAC = pointC.Subtract(pointA);
    

    Now, the normal is the cross product of the two vectors. Use the following formula:

    v1 x v2 = [ y1*z2 – y2*z1 , z1*x2 – z2*x1 , x1*y2 – x2*y1 ]

    This is based on matrix math you don’t strictly have to know to implement it. The three terms in the matrix are the X, Y, and Z of the normal vector. Luckily enough, if you use the Media3D namespace, the Vector3D structure has a CrossProduct() method that will do this for you:

    Vector3D vectorNormal = Vector3D.CrossProduct(vectorAB, vectorAC);
    

    Now, you need a third vector, between LightPoint and A:

    Vector3D vectorLight = PointA.Subtract(LightPoint);
    

    This is the direction that light will travel to get to PointA from your source.

    Now, to find the angle between them, you compute the dot product of these two and the length of these two:

    |v| = sqrt(x^2 + y^2 + z^2)

    v1 * v2 = x1*x2 + y1*y2 + z1*z2

    Or, if you’re using Media3D, Vector3D has a Length property and a DotProduct static method:

    double lengthLight = vectorLight.Length;
    double lengthNormal = vectorNormal.Length;
    double dotProduct = Vector3D.DotProduct(vectorNormal, vectorLight);
    

    Finally, the formula Matias mentioned:

    v1 * v2 = |v1||v2|cos(theta)

    rearranging and substituting variable names:

    double theta = arccos(dotProduct/(lengthNormal*lengthLight))
    

    Or, if you were smart enough to use Media3D objects, forget all the length and dot product stuff:

    double theta = Vector3D.AngleBetween(vectorNormal, vectorLight);
    

    Theta is now the angle in degrees. Multiply this by the quantity 2(pi)/360 to get radians if you need it that way.

    The moral of the story is, use what the framework gives you unless you have a good reason to do otherwise; using the Media3D namespace, all the vector algebra goes away and you can find the answer in 5 easy-to-read lines [I edited this, adding the code I used — Ian]:

    Vector3D vectorAB = Point3D.Subtract(pointB, pointA);
    Vector3D vectorAC = Point3D.Subtract(pointC, pointA);
    Vector3D vectorNormal = Vector3D.CrossProduct(vectorAB, vectorAC);
    Vector3D vectorLight = Point3D.Subtract(pointA, LightPoint);
    
    double lengthLight = light.Length;
    double lengthNormal = norm.Length;
    double dotProduct = Vector3D.DotProduct(norm, light);
    double theta = Math.Acos(dotProduct / (lengthNormal * lengthLight));
    
    // Convert to intensity between 0..255 range for 'Color.FromArgb(... 
    //int intensity = (120 + (Math.Cos(theta) * 90));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a 3D point (x, y & z), and a triangle made of three
I am trying to find circumcenter of Given Three point of Triangle…….. NOTE: all
Let's say I have a triangle given by the three integer vertices (x1,y1), (x2,y2)
I'm trying to animate a triangle around a given point. I want the shape
I've got a right triangle and I want to check if a given point
Given a path expressed as an array of 2d points: Point[] path = new
given a Python class hierarchy, say class Base: def method1 def method2 def method3
Given the triangle with vertices (a,b,c): c / \ / \ / \ a
Is there a Java graphics library that will rasterize a triangle given the coordinates
How to draw a triangle using SlimDX's Direct2D interface given triangle vertices are given

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.