How To Create a Vector XYZ tilted up from the view direction by a specified angle for eg 30 degrees * MAth.pi/180

How To Create a Vector XYZ tilted up from the view direction by a specified angle for eg 30 degrees * MAth.pi/180

FrankHolidaytoiling
Advocate Advocate
838 Views
5 Replies
Message 1 of 6

How To Create a Vector XYZ tilted up from the view direction by a specified angle for eg 30 degrees * MAth.pi/180

FrankHolidaytoiling
Advocate
Advocate

I have a the view direction that I use for my reference intersector. I would like to try various altitude angles up from the view direction in a section with starting point at a wall(See the diagram attached in section). I know there are transforms and various complex maths answers on SO, I was hoping to use a simpler built in method if available? 

0 Likes
Accepted solutions (2)
839 Views
5 Replies
Replies (5)
Message 2 of 6

FrankHolidaytoiling
Advocate
Advocate

ViewDirection-ReferenceIntersector.PNG

0 Likes
Message 3 of 6

FrankHolidaytoiling
Advocate
Advocate

After reviewing a failed to check if a wall is exterior because the walls are courtyard walls, i was thinking this fence avoiding, technique in plan could be used at an angle to point the corner ends towards infinite nothingness as well?

 

0 Likes
Message 4 of 6

jeremy_tammik
Alumni
Alumni
Accepted solution

This kind of trigonometry is not difficult. Your children learn it in school, I hope. Please take a moment to either read the Wikipedia article or study some other tutorials:

  

https://en.wikipedia.org/wiki/Trigonometric_functions#Law_of_tangents

  

From that article, I find this image most helpful:

  

Unit Circle Definitions of Six Trigonometric Functions

  

https://en.wikipedia.org/wiki/File:Unit_Circle_Definitions_of_Six_Trigonometric_Functions.png

  

wiki_trigo.png

    

Decide what angle you wish to use, e.g., 30 degrees. Determine its tangens value, ca. 30*3.14/180 = 0.5. Take your horizontal view direction XYZ vector (x,y,0). Replace the Z coordinate by the tangens you calculated, yielding  (x,y,0.5). Voila. That is your new tilted direction vector. You may normalise it if you like.

   

Please do not be afraid of trigonometry, it is very intuitive as soon as you stop being scared of it.

    

I condemn our teachers and education systems (not all, but all too many) for inoculating kids with fear of maths and geometry.

  

This is basic human intuitive understanding,. The greeks mastered it 3000 yeards ago. We can handle a computer and a smartphone, but not simple trigonometry? 

  

Why?

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 5 of 6

RPTHOMAS108
Mentor
Mentor

 

 

Message 6 of 6

RPTHOMAS108
Mentor
Mentor
Accepted solution

I would probably look at it in terms of the ratio between the forward direction and XYZ.BasisZ that the angle represents.

 

i.e. for 45 degrees it would be the average of the two (forward and up). When you consider each component of each vector they range from the value you have looking forward to the value you have looking up. If you divide these delta values by 90 do you then have a fraction for each component you can multiple by your angle (in degrees) to add to the forward direction? 

 

I've never done it that way to be fair, I would probably have also solved it with trigonometry but the XYZ has good functionality for arithmetic operations.

 

Similar as noted above in Jeremy's post below is probably the easiest way:

 

Dim V0 As New XYZ(1, 0.5, 0) 'some random flat direction
V0 = V0.Normalize
Dim Ang As Double = 30 'Angle in degrees
Dim Ang_r As Double = (Math.PI / 180) * Ang
Dim T As Double = Math.Tan(Ang_r) 'Tan(Ang) = Opp/1
Dim Vz As New XYZ(0, 0, T)
Dim V1 As XYZ = (V0 + Vz).Normalize 'The direction with tilt of 30 degrees up from horizontal

 

I think I was oversimplifying earlier because it isn't linear. Always on the lookout for new ways of doing the same things. Above is ok from 0 to < 90.  From that point on you have to check the quadrant and consider the Tan function doesn't work approaching 90 or 270 but you know those values are looking straight up and straight down respectively.