Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / A function request...

Author
Message
TheCyborg
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Denmark
Posted: 10th Feb 2003 14:03
I don't know if this should have been in the snippets section...

It's very hard to explain, but i need a function to return a x,y coordinate on a circle...

The syntax should be something like this:
Return String=GetOrbitCoord(XPos,YPos,Angle,Distance)

"Return String" should be something like "245,145" (x,y coordinate).

"XPos" & "YPos" is the center of the circle.

"Angle" is the angle of the circle from straight up. 0 will be straight up. 90 would be straight right (or left).

"Distance" is the distance from the specified X/YPos in the specified angle.


The whole idea with this is that i want an object to go around in a circle without turning around.

Hope someone understands what i need and that He/She is able to do this for me.
Thanks in advance.
TheCyborg Development.
http://TheCyborg.Amok.dk
The Ultimate Source To DarkBASIC Programming.
MrTAToad
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 10th Feb 2003 14:32
Do I think you want a function to return the X & Y positions around a circle of a given size ?

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
Beta1
22
Years of Service
User Offline
Joined: 28th Dec 2002
Location:
Posted: 10th Feb 2003 15:22
I cant test.write one 'cos I'm at work but its simple trig.

If A,B is the centre of the circle (x,y coordinates), radius of circle is R and theta is the angle round the circle in a clockwise direction from the y axis then the x and y coordinates on the circle perimeter you want are A+R*SIN(theta)=x and B+R*COS(theta)=y.

That should work OK but like I said thats thinking on the fly at work, I'm not sure whether this would work beyond 90degrees without testing it - you might need a wrapvalue or something

TheCyborg
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Denmark
Posted: 10th Feb 2003 15:22
Yes yes. It's just what i want.
A function to return the X & Y positions around a circle of a given size at a give position in a given angle...
The return string should be the X position and Y position seperated with a comma. I know how to extract each other.

TheCyborg Development.
http://TheCyborg.Amok.dk
The Ultimate Source To DarkBASIC Programming.
TheCyborg
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Denmark
Posted: 10th Feb 2003 15:30
Thanks Beta1. Hehe posted in the same minute...

You are saying that all i need is:



TheCyborg Development.
http://TheCyborg.Amok.dk
The Ultimate Source To DarkBASIC Programming.
TheCyborg
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Denmark
Posted: 10th Feb 2003 15:33
I have not tested it yet because i'm at work to..

TheCyborg Development.
http://TheCyborg.Amok.dk
The Ultimate Source To DarkBASIC Programming.
Beta1
22
Years of Service
User Offline
Joined: 28th Dec 2002
Location:
Posted: 10th Feb 2003 15:50
I think so - you might want to put some brackets round the distance*SIN() and the same for the COS.

I would probably make 2 functions, one x, one y but if you want to do the string output thing why not.

I'm just not 100% sure the it will work past 90 degrees - cos sin(100) is the same as sin(80) so it might end up osscilating backwards and forwards between 0 and 90 degrees, if so you'll need to check whether theta is more than 90 and if so subtract the distance*cos(theta) from B, maybe the same with other axis.

ZomBfied
22
Years of Service
User Offline
Joined: 2nd Oct 2002
Location:
Posted: 11th Feb 2003 23:04


TheCyborg
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Denmark
Posted: 12th Feb 2003 15:43
It did work.. however it returned a wrong y coordinate.

It should be:
Y=YPos-Distance*COS(Wrapvalue(Angle))

instead of:
Y=YPos+Distance*COS(Wrapvalue(Angle))

It worked exactly as i wanted. Thanks again...

TheCyborg Development.
http://TheCyborg.Amok.dk
The Ultimate Source To DarkBASIC Programming.
ZomBfied
22
Years of Service
User Offline
Joined: 2nd Oct 2002
Location:
Posted: 12th Feb 2003 18:17
Oh yeah I forgot one of them should be minus. Yay.

ZomBfied
22
Years of Service
User Offline
Joined: 2nd Oct 2002
Location:
Posted: 12th Feb 2003 18:18
Just curious but why do you want it in a return string? It seems like it would be faster to have it as 2 functions that just return numbers.

Login to post a reply

Server time is: 2025-05-18 20:38:39
Your offset time is: 2025-05-18 20:38:39