当前位置: 首页>>代码示例>>Java>>正文


Java Double2D类代码示例

本文整理汇总了Java中sim.util.Double2D的典型用法代码示例。如果您正苦于以下问题:Java Double2D类的具体用法?Java Double2D怎么用?Java Double2D使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Double2D类属于sim.util包,在下文中一共展示了Double2D类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: translateLatLonToSimCoordinates

import sim.util.Double2D; //导入依赖的package包/类
/**
 * Transforms a location (with latitude/longitude coordinates) into
 * a place on the simulation's continuous 2D space. The coordinates
 * of the simulation's space are in meters.
 *
 * @param location A Location object to be transformed into simulation
 * space.
 * @return A Double2D with simulation coordinates corresponding to the
 * given Location, or null if location is null.
 */
public Double2D translateLatLonToSimCoordinates(Location location) {
  if (location == null) {
    return null;
  }

  double simX;
  double simY;

  LatLng origin = new LatLng(LOWEST_LATITUDE, LOWEST_LONGITUDE);
  LatLng cornerA = new LatLng(LOWEST_LATITUDE, location.longitude);
  LatLng cornerB = new LatLng(location.latitude, LOWEST_LONGITUDE);

  simX = origin.distance(cornerA) * METERS_PER_KILOMETER;
  simY = height - origin.distance(cornerB) * METERS_PER_KILOMETER;

  return new Double2D(simX, simY);
}
 
开发者ID:casific,项目名称:murmur,代码行数:28,代码来源:ProximitySimulation.java

示例2: TargetAgent

import sim.util.Double2D; //导入依赖的package包/类
/**
 * Constructor
 * 
 * @param id
 * @param simulation
 */
public TargetAgent(String id, ShanksSimulation simulation) {
	super(id, simulation.getLogger());
	this.stopMovement();
	this.currentLocation = new Location();
	this.targetLocation = new Location();
	Properties props = simulation.getScenario().getProperties();
	String speedString = simulation.getScenario().getProperties().getProperty(WSNScenario.TARGET_SPEED);
	double speed = new Double(speedString);
	this.setSpeed(speed);
	String ws = props.getProperty(WSNScenario.FIELD_WIDTH);
	String hs = props.getProperty(WSNScenario.FIELD_HEIGHT);
	int w = new Integer(ws);
	int h = new Integer(hs);
	Double2D agentPos = new Double2D(simulation.random.nextInt(w), simulation.random.nextInt(h));
	this.currentLocation.setLocation2D(agentPos);
	this.targetLocation.setLocation2D(agentPos);
	ShanksAgentMovementCapability.updateLocation(simulation, this, currentLocation);
}
 
开发者ID:gsi-upm,项目名称:shanks-wsn-module,代码行数:25,代码来源:TargetAgent.java

示例3: executeReasoningCycle

import sim.util.Double2D; //导入依赖的package包/类
@Override
public void executeReasoningCycle(ShanksSimulation simulation) {
	this.getLogger()
			.finest("-> Reasoning cycle of " + this.getID() + " -> Step: " + simulation.schedule.getSteps());

	double distance2TargetLocation = this.getCurrentLocation().getLocation2D().distance(this.getTargetLocation().getLocation2D());
	if (distance2TargetLocation > this.speed) {
		// Go to target location
		this.startMovement();
		ShanksAgentMovementCapability.goTo(simulation, this, currentLocation, targetLocation, speed);
	} else {
		// Search for new target location
		this.stopMovement();			
		Properties props = simulation.getScenario().getProperties();
		String ws = props.getProperty(WSNScenario.FIELD_WIDTH);
		String hs = props.getProperty(WSNScenario.FIELD_HEIGHT);
		int w = new Integer(ws);
		int h = new Integer(hs);
		Double2D targetPos = new Double2D(simulation.random.nextInt(w), simulation.random.nextInt(h));
		this.setTargetLocation(new Location(targetPos));
		this.getLogger().finer("New target location: " + targetLocation.getLocation2D());
	}
}
 
