Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with sin() math function

Status
Not open for further replies.

Korizon67

Programmer
Apr 25, 2007
36
US
I am not very fluent in VB, I have the following macro for drawing points in the cam program I use to program wire EDMs
Code:
Sub cdb()
    'Macro Recorder 8/31/2007 by Mike
On Error Resume Next

    'Declare the variables
    Dim App As Esprit.Application
    Dim doc As Esprit.Document
    Dim M_Point As Esprit.Point
    Dim M_Segment As Esprit.Segment
    Dim S, W, L, XSINE, YSINE, X1, Y1, X2, Y2, X3, Y3, S1X, S1Y, S2X, S2Y

    'Initialize the App and Doc Variables
    Set App = Application
    Set doc = App.Document
    S = InputBox(prompt, "S Dim", "Input S Dimension")
    W = InputBox(prompt, "W Dim", "Input W Dimension")
    L = InputBox(prompt, "L Dim", "Input L Dimension")
    X1 = 0.0569
    Y1 = 0.6874
    X2 = 0.273406
    Y2 = 0.8124
    X3 = 0.150719
    Y3 = 1.0249
    XSINE = Sin(30) * S
    YSINE = Sin(60) * S
    S1X1 = X1 + XSINE
    S1Y1 = Y1 - YSINE
    S2X1 = X2 + XSINE
    S2Y1 = Y2 - YSINE
    
    'Add a Point
    Set M_Point = doc.Points.Add(S1X1, S1Y1, 0)

    'Set the properties for the new Point object
    With M_Point
        .Color = 65408
        .LineType = espSolid
        .Grouped = 0 'False
        .LineWeight = espLineWeightThin
        .X = S1X1
        .Y = S1Y1
        .Z = 0
        .Layer = doc.Layers("STRAIGHT")
    End With

    'Add a Point
    Set M_Point = doc.Points.Add(S2X1, S2X1, 0)

    'Set the properties for the new Point object
    With M_Point
        .Color = 65408
        .LineType = espSolid
        .Grouped = 0 'False
        .LineWeight = espLineWeightThin
        .X = S2X1
        .Y = S2Y1
        .Z = 0
        .Layer = doc.Layers("STRAIGHT")
    End With

    'Very Important - destroy all of the Objects
    Set M_Point = Nothing
    Set M_Segment = Nothing
    Set doc = Nothing
    Set App = Nothing
    Set S = Nothing
    Set W = Nothing
    Set L = Nothing
    Set X1 = Nothing
    Set Y1 = Nothing
    Set X2 = Nothing
    Set Y2 = Nothing
    Set X3 = Nothing
    Set Y3 = Nothing
    Set S1X = Nothing
    Set S1Y = Nothing
    Set S2X = Nothing
    Set S2Y = Nothing
    
End Sub

My problem seems to lie in the sine calculations, It is returning negative values, for example, .0372 * sin(30) should be .0186, my equation is returning something like -.036755

Any ideas why this would be?

Thank You

Mike
 
Sin(30) = -0.98803
Sin(30[sup]o[/sup]) = 0.5

You need to convert degrees to radians.

Radians = Degrees * PI / 180

-George

"the screen with the little boxes in the window." - Moron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top