# .NET and More > Silverlight >  Position Elements

## kidfug

I'm having a problem positioning elements and not sure where I'm going wrong. The elements are basically ellipsegeometry paths, since all of the elements are have the same radius.x and radius.y I've added a property Radius that I set when I add them.

This code should position them without an overlap and it works fine as long as the elements have the same radius



```
Public Sub Group2Elements(ByVal Conductor1 As Conductor, ByVal Conductor2 As Conductor, ByVal Angle As Double)
        Dim DeltaX As Double = System.Math.Cos(Radians(Angle)) * (Conductor1.Radius + Conductor2.Radius)
        Dim DeltaY As Double = System.Math.Sin(Radians(Angle)) * (Conductor1.Radius + Conductor2.Radius)
        Dim Cond2Center As Point = New Point(Conductor2.GetValue(Canvas.LeftProperty) + Conductor2.Radius, Conductor2.GetValue(Canvas.TopProperty) + Conductor2.Radius)
        Conductor1.SetValue(Canvas.LeftProperty, (Cond2Center.X + DeltaX) - Conductor1.Radius)
        Conductor1.SetValue(Canvas.TopProperty, (Cond2Center.Y + DeltaY) - Conductor1.Radius)
    End Sub
```

and the function to convert Degrees to Radians is as follows





```
Private Function Radians(ByVal Deg As Double) As Double
            Radians = Deg * System.Math.PI / 180
        End Function
```


The other problem I'm having is positioning 1 element next to 2 other elements, once again if the elements have the same radius it seems to work.



```
     Public Sub Group3Elements(ByVal Conductor1 As Conductor, ByVal Conductor2 As Conductor, ByVal Conductor3 As Conductor, ByVal Side As Integer)
            Dim DeltaX As Double
            Dim DeltaY As Double
            Dim Angle As Double
            Dim aLength, bLength, cLength As Double
            Dim aAngle, bAngle, cAngle As Double
            aLength = Conductor3.Radius + Conductor1.Radius
            bLength = Conductor2.Radius + Conductor1.Radius
            cLength = Conductor2.Radius + Conductor3.Radius
           aAngle = Degrees(System.Math.Acos((bLength ^ 2 + cLength ^ 2 - aLength ^ 2) / (2 * bLength * cLength)))
           bAngle = Degrees(System.Math.Acos((aLength ^ 2 + cLength ^ 2 - bLength ^ 2) / (2 * aLength * cLength)))
           cAngle = Degrees(System.Math.Acos((aLength ^ 2 + bLength ^ 2 - cLength ^ 2) / (2 * aLength * bLength)))
           If Side = 0 Then
               Angle = AngleBetween(Conductor2, Conductor3) - aAngle
           Else
               Angle = AngleBetween(Conductor2, Conductor3) + aAngle
           End If
           DeltaX = System.Math.Cos(Radians(Angle)) * (Conductor2.Radius + Conductor1.Radius)
           DeltaY = System.Math.Sin(Radians(Angle)) * (Conductor2.Radius + Conductor1.Radius)
           Dim Cond2Center As Point = New Point(Conductor2.GetValue(Canvas.LeftProperty) + Conductor2.Radius, Conductor2.GetValue(Canvas.TopProperty) + Conductor2.Radius)
           Conductor1.SetValue(Canvas.LeftProperty, (Cond2Center.X + DeltaX) - Conductor1.Radius)
           Conductor1.SetValue(Canvas.TopProperty, (Cond2Center.Y + DeltaY) - Conductor1.Radius)
       End Sub
```

and the AngleBeteween code is as follows



```
 Public Function AngleBetween(ByVal Conductor1 As Conductor, ByVal Conductor2 As Conductor) As Double
        Dim Angle As Double
        Dim Cond1Center As Point = New Point(Conductor1.GetValue(Canvas.LeftProperty) + Conductor1.Radius, Conductor1.GetValue(Canvas.TopProperty) + Conductor1.Radius)
        Dim Cond2Center As Point = New Point(Conductor2.GetValue(Canvas.LeftProperty) + Conductor2.Radius, Conductor2.GetValue(Canvas.TopProperty) + Conductor2.Radius)
        Angle = Degrees(System.Math.Asin((Cond2Center.Y - Cond1Center.Y) / (Conductor2.Radius + Conductor1.Radius)))
        If Cond2Center.X < Cond1Center.X Then Angle = 180 - Angle
        AngleBetween = Angle
    End Function
```

and finally the the function to convert  Degrees to Radians is



```
     Private Function Degrees(ByVal rad As Double) As Double
            Degrees = rad * 180 / System.Math.PI
        End Function
```

Again both Group2Elements & Group3Elements work if the elements all have the same radius. 

Any help would be appreciated

 Thanks

----------