开发者ID:gsi-upm,项目名称:shanks-wsn-module,代码行数:24,代码来源:TargetAgent.java

示例4: ZigBeeSensorNode

import sim.util.Double2D; //导入依赖的package包/类
/**
 * Constructor
 * 
 * @param id
 * @param initialState
 * @param isGateway
 * @param logger
 * @param position
 * @param battery
 * @param rnd
 */
public ZigBeeSensorNode(String id, String initialState, boolean isGateway, Logger logger, Double2D position,
		Battery battery, MersenneTwisterFast rnd) {
	super(id, initialState, isGateway, logger);
	this.rnd = rnd;
	this.setPosition(position);
	this.setZigBeeRouter(false);
	this.setDetecting(false);
	this.setBattery(battery);
	this.setCpu(new CPU());
	this.setMemory(new Memory());
	this.setTemp(35.0);
	// Sensor works perfectly, no possibility of false positive or false
	// negative.
	this.setSensorDamagedPctg(0.0);
	this.setExternalDamagedPctg(0.0);
}
 
开发者ID:gsi-upm,项目名称:shanks-wsn-module,代码行数:28,代码来源:ZigBeeSensorNode.java

示例5: moveInRange

import sim.util.Double2D; //导入依赖的package包/类
/**
 * @param node
 * @param heads
 * @param base
 * @param rangeRadioDistance
 * @throws ShanksException
 */
private void moveInRange(ZigBeeSensorNode node, List<ZigBeeSensorNode> heads, ZigBeeSensorNode base,
		int rangeRadioDistance) throws ShanksException {
	Double2D closestPos = this.getClosestNodePosition(node, heads, base);
	Double2D originalPos = node.getPosition();
	double speed = ((double) rangeRadioDistance) / 5;
	Double2D currentPos = node.getPosition();
	double distance = currentPos.distance(closestPos);

	while (distance > rangeRadioDistance) {
		Double2D direction = closestPos.subtract(currentPos);
		direction = direction.normalize();
		Double2D movement = direction.multiply(speed);
		Double2D newPos = currentPos.add(movement);
		currentPos = newPos;
		distance = currentPos.distance(closestPos);
	}
	this.getLogger().finest(
			"Sensor moved: " + node.getID() + " -> Orignal Pos: " + originalPos.toString() + " / Final Pos: "
					+ currentPos.toString() + " / Target Pos: " + closestPos.toString());
	node.setPosition(currentPos);

}
 
开发者ID:gsi-upm,项目名称:shanks-wsn-module,代码行数:30,代码来源:WSNScenario.java

示例6: build2DSpace

import sim.util.Double2D; //导入依赖的package包/类
/**
 * Create and place all users in the 2D space
 */
private void build2DSpace() {

	try {

		this.usersField2D = new Continuous2D(0.1, this.getGui()
				.getDisplay2D().getSize().getHeight(), this.getGui()
				.getDisplay2D().getSize().getWidth());
	} catch (NullPointerException e) {
		this.usersField2D = new Continuous2D(0.1,
				this.getNetworkDimension(), this.networkDimension);
	}

	this.setUsersField2D(this.usersField2D);

	for (User user : this.getUsers()) {
		this.usersField2D.setObjectLocation(user,
				new Double2D(user.getPosition()[0], user.getPosition()[1]));
	}
}
 
开发者ID:gsi-upm,项目名称:TwitterSimulator,代码行数:23,代码来源:TwitterSimulation.java

示例7: placeJammersRandomly

import sim.util.Double2D; //导入依赖的package包/类
/**
 * Place all the stationary jammers randomly in the grid.
 */
private void placeJammersRandomly() {
  //place the jammers at random in the grid
  for (int i=0; i<NUMBER_OF_STATIC_JAMMERS; i++) {
      Double2D randomLoc = new Double2D(space.getWidth() * 0.5 + random.nextInt(100) - 0.5,
                                      space.getHeight() * 0.5 + random.nextInt(100) - 0.5);
      jammerLocations.add(randomLoc);
  }
}
 
