Jump to content
Sign in to follow this  
Locodarwin

Function to plot destination XY

Recommended Posts

Locodarwin

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.

Thanks in advance.

-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 this post


Link to post
Share on other sites
Malkey

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.

Thanks in advance.

-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 this post


Link to post
Share on other sites
Locodarwin

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]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×