#### Archived

This topic is now archived and is closed to further replies.

# Angle between 2 points used to calculate light.

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

## Recommended Posts

(Newbie - untextured 3D engine) Isn''t there a formula to calculate the angle between to points with only sin, cos or tan? I''m going to use this first to find the angle (for two spots in a polygon) then add 90 degrees to the result and then find the angle between the light spot and the result from before + the 90 degrees. Then find the distance and substract it from the above. Then fin % of the damn thing and calculate how dark a colour in my 3D object should be... Can you give me any hints on doing this? Making light in an untextured 3D model? Please don''t write strange coding language... I''m quite an idiot on that point. I''m having my own coding language, and I don''t think any of you know that...

##### Share on other sites
Oh i think I found out...

To find the angle i can use this formula:

Tan-1( (Za - Zb) / (Xa - Xb) )

##### Share on other sites
Hi there,

in C ( I think math.h ) is a function called atan2 which computes the angle between the origin and a vector. The normal atan (Tan-1)may results in an ambigous angle

Good luck

##### Share on other sites
It''s also good for when (Xa - Xb) = 0

##### Share on other sites
Um, Andos, you''re describing cosine shading. If you have a polygonal surface and a light L whose direction is described by a vector, L.v, the magnitude of light incident on the surface is the dot product of the surface normal and the light direction.

%lighting = dotp( N, L.v );

The surface normal for a triangle can be determined as the cross product of the vectors describing two of its sides. Add one more cross product per additional polygon vertex.

N = crossp( (v2 - v1), (v2 - v3) );
normalize( N );

Done.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 17
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631758
• Total Posts
3002163
×