开发者ID:casific,项目名称:murmur,代码行数:12,代码来源:ProximitySimulation.java

示例8: takeRandomStep

import sim.util.Double2D; //导入依赖的package包/类
private void takeRandomStep(MessagePropagationSimulation sim) {
  Double2D me = sim.space.getObjectLocation(this);
  MutableDouble2D sumForces = new MutableDouble2D();
  sumForces.addIn(new Double2D(sim.randomMultiplier * (sim.random.nextInt(5)-2 * 1.0),
        sim.randomMultiplier * (sim.random.nextInt(5)-2 * 1.0)));

  sumForces.addIn(me);
  sim.space.setObjectLocation(this, new Double2D(sumForces));

}
 
开发者ID:casific,项目名称:murmur,代码行数:11,代码来源:Person.java

示例9: coordinateTransformTest

import sim.util.Double2D; //导入依赖的package包/类
@Test
public void coordinateTransformTest() {
  Location originLocation = 
          new Location(MessagePropagationSimulation.LOWEST_LATITUDE, 
                       MessagePropagationSimulation.LOWEST_LONGITUDE, 
                       0);
  Double2D origin = sim.translateLatLonToSimCoordinates(originLocation);
  assertEquals("Lowest lon not at x=0 meters", origin.x, 0, DELTA);
  assertEquals("Lowest lat not at y=0 meters", 
               origin.y,
               MessagePropagationSimulation.height,
               DELTA);

  Location oppositeCornerLocation = 
          new Location(MessagePropagationSimulation.HIGHEST_LATITUDE, 
                       MessagePropagationSimulation.HIGHEST_LONGITUDE, 
                       0);
  Double2D oppositeCorner =
         sim.translateLatLonToSimCoordinates(oppositeCornerLocation);
  // Margin of error of 100 meters because the tool used to calculate
  // the "correct" value only gives precision out to 100 meters.
  // (http://www.movable-type.co.uk/scripts/latlong.html)
  assertEquals("Highest lon not at correct meter location", 
               OPPOSITE_CORNER_X,
               oppositeCorner.x,
               100);
  assertEquals("Highest lat not at correct meter location", 
               OPPOSITE_CORNER_Y,
               oppositeCorner.y, 
               100);
}
 
开发者ID:casific,项目名称:murmur,代码行数:32,代码来源:MessagePropagationSimulationTest.java

示例10: countVotesForRegions

import sim.util.Double2D; //导入依赖的package包/类
/**
 * @param windowLength
 * @param step
 * @param detectingSensors
 * @param distances
 */
private void countVotesForRegions(int windowLength, long step, HashMap<Resource, Double2D> detectingSensors,
		HashMap<Resource, Double> distances) {
	long initialTimestamp = step - windowLength / 2;
	long finalTimestamp = step + windowLength / 2;
	String query = "SELECT (?x as ?msg) WHERE { ?x a b2d2-wsn:ZigBeeMessage . ?x b2d2-wsn:isDetecting true . ?x b2d2-wsn:timestamp ?tmp FILTER (?tmp >= "
			+ initialTimestamp + " && ?tmp <= " + finalTimestamp + ") }";
	Query arqQuery = ARQFactory.get().createQuery(model, query);
	QueryExecution qExe = QueryExecutionFactory.create(arqQuery, model);
	ResultSet results = qExe.execSelect();
	List<String> alreadyVoted = new ArrayList<String>();
	while (results.hasNext()) {
		QuerySolution result = results.next();
		Resource resource = result.getResource("msg");
		String sensorName = resource.getProperty(Vocabulary.isSentBy).getProperty(Vocabulary.name).getString();
		if (!alreadyVoted.contains(sensorName)) {
			alreadyVoted.add(sensorName);
			Resource auxlocation = resource.getProperty(Vocabulary.isSentBy).getProperty(Vocabulary.locatedAt)
					.getResource();
			long auxX = auxlocation.getProperty(Vocabulary.longitude).getLong();
			long auxY = auxlocation.getProperty(Vocabulary.latitude).getLong();
			Double2D auxPosition = new Double2D(auxX, auxY);
			for (Entry<Resource, Double2D> entry : detectingSensors.entrySet()) {
				double distance = auxPosition.distance(entry.getValue());
				if (distances.containsKey(entry.getKey())) {
					double previous = distances.get(entry.getKey());
					distances.put(entry.getKey(), previous + distance);
				} else {
					distances.put(entry.getKey(), distance);
				}
			}
		}
	}
}
 
