• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Double2D类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: goTo

import sim.util.Double2D; //导入依赖的package包/类
/**
 * Move the agent to the target location with the specific speed. Call this
 * method always you want to move. This method only moves the agent a
 * fragment equals to the velocity.
 * 
 * @param simulation
 * @param agent
 * @param currentLocation
 * @param targetLocation
 * @param speed
 */
private static void goTo(ShanksSimulation simulation,
        MobileShanksAgent agent, Double2D currentLocation,
        Double2D targetLocation, double speed) {
    if (!targetLocation.equals(currentLocation) && agent.isAllowedToMove()) {
        Double2D direction = targetLocation.subtract(currentLocation);
        direction = direction.normalize();
        Double2D movement = direction.multiply(speed);
        ShanksAgentMovementCapability.updateLocation(simulation, agent,
                currentLocation.add(movement));
    }
}
 
开发者ID:gsi-upm,项目名称:Shanks,代码行数:23,代码来源:ShanksAgentMovementCapability.java


示例17: Location

import sim.util.Double2D; //导入依赖的package包/类
/**
 * Create a 2D location
 * 
 * @param location
 */
public Location(Double2D location) {
    this.setLocation2D(location);
    this.is2D = true;
    this.location3D = null;
    this.is3D = false;
}
 
开发者ID:gsi-upm,项目名称:Shanks,代码行数:12,代码来源:Location.java


示例18: getLocation2D

import sim.util.Double2D; //导入依赖的package包/类
/**
 * @return the location2D
 */
public Double2D getLocation2D() {
    if (this.is2DLocation()) {
        return location2D;   
    } else {
        return null;
    }
}
 
开发者ID:gsi-upm,项目名称:Shanks,代码行数:11,代码来源:Location.java


示例19: isNearTo

import sim.util.Double2D; //导入依赖的package包/类
/**
 * Compare two locations and return if the locations are near or not
 * 
 * @param location Location to compare with
 * @param distance The distance between two locations
 * @return true is the real distance is lower or equals than the distance parameter
 */
public boolean isNearTo(Double2D location, double distance) {
    if (this.is2DLocation()) {
        return this.getLocation2D().distance(location) < distance;
    } else {
        return false;
    }
}
 
开发者ID:gsi-upm,项目名称:Shanks,代码行数:15,代码来源:Location.java


示例20: rotate

import sim.util.Double2D; //导入依赖的package包/类
/**
 * @param orig
 * @param alpha is the angle in the plane XY
 * @param beta is the angle in the plane XZ
 * @param gamma is the angle in the plane YZ
 * @return Double3D object
 */
public static Double3D rotate(Double3D orig, Double alpha, Double beta, Double gamma) {
    Double2D origXY = new Double2D(orig.x, orig.y);
    Double2D firstRotated = ShanksMath.rotate(origXY, alpha);
    Double2D firstRotatedXorigZ = new Double2D(firstRotated.x, orig.z);
    Double2D secondRotated = ShanksMath.rotate(firstRotatedXorigZ,
            beta);
    Double2D firstRotatedYsecondRotatedZ = new Double2D(firstRotated.y, secondRotated.y);
    Double2D thirdRotated = ShanksMath.rotate(firstRotatedYsecondRotatedZ, gamma);
    return new Double3D(secondRotated.x, thirdRotated.x, thirdRotated.y);
}
 
开发者ID:gsi-upm,项目名称:Shanks,代码行数:18,代码来源:ShanksMath.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java EMessage类代码示例发布时间:2022-05-22
下一篇:
Java RowSwapProcessorResponse类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap