# Function to plot destination XY

## Recommended Posts

Ok, I need some help finding a destination in Cartesian XY space. My math skills aren't what they used to be. This will probably be easy for someone in high school but that was many, many moons ago for me.

I need a function that, given the following parameters, will find the destination coordinates.

1. Origin as Cartesian coordinates.

2. Distance from origin in Cartesian units.

3. Direction (in degrees, 0 to 360) from origin.

For example, if I send the function an origin of (-2x, 2y) with a distance of 4 and degrees of 270, the function should return destination coords of (2x, 2y).

The function should return the destination coordinates as a two-element array.

-S

(Yet Another) ExcelCOM UDF"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly...[indent]...specialization is for insects." - R. A. Heinlein[/indent]

##### Share on other sites

Ok, I need some help finding a destination in Cartesian XY space. My math skills aren't what they used to be. This will probably be easy for someone in high school but that was many, many moons ago for me.

I need a function that, given the following parameters, will find the destination coordinates.

1. Origin as Cartesian coordinates.

2. Distance from origin in Cartesian units.

3. Direction (in degrees, 0 to 360) from origin.

For example, if I send the function an origin of (-2x, 2y) with a distance of 4 and degrees of 270, the function should return destination coords of (2x, 2y).

The function should return the destination coordinates as a two-element array.

-S

This gives the result you have described.

```;
\$AngRes = _XYDistAng(-2, 2, 4, 270)

MsgBox(0, "", " New X, Y position = " & \$AngRes[0] & ", " & \$AngRes[1])

;\$iX,\$iY - X, Y start position or origin as Cartesian coordinates.
;\$Dist   - Distance from origin in Cartesian units.
;\$Ang    - Angle (in degrees, 0 to 360) from origin.
Func _XYDistAng(\$iX, \$iY, \$Dist, \$Ang)
Local \$Ret[2]
\$Ang = \$Ang + 90 ; +90 degrees makes positive Y direction zero/360 degrees.
\$Ret[0] = Round(\$Dist * Cos(\$Ang * (4 * ATan(1)) / 180) + \$iX, 12)
\$Ret[1] = Round(\$Dist * Sin(\$Ang * (4 * ATan(1)) / 180) + \$iY, 12)
Return \$Ret
EndFunc   ;==>_XYDistAng
;```

##### Share on other sites

Most excellent! Problem solved. Thank you kindly.

-S

(Yet Another) ExcelCOM UDF"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly...[indent]...specialization is for insects." - R. A. Heinlein[/indent]

## Create an account

Register a new account