开发者ID:gsi-upm,项目名称:shanks-wsn-module,代码行数:40,代码来源:ZigBeeCoordiantorNodeSoftware.java

示例11: getRequiredCurrentForEmissionToNode

import sim.util.Double2D; //导入依赖的package包/类
/**
 * @param sensor
 * @param noise
 *            in dB
 * @return in mA
 */
public double getRequiredCurrentForEmissionToNode(ZigBeeSensorNode sensor, double noise) {
	Double2D pos1 = this.getPosition();
	Double2D pos2 = sensor.getPosition();
	double distance = pos1.distance(pos2);
	double distanceKm = distance / 1000;
	double loss = 100 + (20 * Math.log10(distanceKm)); // in dB for 2,4GHz
	double sensitivy = -90; // Sensitivity in dBm
	// Emission power required to ensure the reception (in dBm)
	double emisionPower = sensitivy + loss + noise;
	double emissionConsumption = Double.MAX_VALUE;

	// Consumption criteria (in mA) - (emissionPower in dBm)
	if (emisionPower < -24) {
		emissionConsumption = 7.3;
	} else if (emisionPower < -20) {
		emissionConsumption = 8.3;
	} else if (emisionPower < -18) {
		emissionConsumption = 8.8;
	} else if (emisionPower < -13) {
		emissionConsumption = 9.8;
	} else if (emisionPower < -10) {
		emissionConsumption = 10.4;
	} else if (emisionPower < -6) {
		emissionConsumption = 11.3;
	} else if (emisionPower < -2) {
		emissionConsumption = 15.6;
	} else if (emisionPower < 0) {
		emissionConsumption = 17.0;
	} else if (emisionPower < 3) {
		emissionConsumption = 20.2;
	} else if (emisionPower < 4) {
		emissionConsumption = 22.5;
	} else if (emisionPower < 5) {
		emissionConsumption = 26.9;
	}

	return emissionConsumption;
}
 
开发者ID:gsi-upm,项目名称:shanks-wsn-module,代码行数:45,代码来源:ZigBeeSensorNode.java

示例12: getEmmitedPowerToNode

import sim.util.Double2D; //导入依赖的package包/类
/**
 * @param sensor
 * @param noise
 *            in dB
 * @return in mA
 */
public int getEmmitedPowerToNode(ZigBeeSensorNode sensor, double noise) {
	Double2D pos1 = this.getPosition();
	Double2D pos2 = sensor.getPosition();
	double distance = pos1.distance(pos2);
	double distanceKm = distance / 1000;
	double loss = 100 + (20 * Math.log10(distanceKm)); // in dB for 2,4GHz
	double sensitivy = -90; // Sensitivity in dBm
	// Emission power required to ensure the reception (in dBm)
	double emisionPower = sensitivy + loss + noise;
	int emittedPower = Integer.MAX_VALUE;

	// Consumption criteria (in mA) - (emissionPower in dBm)
	if (emisionPower < -24) {
		emittedPower = -24;
	} else if (emisionPower < -20) {
		emittedPower = -20;
	} else if (emisionPower < -18) {
		emittedPower = -18;
	} else if (emisionPower < -13) {
		emittedPower = -13;
	} else if (emisionPower < -10) {
		emittedPower = -10;
	} else if (emisionPower < -6) {
		emittedPower = -6;
	} else if (emisionPower < -2) {
		emittedPower = -2;
	} else if (emisionPower < 0) {
		emittedPower = 0;
	} else if (emisionPower < 3) {
		emittedPower = 3;
	} else if (emisionPower < 4) {
		emittedPower = 4;
	} else if (emisionPower < 5) {
		emittedPower = 5;
	}

	return emittedPower;
}
 
