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


Java Vector2d.length方法代码示例

本文整理汇总了Java中javax.vecmath.Vector2d.length方法的典型用法代码示例。如果您正苦于以下问题:Java Vector2d.length方法的具体用法?Java Vector2d.length怎么用?Java Vector2d.length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.vecmath.Vector2d的用法示例。


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

示例1: adjacentDist

import javax.vecmath.Vector2d; //导入方法依赖的package包/类
public double adjacentDist(Line l, Point2d pt) {

		Vector2d v1 = new Vector2d(l.end);
		v1.sub(l.start);
		Vector2d v2 = new Vector2d(pt);
		v2.sub(l.start);
		double param = v2.dot(v1) / v1.length();

		if ( param < 0 || param > v1.length() )
			return Double.MAX_VALUE;
		
		v1.normalize();
		v1.scale( param );
		v1.add( l.start );
		
		return new Point2d (v1).distance(pt);
	}
 
开发者ID:twak,项目名称:chordatlas,代码行数:18,代码来源:FacadeFinder.java

示例2: project

import javax.vecmath.Vector2d; //导入方法依赖的package包/类
public static Point2d project(Line l, Point2d pt) {
	
	Vector2d v1 = new Vector2d(l.end);
	v1.sub(l.start);
	Vector2d v2 = new Vector2d(pt);
	v2.sub(l.start);
	double param = v2.dot(v1) / v1.length();

	if (param < 0 || param > v1.length())
		return null;

	v1.normalize();
	v1.scale(param);
	v1.add(l.start);

	return new Point2d(v1);
}
 
开发者ID:twak,项目名称:chordatlas,代码行数:18,代码来源:Concarnie.java

示例3: generateVoronoi

import javax.vecmath.Vector2d; //导入方法依赖的package包/类
private void generateVoronoi() {
		Random rand = new Random();
		Voronoi voronoi = new Voronoi();
		Set<Vector2d> pointSet = new HashSet<>();
		for (int i=0; i<n; ++i) {
			float x = (rand.nextFloat() * w * scale);
			float y = (rand.nextFloat() * h * scale);
			pointSet.add(new Vector2d(x, y));
		}
		points = new ArrayList<>(n);
		points.addAll(pointSet);
		
		long time1 = System.currentTimeMillis();
		edges = voronoi.getEdges(points, w*scale, h*scale);
		edges = Voronoi.closeEdges(edges, w*scale, h*scale);
		//relax n times
		int m = 1;
		for (int i=0; i<m; ++i) {
			points = VoronoiUtils.generateRelaxedSites(points, edges);
			edges = voronoi.getEdges(points, w*scale, h*scale);
			edges = Voronoi.closeEdges(edges, w*scale, h*scale);
		}
		long time2 = System.currentTimeMillis();
		
		for (Iterator<Edge> it = edges.iterator(); it.hasNext(); ) {
			Edge e = it.next();
			Vector2d v = new Vector2d(e.getStart().x - e.getEnd().x, e.getEnd().y - e.getEnd().y);
			if (v.length() > 0.05 * w * scale) {
				System.out.println("long edge: "+e);
//				it.remove();
			}
		}
		
		System.out.println("edges: ("+edges.size()+")");
//		for (Edge e : edges) {
//			System.out.println(" "+e.start+" -- "+e.end);
//		}
		System.out.println("time to compute: "+(time2-time1)+" msec");
		panel.repaint();
	}
 
开发者ID:shamanDevel,项目名称:ProceduralTerrain,代码行数:41,代码来源:DisplayVoronoiDiagram.java

示例4: drawAimAPI

import javax.vecmath.Vector2d; //导入方法依赖的package包/类
public void drawAimAPI(Graphics2D g, int playerIndex, int distance) {
    if(getGameCanvas().requestedAimAPI() && playerIndex >= 0 && playerIndex < Team.MAX_TEAM_SIZE && distance > 0) {
        Team aimingTeam = isLeft() ? getClient().getMatch().getTeam(0) : getClient().getMatch().getTeam(1);

        if(aimingTeam != null) {
            Player aimingPlayer = aimingTeam.getPlayers().get(playerIndex);

            if(aimingPlayer != null) {
                Vector2d aimingPlayerPos = (Vector2d) aimingPlayer.getPos().clone();

                if(aimingPlayerPos != null) {
                    Vector2d dist = new Vector2d(getGameCanvas().getPitchMouseLogic().getMXY()[0], getGameCanvas().getPitchMouseLogic().getMXY()[1]);
                    dist.sub(aimingPlayerPos);

                    if(dist.length() <= distance) {
                        Color paint = SBColor.YELLOW;
                        if(aimingFieldDistanceClass == 1) paint = SBColor.ORANGE_BRIGHT;
                        if(aimingFieldDistanceClass == 2) paint = SBColor.ORANGE_DARK;
                        if(aimingFieldDistanceClass == 3) paint = SBColor.RED;
                        drawCurveToMouse(g, aimingPlayerPos, paint);

                        paint = SBColor.YELLOW_80;
                        if(aimingFieldDistanceClass == 1) paint = SBColor.ORANGE_BRIGHT_80;
                        if(aimingFieldDistanceClass == 2) paint = SBColor.ORANGE_DARK_80;
                        if(aimingFieldDistanceClass == 3) paint = SBColor.RED_80;
                        if(getGameCanvas().getPitchMouseLogic() != null)
                            if(getGameCanvas().getPitchMouseLogic().getFieldAimingAt() != null)
                                highlightField(g, getGameCanvas().getPitchMouseLogic().getFieldAimingAt().getPos().x, getGameCanvas().getPitchMouseLogic().getFieldAimingAt().getPos().y, paint);
                    }
                }
            }
        }

    }
}
 
开发者ID:milanvanzanten,项目名称:SafariBowl,代码行数:36,代码来源:GameRenderer.java

示例5: getNearestPoint

import javax.vecmath.Vector2d; //导入方法依赖的package包/类
public static Vector2d getNearestPoint(Vector2d start, Vector2d end, Vector2d pointP, boolean justAbscissa) {

        //Now we need an equation for the line on which the points start and end lie.
        double a;
        double b;
        double c;
        Vector2d abscissa = new Vector2d(end.x - start.x, end.y - start.y);
        //Coefficients in the equation are normal vector of tmp.
        a = abscissa.y;
        b = -abscissa.x;
        //start point lies on the line, therefore we can use it to get c.
        c = -a * start.x - b * start.y;

        //Special cases solving.
        if (a == 0) {
            a = 0.001; //In case something messes up and a ends up being zero, we need to fix it, otherwise we'd divide by zero later.
        }
        if (a * a + b * b == 0) {
            a = a + 0.001; //Similar for a^2+b^2==0
        }

        //Coefficients of the equation for the line perpendicular to our line are -b, a, d; d will be counted. PointHeading lies on it, therefore we use its coordinates.
        double d = b * pointP.x - a * pointP.y;

        //Now we have to get the intersection of linex ax+by+c=0 and -bx+ ay+d=0, the foot point.
        //This is a general solution of system of equations consisting of ax+by+c=0 and -bx+ay+d=0.
        //We could use some Gaussian solver as well, but since we don't need to solve general systems of equations, this should be faster.
        double footXCor = (b * ((a * d + b * c) / (a * a + b * b)) - c) / a;
        double footYCor = (-a * d - b * c) / (a * a + b * b);

        /** The nearest point on the line to the pointP.*/
        Vector2d foot = new Vector2d(footXCor, footYCor);

        /*The point in the middle of the abscissa.*/
        Vector2d middlePoint = new Vector2d((start.x + end.x) / 2,(start.y + end.y) / 2);

        Vector2d footToMiddlePoint = new Vector2d(foot.x - middlePoint.x, foot.y - middlePoint.y);

        /** The nearest point of the abscissa to the pointP.*/
        Vector2d nearestPoint = new Vector2d(foot.x, foot.y);

        if (justAbscissa) {
            /* The foot point doesn't lie between start and end. Therefore we will choose start or end point - that which is nearer to the pointP.*/
            if (footToMiddlePoint.length() > abscissa.length()) {
                Vector2d startToPointP = new Vector2d(start.x - pointP.x,start.y - pointP.y);
                Vector2d endToPointP = new Vector2d(end.x - pointP.x,end.y - pointP.y);
                if (startToPointP.length() < endToPointP.length()) {
                    nearestPoint = start;
                } else {
                    nearestPoint = end;
                }
            }
        }
        return nearestPoint;
    }
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:56,代码来源:SteeringTools.java

示例6: calculateOnPitch

