See the top rated post in this thread. Click here

Results 1 to 6 of 6

Thread: Math in .Net

  1. #1
    100 Club matt.worland's Avatar
    Join Date
    2015-12
    Location
    Denver, CO USA
    Posts
    174
    Login to Give a bone
    0

    Default Math in .Net

    Im trying to port over some code and Im still fairly new to .net and cant readily find functions when needed.
    How would I translate this code to vb.net
    Code:
    (or
       (and (= (car P2) (car P1)) (< (cadr P1) (cadr P2))) ;UP
       (and (< (car P1) (car P2)) (< (cadr P1) (cadr P2))) ;UP-Right
       (and (< (car P1) (car P2)) (= (cadr P2) (cadr P1))) ;Right
       (and (< (car P1) (car P2)) (> (cadr P1) (cadr P2))) ;Right-Down
    )
    (setq P1 (polar P1 (angle P1 P2) 0.0625))
    Thanks,
    matt
    matt worland

  2. #2
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Chelan WA
    Posts
    1,043
    Login to Give a bone
    1

    Default Re: Math in .Net

    Its untested but it is something like this.

    Code:
    Imports Autodesk.AutoCAD.Geometry
    Imports Autodesk.AutoCAD.DatabaseServices
    Imports Autodesk.AutoCAD.Runtime
    
    Public Class Class1
    
        Private Function Polar5Net(ByVal objPoint1 As Point2d, ByVal objPoint2 As Point2d)
            On Error Goto OnError
            If (objPoint1.X = objPoint2.X And objPoint1.Y < objPoint2.Y) Or _
               (objPoint1.X < objPoint2.X And objPoint1.Y < objPoint2.Y) Or _
               (objPoint1.X < objPoint2.X And objPoint1.Y = objPoint2.Y) Or _
               (objPoint1.X < objPoint2.X And objPoint1.Y > objPoint2.Y) Then
                With objPoint1.GetVectorTo(objPoint2)
                    Return objPoint1.Add(.DivideBy(.Length / 0.625))
                End With
            End If
    OnError:   Return Nothing
        End Function
    
        <LispFunction("Polar5")> _ 
        Public Function Polar5LISP(ByVal rbfLISPArguments As ResultBuffer)
            On Error GoTo OnError
            Dim arrLISPArguments As TypedValue() = rbfLISPArguments.AsArray
            If arrLISPArguments.Length = 2 Then
                Dim objPoint1 As Point2d = CType(arrLISPArguments(0).Value, Point2d)
                Dim objPoint2 As Point2d = CType(arrLISPArguments(1).Value, Point2d)
                Return Polar5Net(objPoint1, objPoint2)
            End If
    OnError: Return New TypedValue(LispDataType.Nil, -1)
        End Function
    
    End Class
    I made a few modifications and exposed the function to LISP too.
    Last edited by peter; 2014-01-14 at 06:55 PM.
    AutomateCAD

  3. #3
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,536
    Login to Give a bone
    1

    Default Re: Math in .Net

    Code:
    using Autodesk.AutoCAD.Geometry;
    
    using System;
    
    namespace BlackBox.AutoCAD.Geometry
    {
        public class Sample
        {
            object Foo(Point2d pt1, Point2d pt2, double length) //PolarIf
            {
                object ret = null;
    
                if (pt1.X == pt2.X && pt1.Y < pt2.Y | // up
                    pt1.X < pt2.X && pt1.Y < pt2.Y | // up-right
                    pt1.X < pt2.X && pt1.Y == pt2.Y | // right
                    pt1.X < pt2.X && pt1.Y > pt2.Y // right-down
                    )
                {
                    double ang = pt1.GetVectorTo(pt2).Angle;
    
                    ret = new Point2d(pt1.X + length * Math.Cos(ang),
                        pt1.Y + length * Math.Sin(ang));
                }
    
                return ret;
            }
        }
    }
    * Note - I typically reserve Try, Catch, Finally blocks for main code, unless the Method being called is unable to preclude an exception through code logic.
    Last edited by BlackBox; 2014-01-15 at 05:26 PM.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3620, Core i7-7700K 4.2GHz, 64GB RAM, Samsung 970 Pro M.2, 8GB NVIDIA Quadro P4000

  4. #4
    100 Club matt.worland's Avatar
    Join Date
    2015-12
    Location
    Denver, CO USA
    Posts
    174
    Login to Give a bone
    0

    Default Re: Math in .Net

    Thank you guys, I was in the middle of writing a GetVectorTo function. I was hoping Autodesk didnt leave out the little stuff.

    I appreciate the examples,
    matt
    matt worland

  5. #5
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,536
    Login to Give a bone
    0

    Default Re: Math in .Net

    Quote Originally Posted by matt.worland View Post
    Thank you guys, I was in the middle of writing a GetVectorTo function. I was hoping Autodesk didnt leave out the little stuff.

    I appreciate the examples
    You're welcome; I'm happy to help.

    Along the lines of 'examples', one could also implement a simple Extension Method, which would reduce my code above, to this:

    Code:
    using Autodesk.AutoCAD.Geometry;
    
    namespace BlackBox.AutoCAD.Geometry
    {
        public class Sample
        {
            static object Foo(Point2d pt1, Point2d pt2, double length)
            {
                return pt1.PolarIf(pt2, length);
            }
        }
    }
    ... And here's the dependent Extension Method:

    Code:
    using System;
    
    namespace Autodesk.AutoCAD.Geometry
    {
        public static class Point2dExtensions
        {
            public static object PolarIf(this Point2d pt1, Point2d pt2, double length)
            {
                object ret = null;
    
                if (pt1.X == pt2.X && pt1.Y < pt2.Y | // up
                    pt1.X < pt2.X && pt1.Y < pt2.Y | // up-right
                    pt1.X < pt2.X && pt1.Y == pt2.Y | // right
                    pt1.X < pt2.X && pt1.Y > pt2.Y // right-down
                    )
                {
                    double ang = pt1.GetVectorTo(pt2).Angle;
    
                    ret = new Point2d(pt1.X + length * Math.Cos(ang),
                        pt1.Y + length * Math.Sin(ang));
                }
    
                return ret;
            }
        }
    }
    Cheers
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3620, Core i7-7700K 4.2GHz, 64GB RAM, Samsung 970 Pro M.2, 8GB NVIDIA Quadro P4000

  6. #6
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,536
    Login to Give a bone
    0

    Default Re: Math in .Net

    Quote Originally Posted by matt.worland View Post
    ... I was in the middle of writing a GetVectorTo function. I was hoping Autodesk didnt leave out the little stuff.
    Also worthy of note; Object Browser is your friend.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3620, Core i7-7700K 4.2GHz, 64GB RAM, Samsung 970 Pro M.2, 8GB NVIDIA Quadro P4000

Similar Threads

  1. Revit Math
    By ThinkRevit in forum Revit Architecture - Families
    Replies: 1
    Last Post: 2012-10-18, 05:33 PM
  2. Replies: 1
    Last Post: 2011-12-14, 11:51 PM
  3. Looking for a math genius
    By robert.manna in forum Revit Architecture - Families
    Replies: 24
    Last Post: 2009-09-24, 11:50 PM
  4. Autocad Math?
    By Anthony Rhodes in forum AutoLISP
    Replies: 6
    Last Post: 2008-12-01, 06:15 PM

Posting Permissions

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