Solved

Function to find X Y coordinates of an arcs center point

Posted on 2010-08-24
6
2,341 Views
Last Modified: 2012-05-10
Hi,
I am trying to create a function in VB.net to return to me the xy coordinates of where the center point of any arc is.
I am very poor with math so this is really over my head. I did a lot of searching but could not find anything close enough so that i could make it work.

I know the arc start point ,arc end point and the radius.

Please help,
Regards,
Ben
Private Sub GetCenterPoints(ByVal dbArcStartX As Double, ByVal dbArStartY As Double, _
                                ByVal dbArcEndX As Double, ByVal dbArcEndY As Double, ByVal dbRadius As Double)

        Dim dbCenterPointX As Double
        Dim dbCenterPointY As Double


        MessageBox.Show("The center point = X " & dbCenterPointX & " Y " & dbCenterPointY)
    End Sub

Open in new window

Arc.JPG
0
Comment
Question by:bguenther
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 10

Expert Comment

by:Jini Jose
ID: 33516071
0
 
LVL 13

Expert Comment

by:Carl Bohman
ID: 33516313
Note that there are two possible centers, not just one.  This page explains why:

http://mathforum.org/library/drmath/view/54490.html
0
 

Expert Comment

by:tyogerst
ID: 33516353
http://en.wikipedia.org/wiki/Versine

Find the midpoint between your start(x1,y1) and end(x2,y2) points:
midpoint(x3,y3) = (x1 + x2)/2 , (y1 + y2)/2

the slope of the versine segment will be perpendicular to the line between the start and end points
slope = -(y2-y1)/(x2-x1)

starting at the center of the circle, calculate the endpoint of a radius segment that passes through the midpoint with the same slope as the versine.
radiusendpoint(x4,y4):
x4 = sqrt(r^2 / (1+slope^2))
y4 = x4*slope

Assumptions: a clockwise path between start and end points, circle centered at (0,0) - if not, then just apply a linear offset before and after your calculation
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

Author Comment

by:bguenther
ID: 33557530
Thanks for the reply's, I will play with this and see if i can get it going.

What i am trying to achieve here is by knowing start and end point and radius and whether it is clockwise or counter clockwise is to get the start angle and end angle of the arc.

As for my original question "How to get the center point of the arc" is it possible to get just one possible to get just one center with the specs that i have?

The code that i have pasted below is the function that i was going to use once i had the center point of the arc. It only works on arcs under 180 degrees. So it is useless to me because my arcs will be all over the place.
It also does not work quite right it does not figure out the end angle properly.

I am not sure if this is allowed but I would like to rephrase  my original question. How to get the start and end angle of an arc. knowing start and end point and radius and whether it is clockwise or counter clockwise

Regards,
Ben
Private Shared Sub GetCirlce(ByVal dbArcStartX As Double, ByVal dbArStartY As Double, _
                               ByVal dbArcEndX As Double, ByVal dbArcEndY As Double, _
                               ByVal dbArcMidX As Double, ByVal dbArcMidY As Double, _
                               ByRef dbArcCenterX As Double, ByRef dbArcCenterY As Double, _
                               ByRef dbArcStartAngle As Double, ByRef dbArcEndAngle As Double, _
                               ByRef dbArcRadius As Double)

        Dim dbUnknown1 As Double
        Dim dbUnknown2 As Double
        Dim dbUnknown3 As Double
        Dim dbUnknown4 As Double
        Dim dbUnknown5 As Double
        Dim dbUnknown6 As Double

        'Unknown
        dbUnknown2 = (2 * dbArcStartX * (2 * dbArcEndY - 2 * dbArcMidY) - 2 * dbArStartY * (2 * dbArcEndX - 2 * dbArcMidX) + 4 * dbArcEndX * dbArcMidY - 4 * dbArcEndY * dbArcMidX)

        'Get the arc center point for X
        dbArcCenterX = ((dbArcStartX ^ 2 + dbArStartY ^ 2) * (2 * dbArcEndY - 2 * dbArcMidY) - 2 * dbArStartY * (dbArcEndX ^ 2 + dbArcEndY ^ 2 - dbArcMidX ^ 2 - dbArcMidY ^ 2) + 2 * dbArcMidY * (dbArcEndX ^ 2 + dbArcEndY ^ 2) - 2 * dbArcEndY * (dbArcMidX ^ 2 + dbArcMidY ^ 2)) / dbUnknown2
        'Get the arc center point for X
        dbArcCenterY = (2 * dbArcStartX * (dbArcEndX ^ 2 + dbArcEndY ^ 2 - dbArcMidX ^ 2 - dbArcMidY ^ 2) - (dbArcStartX ^ 2 + dbArStartY ^ 2) * (2 * dbArcEndX - 2 * dbArcMidX) + 2 * dbArcEndX * (dbArcMidX ^ 2 + dbArcMidY ^ 2) - 2 * dbArcMidX * (dbArcEndX ^ 2 + dbArcEndY ^ 2)) / dbUnknown2
        'Unknown
        dbUnknown1 = (2 * dbArcStartX * (2 * dbArcEndY * (dbArcMidX ^ 2 + dbArcMidY ^ 2) - 2 * dbArcMidY * (dbArcEndX ^ 2 + dbArcEndY ^ 2)) - 2 * dbArStartY * (2 * dbArcEndX * (dbArcMidX ^ 2 + dbArcMidY ^ 2) - 2 * dbArcMidX * (dbArcEndX ^ 2 + dbArcEndY ^ 2)) + (dbArcStartX ^ 2 + dbArStartY ^ 2) * (4 * dbArcEndX * dbArcMidY - 4 * dbArcEndY * dbArcMidX)) / dbUnknown2

        'Get the arc radius
        dbArcRadius = Math.Sqrt(dbUnknown1 + dbArcCenterX ^ 2 + dbArcCenterY ^ 2)

        If dbArcCenterX < dbArcStartX And dbArcCenterY <> dbArStartY Then
            dbArcStartAngle = Math.Atan((dbArStartY - dbArcCenterY) / (dbArcStartX - dbArcCenterX)) * 180 / 3.1415927
        End If

        If dbArcCenterX > dbArcStartX And dbArcCenterY <> dbArStartY Then
            dbArcStartAngle = 180 - Math.Atan((dbArStartY - dbArcCenterY) / (dbArcCenterX - dbArcStartX)) * 180 / 3.1415927
        End If

        If dbArcCenterX = dbArcStartX And dbArcCenterY < dbArStartY Then
            dbArcStartAngle = 90
        End If

        If dbArcCenterX < dbArcStartX And dbArcCenterY = dbArStartY Then
            dbArcStartAngle = 0
        End If

        If dbArcCenterX = dbArcStartX And dbArcCenterY > dbArStartY Then
            dbArcStartAngle = -90
        End If

        If dbArcCenterX > dbArcStartX And dbArcCenterY = dbArStartY Then
            dbArcStartAngle = 180
        End If

        dbUnknown3 = 1 - (((dbArcStartX - dbArcMidX) ^ 2 + (dbArStartY - dbArcMidY) ^ 2) / (2 * (dbArcRadius ^ 2)))
        If dbUnknown3 <> 1 And dbUnknown3 <> -1 Then
            dbArcEndAngle = Math.Atan(-dbUnknown3 / Math.Sqrt(1 - (dbUnknown3 ^ 2))) * 180 / 3.1415927 + 90
        End If
        If dbUnknown3 = -1 Then
            dbArcEndAngle = 180
        End If

        dbUnknown6 = (dbArcMidX - dbArcStartX)

        If dbUnknown6 <> 0 Then
            dbUnknown5 = (dbArcMidY - dbArStartY) / dbUnknown6
        End If

        dbUnknown4 = dbUnknown5 * (dbArcEndX - dbArcStartX) + dbArStartY

        If dbArcStartX < dbArcMidX And dbArcEndY > dbUnknown4 Then
            dbArcEndAngle = dbArcEndAngle * (-1)
        End If

        If dbArcStartX > dbArcMidX And dbArcEndY < dbUnknown4 Then
            dbArcEndAngle = dbArcEndAngle * (-1)
        End If

        If dbArcStartX = dbArcMidX And dbArcMidY > dbArStartY And dbArcEndX < dbArcStartX Then
            dbArcEndAngle = dbArcEndAngle * (-1)
        End If

        If dbArcStartX = dbArcMidX And dbArcMidY < dbArStartY And dbArcEndX > dbArcStartX Then
            dbArcEndAngle = dbArcEndAngle * (-1)
        End If
    End Sub

