Here you can find the source of crossEndForLineVectorAlgebra(double x1, double y1, double x2, double y2, double margin, double width)
Parameter | Description |
---|---|
x1 | line start A X |
y1 | line start A Y |
x2 | line end B X |
y2 | line end B Y |
margin | cross from B |
width | of cross |
public static double[][] crossEndForLineVectorAlgebra(double x1, double y1, double x2, double y2, double margin, double width)
//package com.java2s; /*/*www. j a v a 2 s.c o m*/ * Beigesoft ? * * Licensed under the Apache License, Version 2.0 * * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 */ public class Main { /** * Calculate cross end for given line with vector algebra:<br> * ---------------x--<br> * Cross points:<br> *       C D<br> * A---------------x--B<br> *       E F<br> * * Usage code: * <pre> * </pre> * @param x1 line start A X * @param y1 line start A Y * @param x2 line end B X * @param y2 line end B Y * @param margin cross from B * @param width of cross * @return arrays of calculated cross points: * cross's points: * [C x, D x, E x, F x] * [C y, D y, E y, F y]</li> * </ul> */ public static double[][] crossEndForLineVectorAlgebra(double x1, double y1, double x2, double y2, double margin, double width) { double[][] result = new double[2][4]; double[] baseVector = { x2 - x1, y2 - y1 }; double baseVectorLenght = Math.sqrt(baseVector[0] * baseVector[0] + baseVector[1] * baseVector[1]); double[] baseUnitVector = { baseVector[0] / baseVectorLenght, baseVector[1] / baseVectorLenght }; double[] normal = { -baseUnitVector[1], baseUnitVector[0] }; //Point C: result[0][0] = x2 - baseUnitVector[0] * (margin + width / 2) - normal[0] * width / 2; result[1][0] = y2 - baseUnitVector[1] * (margin + width / 2) - normal[1] * width / 2; //Point D: result[0][1] = x2 - baseUnitVector[0] * (margin - width / 2) - normal[0] * width / 2; result[1][1] = y2 - baseUnitVector[1] * (margin - width / 2) - normal[1] * width / 2; //Point E: result[0][2] = x2 - baseUnitVector[0] * (margin + width / 2) + normal[0] * width / 2; result[1][2] = y2 - baseUnitVector[1] * (margin + width / 2) + normal[1] * width / 2; //Point F: result[0][3] = x2 - baseUnitVector[0] * (margin - width / 2) + normal[0] * width / 2; result[1][3] = y2 - baseUnitVector[1] * (margin - width / 2) + normal[1] * width / 2; return result; } }