1 Replies - 2714 Views - Last Post: 05 October 2010 - 04:25 PM Rate Topic: -----

#1 Cooke3   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 24-January 10

How to make radial lines come out of one point?

Posted 05 October 2010 - 04:07 PM

I am doing a project for school and one part of it needs to made n radial lines (each line is at an angular increment of 2(pi)/n) come out of a point. Eventually the program will have the robot (the point where the lines are coming from) within some polygon (the room) with the radial lines coming out of it and stopping at the edges of the polygon.

So far I'm stuck on how to make the lines, I'm not sure how to do that, other than I would need a for loop.

This is my code so far

import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class Robot extends Frame
{	public static void main(String[] args){new Robot();}

    Robot()
	{	super("Robot Range Map");
		addWindowListener(new WindowAdapter()
			{public void windowClosing(WindowEvent e){System.exit(0);}});
		setSize(600,600);
		add(new RobotCalc());
		show();
	}
}

class RobotCalc extends Canvas
{	Point pos; //position of robot
	float head;  //heading direction
	int n; // number of sensors
	float rad; //radius of circle
	float angle; //angle (2(pi))/n

	int iX(float x){return Math.round(x);}

	RobotCalc()
	{	/*rad = 5.9;
		pos.x = 350;
		pos.y = 222;*/  // test points
	}

	public void paint (Graphics g)
	{	//n = 30; //set direction of robot

		//room map, polygon
		Polygon room = new Polygon();
		room.addPoint(100,100);
		room.addPoint(500,100);
		room.addPoint(500,500);
		room.addPoint(100,500);
		g.drawPolygon(room);


		//draw the robot, circle with line indicating direction
		g.drawOval (iX(pos.x-rad),iX(pos.y-rad),iX(2*rad),iX(2*rad));

		//drawing n radial lines from robot
		for (i=1; i<=n; i++)
		{

			g.drawLine(pos.x,pos.y,)
		}

	}
}


Is This A Good Question/Topic? 0
  • +

Replies To: How to make radial lines come out of one point?

#2 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12305
  • View blog
  • Posts: 45,401
  • Joined: 27-December 08

Re: How to make radial lines come out of one point?

Posted 05 October 2010 - 04:25 PM

Take a look at the Graphics drawLine() method to handle drawing your lines to the screen. Also, perhaps you may want to look at Polar Coordinates for correct placement of your lines. It is basically an expansion of the Unit Circle, so you'll need some basic Trig as well. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1