开发者ID:gsi-upm,项目名称:shanks-wsn-module,代码行数:45,代码来源:ZigBeeSensorNode.java

示例13: destinyAchieved

import sim.util.Double2D; //导入依赖的package包/类
/**
 * Comprueba si se ha llegado al destino.
 *  Ver isFinished
 * @param simState
 * @return
 */
private boolean destinyAchieved(SimState simState){
    MutableInt2D m= personImplementingAutomaton.getPosition();
    if(m.distance(new Double2D(x,y)) <= minDistance) 
    	return true;
    else if(numOfTries == 0) {
            LOG.info(name + "Destiny is not achieved, but the number of tries has been exeeded");
    	return true;
    }
    return false;
}
 
开发者ID:emilioserra,项目名称:UbikSim,代码行数:17,代码来源:SimpleMove.java

示例14: mediatriz

import sim.util.Double2D; //导入依赖的package包/类
public Int2D mediatriz(Int2D p1, Int2D p2, Int2D q1, Int2D q2) {
    Int2D result = null;
    double t = 0;
    double s = 0;

    double vx = p2.y - p1.y;
    double vy = p2.x - p1.x;
    double wx = q2.y - q1.y;
    double wy = q2.x - q1.x;

    // Si los segmentos son paralelos devuelve null
    if (Math.round(vx / wx) == Math.round(vy / wy)) {
        return null;
    }

    Double2D p1m = puntoMedio(new Double2D(p1.x, p1.y), new Double2D(p2.x, p2.y));

    Double2D p2m = puntoMedio(new Double2D(q1.x, q1.y), new Double2D(q2.x, q2.y));

    s = (vx * (p2m.y - p1m.y) - p2m.x + p1m.x) / (wx - wy * vx);

    double x2 = p2m.x + s * wx;
    double y2 = p2m.y + s * wy;

    t = (p2m.x + s * wx - p1m.x) / vx;

    double x1 = p1m.x + t * vx;
    double y1 = p1m.y + t * vy;

    return new Int2D((int) Math.round(x2), (int) Math.round(y2));
}
 
开发者ID:emilioserra,项目名称:UbikSim,代码行数:32,代码来源:SpaceArea.java

示例15: mediatriz

import sim.util.Double2D; //导入依赖的package包/类
public Int2D mediatriz(Int2D p1, Int2D p2, Int2D q1, Int2D q2) {
    double t = 0;
    double s = 0;

    double vx = p2.y - p1.y;
    double vy = p2.x - p1.x;
    double wx = q2.y - q1.y;
    double wy = q2.x - q1.x;

    // Si los segmentos son paralelos devuelve null
    if (Math.round(vx / wx) == Math.round(vy / wy)) {
        return null;
    }

    Double2D p1m = puntoMedio(new Double2D(p1.x, p1.y), new Double2D(p2.x, p2.y));

    Double2D p2m = puntoMedio(new Double2D(q1.x, q1.y), new Double2D(q2.x, q2.y));

    s = (vx * (p2m.y - p1m.y) - p2m.x + p1m.x) / (wx - wy * vx);

    double x2 = p2m.x + s * wx;
    double y2 = p2m.y + s * wy;

    t = (p2m.x + s * wx - p1m.x) / vx;

    double x1 = p1m.x + t * vx;
    double y1 = p1m.y + t * vy;

    return new Int2D((int) Math.round(x2), (int) Math.round(y2));
}
 
开发者ID:emilioserra,项目名称:UbikSim,代码行数:31,代码来源:Furniture.java


注:本文中的sim.util.Double2D类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。