vba ratio approximation

vba ratio approximation

Amremad
Collaborator Collaborator
983 Views
6 Replies
Message 1 of 7

vba ratio approximation

Amremad
Collaborator
Collaborator

i have a question about approximation when i trying to make a macro dependent angles which iam using PI Value (22/7)

or (3.14285714285714)

 

but the range of the double type isn't enogh to carry (3.1428571428571428571428571428571) cause i need this approcimation or greater than but i can't know how can i make this in vba macro

 

sorry for my english

 

if u can help me to calculate this ((3.142857142857142857142857142857142857142857142857142857142857142857142857142857142857142857)

i will be happy

 

thanks

0 Likes
Accepted solutions (1)
984 Views
6 Replies
Replies (6)
Message 2 of 7

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

if you look to >>>this table<<< (dotNET based) you see the datatype "double" is limited and there is no other datatype (except you develop your own) that can hold more decimal places. And at least CPU's and GPU's also can't hold more accuracy then double.

 

The other question would be: whatfor do you need more accuracy as it will be lost at the point you create a geometry element with that data. Because AutoCAD (or any other CAD-package) is able to hold data more detailed than double.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 7

Amremad
Collaborator
Collaborator

thx mr alfred for fast reply

 

i know the double type is the max range of floating numbers - but i have a miss calculte becouse i can't get approximation witch i need - my question how can i solve this problem without double type or with other datatype

 

if you need to write whole code i will

0 Likes
Message 4 of 7

truss_85
Advocate
Advocate

This is very curios can you post your code and what would be cause misscalculation need that number of data.

0 Likes
Message 5 of 7

Amremad
Collaborator
Collaborator

Private Function DrawSideElbow(PDM As Double, PL As Double, PR As Double, FT As Double, FOD As Double, FID As Double, FTC As Double, Ang As Double, PB0 As Point, View As Integer)
'On Error Resume Next
Dim L As Double
'Dim R1 As Double
'Dim R2 As Double

Dim PLine As AcadPolyline
Dim P(1 To 4) As Point


Dim PB1 As Point

Dim Ang1 As Double
Dim Ang2 As Double
Dim X As Double

Select Case View
    ' Draw Side View
    Case 0
        'draw first elbow part
        L = PL - (PR + FT)
        'R1 = PR + PDM / 2
        'R2 = PR - PDM / 2
        
        PB1.X = PB0.X - L: PB1.y = PB0.y + L
        
        P(1) = GetPoint(PB0, -90, (L + PR + PDM / 2))
        P(2) = GetPoint(PB1, -90, (PR + PDM / 2))
        P(3) = GetPoint(PB1, -180, (PR + PDM / 2))
        P(4) = GetPoint(PB0, -180, (L + PR + PDM / 2))

        
        Set PLine = DrawPolyLine(P())
        PLine.SetBulge 1, Tan(90 / (22 / 7))
        PLine.Layer = "BIO-PIPE1"

        P(1) = GetPoint(PB0, -90, (L + PR - PDM / 2))
        P(2) = GetPoint(PB1, -90, (PR - PDM / 2))
        P(3) = GetPoint(PB1, -180, (PR - PDM / 2))
        P(4) = GetPoint(PB0, -180, (L + PR - PDM / 2))


        Set PLine = DrawPolyLine(P())
        PLine.SetBulge 1, Tan(90 / (22 / 7))
        PLine.Layer = "BIO-PIPE1"

        'draw first flange
        'PF.X = P0.X + L
        'PF.y = P0.y
        'DrawFlange FOD, FID, FT, FTC, Ang, PF, DegToRad(-90)

        'draw second flange
        'PF.X = P0.X - PR
        'PF.y = P0.y - PR - L
        'DrawFlange FOD, FID, FT, FTC, Ang, PF, -180

    Case 1
    Case 2
End Select

End Function

Public Function GetPoint(P As Point, Angle As Double, R As Double) As Point
        'Dim X, Y As Double
        GetPoint.y = P.y - (Sin(DegToRad(Angle)) * R)
        GetPoint.X = P.X + (Cos(DegToRad(Angle)) * R)
End Function

Private Function DegToRad(Ang As Double) As Double
DegToRad = Ang * (22 / 7) / 180
End Function

Private Function RadToDeg(Ang As Double) As Double
RadToDeg = Ang * 180 / (22 / 7)

End Function

Public Function GetPoint(P As Point, Angle As Double, R As Double) As Point
        'Dim X, Y As Double
        GetPoint.y = P.y - (Sin(DegToRad(Angle)) * R)
        GetPoint.X = P.X + (Cos(DegToRad(Angle)) * R)
End Function


0 Likes
Message 6 of 7

Alfred.NESWADBA
Consultant
Consultant
Accepted solution

Hi,

 

have you ever checked that

PI - 22/7 = 0,00126448926734961868021375957764

 

So you have a difference as 22/7 is not equal to PI.

 

What you can use instead to calculate PI is:

PI = 4 * arctan(1)

 

HTH, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 7 of 7

Amremad
Collaborator
Collaborator

thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx thx

 

iam soo happy

it's work very good

0 Likes