Open in new window

0
 

Author Comment

by:bguenther
ID: 33599132
Hi,

Well after more searching and crying below is what i found and am going to settle for, thanks for all your help.
Regards,
Ben
0
 

Accepted Solution

by:
bguenther earned 0 total points
ID: 33599139
Sorry forgot to attach code
Public Function DrawArc(ByVal StartPoint As PointF, ByVal EndPoint As PointF, ByVal Radius As Single, ByVal Clockwise As Boolean, ByRef sngStartAngle As Single, ByRef sngEndAngle As Single)
        Try
            ' Find the point that corresponds to the midpoint of the line.
            Dim pLineMidPoint As New PointF((StartPoint.X + EndPoint.X) / 2, (StartPoint.Y + EndPoint.Y) / 2)

            ' Calculate 1/2 the distance between the start and end point.
            Dim sngMidpointDistance As Single = PointDistance(StartPoint, pLineMidPoint)

            ' If 1/2 between the two points is greater than the radius, then a
            ' circular segment cannot be draw. Instead, draw a straight line
            ' between the two points.
            If sngMidpointDistance > Radius Then
                Return False
            End If

            ' Find the slope of a line drawn between the start and end point.
            Dim sngLineSlope As Single = GetSlope(StartPoint, EndPoint)
            ' Find the distance between the midpoint of the line and the midpoint
            ' of the arc.

            Dim sngDistanceToCenterPoint As Single = CSng(Math.Sqrt(Radius ^ 2 - sngMidpointDistance ^ 2))

            ' Find the mid point of the arc.
            Dim pOffset As New PointF(0, sngDistanceToCenterPoint)
            If Not Clockwise Then pOffset.Y *= -1
            Dim pArcMidpoint As PointF = OffsetPointsByAngle(pLineMidPoint, pOffset, sngLineSlope)

            ' Build a bounding box to hold the arc.
            Dim rCircle As New RectangleF(pArcMidpoint.X - Radius, (pArcMidpoint.Y - Radius), Radius * 2, Radius * 2)

            ' Find the starting angle.
            sngStartAngle = 360 - GetSlope(pArcMidpoint, StartPoint)
            ' Find the the ending angle.
            sngEndAngle = 360 - GetSlope(pArcMidpoint, EndPoint)

            If sngEndAngle < sngStartAngle Then sngEndAngle += 360
            ' Convert the ending angle to the number of degrees between the start
            ' and end angle.
            sngEndAngle = Math.Abs(sngStartAngle - sngEndAngle)
            If Not Clockwise Then sngEndAngle = sngEndAngle - 360

            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
How to Win a Jar of Candy Corn: A Scientific Approach! I love mathematics. If you love mathematics also, you may enjoy this tip on how to use math to win your own jar of candy corn and to impress your friends. As I said, I love math, but I gu…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question