Jump to content

Drawing Lines From a Point in 360 Degrees

prolemur

I want to be able to cast a ray from a point in whatever direction I want.

 

How would I go about this using (x,y) as the position of the point and an angle variable?

I feel like it is something from my functions class when we touched on circles and radian...

 

This is my ghetto solution so far, but it relies on using the edges of the screen and separating the draw line method into 4 parts; one for each side of the screen.

 

circle.png

@bobhays Also you can kind of see what I'm going for as the program I linked does work, but the code for it is definitely not proper.

Link to comment
Share on other sites

Link to post
Share on other sites

could you upload a picture of what you are talking about? I would like to help but have no idea what you mean

 

EDIT: @prolemur, i'm on a school computer so I can't run the program right now but if you're trying to do what I think you're trying to do,

 

lets call point 1 (x,y) or the origin of the ray.

 

I'm just going to replace theta with the @ sign, so @ is the variable.

 

( cos(@) * r ) + x = x.1

 

( sin(@) * r ) + y = y.1

 

x.1 and y.1 are the new endpoints so the ray would go from (x,y) to (x.1, y.1)

 

If you plot every value from 0-360 it should make a full circle.

Link to comment
Share on other sites

Link to post
Share on other sites

could you upload a picture of what you are talking about? I would like to help but have no idea what you mean

 

EDIT: @prolemur, i'm on a school computer so I can't run the program right now but if you're trying to do what I think you're trying to do,

 

lets call point 1 (x,y) or the origin of the ray.

 

I'm just going to replace theta with the @ sign, so @ is the variable.

 

( cos(@) * r ) + x = x.1

 

( sin(@) * r ) + y = y.1

 

x.1 and y.1 are the new endpoints so the ray would go from (x,y) to (x.1, y.1)

 

If you plot every value from 0-360 it should make a full circle.

Thanks that worked for what I was trying to accomplish :D

 

Now I need to do some collision on that line instead of giving it an random radius. It needs to check if the line goes through a space where there is a wall every intersection on a 1x1 square grid.

 

Actually now I am trying to make the player follow the line that it is displaying. I tried using the same sin and cos functions but they only kind of worked.

Rounding made it change a bit so now all my variables are decimals.

Link to comment
Share on other sites

Link to post
Share on other sites

Thanks that worked for what I was trying to accomplish :D

 

Now I need to do some collision on that line instead of giving it an random radius. It needs to check if the line goes through a space where there is a wall every intersection on a 1x1 square grid.

 

Actually now I am trying to make the player follow the line that it is displaying. I tried using the same sin and cos functions but they only kind of worked.

Rounding made it change a bit so now all my variables are decimals.

Sorry not quite sure what you mean, if there is a specific thing you want help on let me know and i'll see what I can do

Link to comment
Share on other sites

Link to post
Share on other sites

Sorry not quite sure what you mean, if there is a specific thing you want help on let me know and i'll see what I can do

Thanks I got it though :)

if control (KEY_UP_ARROW) then    x -= x - (cos (angle) * speed + x)    y -= y - (sin (angle) * speed + y)elsif control (KEY_DOWN_ARROW) then    x += x - (cos (angle) * speed + x)    y += y - (sin (angle) * speed + y)end if
Link to comment
Share on other sites

Link to post
Share on other sites

 

Thanks I got it though :)

if control (KEY_UP_ARROW) then    x -= x - (cos (angle) * speed + x)    y -= y - (sin (angle) * speed + y)elsif control (KEY_DOWN_ARROW) then    x += x - (cos (angle) * speed + x)    y += y - (sin (angle) * speed + y)end if

ok cool

Link to comment
Share on other sites

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

×