+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15
  1. #1
    Senior Member
    Using
    Civil 3D 2008
    Join Date
    Feb 2008
    Posts
    294

    Default Angle/Slope of Tangent to a curve vb.net

    Registered forum members do not see this ad.

    Is anyone able to help

    In vb.net how do i find the angle of the tangent line to a curve at a given point relative to the X axis?

    Also would this have to be quadrant sensitive?

  2. #2
    Forum Deity
    Using
    not specified
    Join Date
    Jul 2004
    Location
    Anchorage, Alaska
    Posts
    2,074

    Default

    Don't know vb.net, but the function/expression you need is the "arc tangent", so look for something like that. In lisp it's "atan". And yes it's quadrant sensitive, positive tangent would give you a 0-90 degree result, negative is for a 90-180 degrees.

    **edit** found this, might help:

    This example uses the Atan method of the Math class to calculate the value of pi.

    Code:
    Public Function GetPi() As Double
        ' Calculate the value of pi.
        Return 4.0 * Math.Atan(1.0)
    End Function
    Last edited by CarlB; 2nd Mar 2009 at 09:46 am.

  3. #3
    Super Member SEANT's Avatar
    Using
    AutoCAD 2012
    Join Date
    Aug 2005
    Location
    Rhode Island
    Posts
    1,971

    Default

    The general methodology for 3d curves would be:

    1. Select the curve
    2. Pick a point(Point3d) on the curve with (DatabaseServices.Curve.GetClosestPointTo)
    3. Get first derivative(Geometry.Vector3d) with(DatabaseServices.Curve.GetFirstDerivative (Geometry.Point3d))
    4. Get angle with System.Math.Atan(Geometry.Vector3d.Y/Geometry.Vector3d.X)

  4. #4
    Senior Member
    Using
    Civil 3D 2008
    Join Date
    Feb 2008
    Posts
    294

    Default

    ahh thank you very much

  5. #5
    Senior Member
    Using
    Civil 3D 2008
    Join Date
    Feb 2008
    Posts
    294

    Default

    so how do i calculate what quadrant it is in so that i can calculate the 'Normal to the tangent'.?

  6. #6
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,818

    Default

    Tan is positive for quadrants 1 and 3 and negative for quadrants 2 and 4, hence a positive result indicates a vector at 0-pi/2 to the x-axis, plus or minus pi; and negative pi/2 - pi, plus or minus pi.

    I suppose you could add coding to correct the angle by pi radians so that you will only get an answer between 0 and pi, then the normal to the tangent will just be the arctan + pi/2.

    Is this a purely 2D problem, or are you interested in the Binormal to the tangent also?
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  7. #7
    Senior Member
    Using
    Civil 3D 2008
    Join Date
    Feb 2008
    Posts
    294

    Default

    No its purely 2d.

    Thanks for that - i changed the code around so it will work now.

    This is what i have.

    Code:
    Public Function CalcAngle(ByVal ObjCurve As AcadNetDbServices.Curve, ByVal Dist As Double)
     
    Dim Radians As Double
    Dim Degrees As Double
    Dim Point1 As AcadNetGeometry.Point3d = ObjCurve.GetPointAtDist(Dist)
    Dim firstderiv As AcadNetGeometry.Vector3d = ObjCurve.GetFirstDerivative(Point1)
    Radians = Math.Atan2(Cdbl(firstderiv.Y) , Cdbl(firstderiv.X))
    Degrees = Radians * (180 / Math.PI)
    
    'If in positive quadrants then = 180 - abs.Degrees
    'If in Negative quadrants then = Abs.Degrees - 180
    If Degrees < 0 Then
    Degrees = (Math.Abs(Degrees)) + 180
    Else
    Degrees = 180 - (Math.Abs(Degrees))
    End If
    CalcAngle = Degrees
    
    End Function
    

  8. #8
    Forum Deity
    Using
    not specified
    Join Date
    Jul 2004
    Location
    Anchorage, Alaska
    Posts
    2,074

    Default

    Not sure why you would set Degrees = 180 - angle for any positive result. Say it was initially calculated at 45 degrees, wouldn't that be a good answer already? But then I don't know what you're using it for...

  9. #9
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,818

    Default

    I don't know much about vb.net (in fact I know absolutely nothing about it), but when you find the first derivative, does that not return a vector? - Then you would know exactly the direction of the tangent from the vector.
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  10. #10
    Senior Member
    Using
    Civil 3D 2008
    Join Date
    Feb 2008
    Posts
    294

    Default

    Registered forum members do not see this ad.

    derivative gives the slope of the tangent.

    using atan2 gets the arc tangent to it.

    also i had to use Degrees = 180 - Angle in the positive quadrant because i was getting answers like 175 & 115 when it should be 5 & 65 etc

    Thanks for your help guys.

    This works

Similar Threads

  1. how do you shade 20% slope
    By paulg in forum AutoCAD General
    Replies: 5
    Last Post: 21st Jan 2010, 09:00 pm
  2. Slope of a line
    By smorales02 in forum AutoCAD General
    Replies: 19
    Last Post: 13th Aug 2008, 03:50 pm
  3. Top, bottom of Slope linetype
    By Hardney in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 10
    Last Post: 16th Jun 2008, 01:01 pm
  4. Slope Shading Questions
    By ebwbjen in forum AutoCAD Drawing Management & Output
    Replies: 2
    Last Post: 31st May 2008, 11:46 pm
  5. Tangent,Tangent,Radius?
    By bugleboy62 in forum AutoCAD Beginners' Area
    Replies: 24
    Last Post: 10th Feb 2007, 09:57 am

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts