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


Java Vector2d.normalize方法代码示例

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


在下文中一共展示了Vector2d.normalize方法的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: haveSameDirection

import javax.vecmath.Vector2d; //导入方法依赖的package包/类
/**Gets the intersection of the half-lines A and B (line has the start point and its direction.
 * If there isn't the intersection of the half-lines, or the direction is the same, we return null.*/
public static boolean haveSameDirection(Vector2d sA, Vector2d dA, Vector2d sB, Vector2d dB) {        
    dA.normalize();
    dB.normalize();
    if (dA.equals(dB)) {
        return true;
    } else {
        return false;
    }
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:12,代码来源:SteeringTools.java

示例4: extrude

import javax.vecmath.Vector2d; //导入方法依赖的package包/类
public static void extrude( ObjDump out, LoopL<Point2d> slice, double h1, double h2 ) {
		 
		for (Loop<Point2d> loop : slice) {

			for (Loopable<Point2d> pt : loop.loopableIterator()) {
				
				List<double[]> pts = new ArrayList<>(),
						norms = new ArrayList<>();
				
				Point2d a = pt.get(), b = pt.getNext().get();

				pts.add( new double[] { a.x, h1, a.y} );
				pts.add( new double[] { b.x, h1, b.y} );
				pts.add( new double[] { b.x, h2, b.y} );
				pts.add( new double[] { a.x, h2, a.y} );
				
				Vector2d d = new Vector2d( b);
				d.sub(a);
				d.normalize();
				
				double[] norm = new double[] {-d.y, 0, d.x};
//				double[] norm = new double[] {d.y, 0, -d.x};
				
				for (int i = 0; i < 4; i++)
					norms.add(norm);
				
				out.addFace(pts.toArray( new double[pts.size()][] ), null, norms.toArray( new double[norms.size()][] ));
			}
		}
	}
 
开发者ID:twak,项目名称:chordatlas,代码行数:31,代码来源:Slice.java

示例5: createDormerWindowsFor

import javax.vecmath.Vector2d; //导入方法依赖的package包/类
public void createDormerWindowsFor(Bar b, double desiredSpacing )
{
    b.mould.clear();
    
    double length = b.length();
    int count = (int)(length /desiredSpacing);
    double delta = length / (count+1.);
    Vector2d v = new Vector2d (b.end);
    v.sub(b.start);
    v.normalize();
    v.scale(delta);
    
    for (int i = 1; i <= count; i++)
    {
        Vector2d loc = new Vector2d (v);
        loc.scale(i);
        loc.add(b.start);
        Marker m = new Marker();
        m.set(loc);
        m.bar = b;
        
        b.mould.create(m, null);

        Marker profM =  profileMarkers.get( profiles.get(b));


        if (profM != null) {
            Ship.Instance instance = ns.newInstance();
            instance.anchors = new Anchor[]{new Anchor(m.generator, profM.generator)};
        }
    }
}
 
开发者ID:twak,项目名称:siteplan,代码行数:33,代码来源:OverhangPlan.java

示例6: returnLineTo

import javax.vecmath.Vector2d; //导入方法依赖的package包/类
/**
 * gibt einen Polygonzug der mit Breite und einer Spitze versehen Linie von
 * this zu p2 zurueck, zur Weiterverwendung in createLine()
 *
 * @param p2
 * @return {x1,y1,z1,x2,y2,z2,...,x6,y6,z6}
 */
float[] returnLineTo(TurningPoint p2) {
	Vector2d offset = new Vector2d(0.5, 0.5);
	Vector2d length = new Vector2d(p2.pos);
	length.sub(this.pos);
	Vector2d halfWidth = new Vector2d(-length.y, length.x);
	halfWidth.normalize();
	halfWidth.scale(lineWidth / 2);
	Vector2d corner = new Vector2d(this.pos);
	// corner.add(new Vector2d(0.5,0.5));
	corner.sub(halfWidth);
	corner.sub(offset);
	float[] polygon = new float[18];
	polygon[0] = (float) corner.x;
	polygon[1] = (float) corner.y;
	polygon[2] = height;
	corner.add(length);
	polygon[3] = (float) corner.x;
	polygon[4] = (float) corner.y;
	polygon[5] = height;
	corner.add(halfWidth);
	corner.add(halfWidth);
	polygon[6] = (float) corner.x;
	polygon[7] = (float) corner.y;
	polygon[8] = height;
	corner.sub(length);
	polygon[9] = (float) corner.x;
	polygon[10] = (float) corner.y;
	polygon[11] = height;
	corner.sub(halfWidth);
	Vector2d head = new Vector2d(length);
	head.normalize();
	head.scale(-lineWidth / 2);
	corner.add(head);
	polygon[12] = (float) corner.x;
	polygon[13] = (float) corner.y;
	polygon[14] = height;
	corner.sub(halfWidth);
	corner.sub(head);
	polygon[15] = (float) corner.x;
	polygon[16] = (float) corner.y;
	polygon[17] = height;
	return polygon;
}
 
开发者ID:tsandmann,项目名称:ct-sim,代码行数:51,代码来源:TurningPoint.java

示例7: setPlan

import javax.vecmath.Vector2d; //导入方法依赖的package包/类
private void setPlan(Marker planC, double distance, Marker planM) {
            
            // we always trail by 1 frame, but this can't really be helped.
            Bar bar = planC.bar;
//            Loop<Bar> loop = null;
//            Loopable<Bar> able = null;

            LoopLoopable<Bar>
                cAble = Siteplan.instance.plan.points.find( bar ),
                mAble = Siteplan.instance.plan.points.find( planM.bar );

            if ( cAble == null || mAble == null )
                return; // didn't find marker on main plan. give up.

            // remove plan marker from old location
            Object generator = planM.bar.mould.remove( planM );
            
            // anchors may have re-genereated. grab the most recent location
            planC = refresh (planC, cAble );
//            planM = refresh (planM, mAble);

//            Object generator = mAble.loopable.get().mould.remove( planM );

            // move plan marker - find correct bar by subtracting from desired distance

            double leftInBar;

            Loopable<Bar> able = cAble.loopable;

            if ( distance > 0 )
            {
                leftInBar = planC.distance( able.get().end );

                do
                    if ( leftInBar > distance )
                    {
                        leftInBar -= distance;
                        break;
                    }
                    else
                    {
                        distance -= leftInBar;
                        able = able.getNext();
                        leftInBar = able.get().length();
                    }
                while ( true );
            }
            else
            {
                distance = -distance;
                leftInBar = planC.distance( able.get().start );

                do
                    if ( leftInBar > distance )
                    {
                        leftInBar -= distance;
                        leftInBar = able.get().length() - leftInBar;
                        break;
                    }
                    else
                    {
                        distance -= leftInBar;
                        able = able.getPrev();
                        leftInBar = able.get().length();
                    }
                while ( true );
            }

            planM.bar = able.get();

            // calculate position as distance from end
            Vector2d dir = new Vector2d (planM.bar.end );
            dir.sub( planM.bar.start );
            dir.normalize();
            dir.scale( -leftInBar );
            dir.add( planM.bar.end );

            planM.set( dir );

            planM.bar.mould.create( planM, generator );
        }
 
开发者ID:twak,项目名称:siteplan,代码行数:82,代码来源:AnimateAnchorCircularShip.java


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