import javax.vecmath.Vector2d; //导入方法依赖的package包/类
void calculateOnPitch(MouseEvent e) {
    if (!isMovingPlayer()) { // is not moving player
        setMXY(e);
    } else { // is moving player
        // some magic numbers
        double  x0 = mX * getpW() + getpW() / 2, y0 = mY * getpH() + getpH() / 2,
                a = 7*getpW()/8;
        Vector2d mouse = getGameCanvas().getGameRenderer().dispToPos(new Vector2d(e.getX(), e.getY()));
        double dx = mouse.x - x0, dy = mouse.y - y0;
        if ((dx < -a || dx > a) || (dy < -a || dy > a)) { // moved outside of action zone (ask milan what the heck that means)
            setMXY(e);
        }
    }

    if(mX >= 0 && mX < Pitch.PITCH_LENGTH && mY >= 0 && mY < Pitch.PITCH_WIDTH) {

        if (getPitch() != null && (mX != mXOld || mY != mYOld)) { // mouse is on different field and pitch exists
            if (isAiming()) { // is aiming...
                Vector2d dist = (Vector2d) getAimingPlayer().getPos().clone();
                if (!dist.equals(getPitch().getFields()[mX][mY].getPos())) { // ... but not on itself
                    dist.sub(new Vector2d(mX, mY));
                    if (dist.length() <= RuleThrow.LONG_BOMB) // distance is shorter than max
                        setFieldAimingAt(getPitch().getFields()[mX][mY]);
                } else { // ... but on itself
                    resetAimingPlayer();
                }
            } else { // is not aiming
                if (getPitch().getFields()[mX][mY].getPlayer() != null) { // there is a player on the hovered field
                    setHoveringPlayer(getPitch().getFields()[mX][mY].getPlayer());
                } else {
                    resetHoveringPlayer();
                }

                if (isMovingPlayer()) { // player was moved one field
                    if (!isHoveringPlayer() || getHoveringPlayer().equals(getMovingPlayer())) { // next field is empty or moved player stands on this field
                        if (getDrawingPath().getPath().get(getDrawingPath().getPath().size() - 1).getPos().equals(new Vector2d(mX, mY))) { // hovering last drawn field
                            resetFieldBlitzing();
                        }
                        if (getDrawingPath().getPath().size() > 1) { // path is longer than one field
                            if (getDrawingPath().getPath().get(getDrawingPath().getPath().size() - 2).getPos().equals(new Vector2d(mX, mY))) { // moved one field back
                                removeLastPathElement();
                            } else {
                                addPathElement();
                            }
                        } else if (getDrawingPath().getPath().size() == 1) {
                            addPathElement();
                        }
                    } else { // there is already a player on this field
                        PitchField potentialBlitzField = getPitch().getFields()[mX][mY];
                        if (!isHoveringOwnPlayer() && potentialBlitzField != null) // cannot blitz own player
                            if (getMovingPlayer().invokeGetRemainingBe() >= getDrawingPath().getPath().size() // if player has another move..
                                    && getMovingPlayer().getTeam().getBlitz() // .. and team can still blitz, or ..
                                    || getDrawingPath().getPath().size() <= 1 // .. player is blocking ..
                                    && getMovingPlayer().invokeGetRemainingBe() == getMovingPlayer().invokeGetBe()) // .. and has not moved yet
                                if (getPitch().isAdjacent(potentialBlitzField, getDrawingPath().getPath().get(getDrawingPath().getPath().size() - 1)))
                                    setFieldBlitzing(potentialBlitzField);
                    }
                }

            }
        }

    } else {
        resetAimingPlayer();
    }

    if(mYCoord >= getPitchHeight()) {
        resetHoveringPlayer();
        resetMovingPlayer();
        resetAimingPlayer();
    }
}
 
开发者ID:milanvanzanten,项目名称:SafariBowl,代码行数:73,代码来源:PitchMouseLogic.java

示例7: getDistanceTo

import javax.vecmath.Vector2d; //导入方法依赖的package包/类
/**
 * Euklidischer Abstand von this zu p2
 *
 * @param p2
 * @return Euklidischer Abstand von this zu p2
 */
double getDistanceTo(TurningPoint p2) {
	Vector2d h = new Vector2d(p2.pos);
	h.sub(this.pos);
	return h.length();
}
 
开发者ID:tsandmann,项目名称:ct-sim,代码行数:12,代码来源:TurningPoint.java


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