Click here to Skip to main content
15,887,464 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Quote:
I want to find out the nearest point on my road network by intersecting which is a multiline string from a point geometry (bus stops) with latitude longitude value.

1)my bus stop point is => POINT (2.155033 41.419847)

2)my bus route line is =>
C#
MULTILINESTRING ((2.18789506289074 41.369152699421,2.18802127513857 41.3697888552612,2.18767057866036 41.3703119852137,2.18766979654406 41.37074318776,2.18812304854065 41.3735307354314,2.1886789194413 41.374569746161,2.1889098578737 41.3751158610535,2.18897512779238 41.37554833165,2.18891950779056 41.3760571184838,2.18851443688044 41.3771741639192,2.18675736708143 41.3816169797163,2.1866456406235 41.3818226073718,2.18645684935226 41.3820135576997,2.18627914329181 41.382116195095,2.18612082823024 41.3821713914564,2.18570997718131 41.3822243968918,2.18539513043179 41.3823086425584,2.18525347359646 41.3824079753751,2.1839340136748 41.3830322047531,2.18390649158089 41.3830783714921,2.18392395185484 41.3831397194255,2.18587276708772 41.3854576756498,2.18589964790164 41.385532024675,2.18586945793199 41.3856444864379,2.18261558494506 41.3881041545251,2.18263627091791 41.3882154992448,2.18385012509596 41.3891325983823,2.18386449826827 41.3892046883763,2.18382901652674 41.3892463038772,2.18077395880723 41.3915437862463,2.18061552873923 41.3915945063379,2.18015295947031 41.3915850528886,2.17997563538183 41.3916181537168,2.17635656012648 41.3943518432113,2.1762690019103 41.3945260696834,2.17621402105296 41.3950594155552,2.17602498447386 41.3952737839804,2.17574376035482 41.3953920396521,2.17504719057014 41.3954189959932,2.1748057474122 41.3955130222053,2.17103760006674 41.3983620708474,2.17100580187205 41.3984173375346,2.17103307081089 41.3984813830085,2.17198522935863 41.3991943408547,2.17201302651318 41.3992660845497,2.1719568210244 41.3993412311992,2.17101188414727 41.4000516296092,2.17090403398947 41.4000914248132,2.17074921760649 41.4000390504765,2.16998030241801 41.3994731788606,2.16989026605797 41.3994481375127,2.1698295916173 41.3994659583111,2.16448214139734 41.4034794856289,2.16318461586861 41.4045013675403,2.16315703967497 41.4045648140841,2.16318575581575 41.4046616101348,2.16353512791859 41.4048925336147,2.16355739669082 41.404959422892,2.16310716321625 41.4054381694339,2.16308208344468 41.4055709377397,2.16468694950139 41.4115720408457,2.16465965369799 41.4116650036247,2.16358186449532 41.4133536341306,2.16292619467356 41.4143147146608,2.16284769038596 41.414325481179,2.16231208023113 41.4141488328281,2.1615680417046 41.4138249759612,2.16147380438529 41.4138480874758,2.16128163869348 41.4140464737516,2.1611128964892 41.4140925157267,2.16098341760918 41.4140814118793,2.16070601787816 41.4139478359664,2.16053324230585 41.4139028000957,2.16033780597739 41.4139115805377,2.16011896821586 41.4139777657569,2.15955183028039 41.4142323673026,2.15894048566937 41.4146476878184,2.15868188838981 41.4148795246025,2.15832159453006 41.4152763820253,2.15786274465684 41.4159450116298,2.15776819063413 41.4160099304729,2.15760661155469 41.4160594335024,2.15737596361437 41.4160609074286,2.1571667702615 41.4160021788549,2.15591866248559 41.4151709506932,2.15578146424415 41.4151275016074,2.15555962149441 41.4151145524377,2.15531597360884 41.4151971022672,2.15520719264591 41.4153025563675,2.15517120251879 41.4153984651125,2.15517292754464 41.4154981184573,2.15523470869394 41.4156245592996,2.1553211399956 41.4156908849094,2.15589391704465 41.4158979697658,2.15610219377705 41.4160098740629,2.15622594930354 41.4161325260572,2.1564303948017 41.4164566357827,2.15658467318461 41.41663140306,2.15660296691178 41.4168083717798,2.15641473451821 41.4172125002561,2.15639168180855 41.4173647467975,2.15645316531924 41.4175108210626,2.1566325379471 41.4176486523024,2.1570419184921 41.4177832133066,2.15724013470411 41.4177834122703,2.15736442451896 41.4177483821214,2.15853377378558 41.416895080858,2.1586282330502 41.4168013638101,2.15874528809398 41.4165820224003,2.15884014751862 41.4164971174055,2.15897476708948 41.4164671511063,2.15909613709129 41.4164949969385,2.15918538829584 41.416576887141,2.15919102741094 41.4166871347685,2.15908280759959 41.4167929749269,2.15863911109509 41.4170128487073,2.15750770479131 41.4180635932117,2.15743614394059 41.4181889219617,2.15726685656931 41.4187383817924,2.15690532134724 41.4192845061635,2.15661333306303 41.4196165178246,2.15641290681801 41.4197312729088,2.15618819335814 41.4197873191196,2.15591109576761 41.4197994657908,2.15551230115104 41.419743028144,2.15522379857254 41.4198097738491,2.15387543467082 41.4209946864277,2.15362073177007 41.42111024472,2.15320002792306 41.4211739687329,2.15288578677564 41.42114405829,2.1526624134297 41.4210493404849,2.15250276141849 41.420908720865,2.15208247961031 41.4203912821938,2.15189987121164 41.4202677960095,2.15166211361205 41.4201872561449,2.15123637745327 41.4201846409631,2.14999573527314 41.4203368843969,2.14928716009347 41.4203770848161,2.14918943593202 41.4203398464583,2.1489346657225 41.4200409423644,2.14827032508294 41.4186464569164,2.14814333035007 41.4184968221271,2.14779533944322 41.4182119619259,2.14751100083161 41.4174013466036,2.14722465431309 41.4170561406168,2.14714200159937 41.4169053829003,2.14679877807155 41.4158012533751,2.14659147214001 41.4156035973331,2.14537146309842 41.415010467696,2.14492985539079 41.4147424143399,2.14484003769828 41.4146560051506,2.14474527252954 41.4145052367747,2.14469912594483 41.4143442457027,2.14471160497103 41.413949063427,2.14479002548599 41.4134871841704,2.14453145258584 41.4133659683231,2.14450273827275 41.4132133755228,2.14417088287778 41.4129532595272,2.14322372613549 41.4115507107144,2.14316842827768 41.411511487446,2.14098780722705 41.4117427490472,2.14076629541149 41.4118229922116,2.1400933357572 41.4123435039765,2.13996581335241 41.4123882781541,2.13982573410804 41.4123509060497,2.1384940910649 41.411389837522,2.13839908879386 41.4113695249474,2.13833930134323 41.4113972421172,2.13829441498894 41.4114529839529,2.13767474373572 41.4139074405777,2.13778273645247 41.4141784311499,2.13826933396943 41.4145976391868,2.13835735882591 41.4147901480802,2.13836745279339 41.4149518086367,2.13827363864394 41.4151704474618,2.13816602593613 41.4153031417278,2.13742771413447 41.4159399356035,2.13713716476966 41.416091669169,2.13678903517276 41.4161384386491,2.13651629536687 41.4160952744543,2.13364430291646 41.4148433428198,2.13362844859739 41.4147649396062,2.13382468416606 41.4144991648562,2.13394942406275 41.4144580612775,2.13474414367748 41.4145878925797,2.13518740096296 41.4147011589352,2.13610602714288 41.4150313692507,2.13629572931172 41.4150296038002,2.13704340713785 41.4144075514543,2.13794256758116 41.4139603312988,2.14063972292387 41.411835297597,2.14079412128117 41.4117461138759,2.14099625254814 41.4116801830698,2.14319434432978 41.4114655095912,2.1432807925186 41.4115106343852,2.14425014429959 41.4129502366445,2.14446057172673 41.4131276623438,2.14486533122048 41.4133660615025,2.14471664782622 41.4141859884436,2.14476188057032 41.4144550353838,2.14485317417719 41.4146141368991,2.14498443428285 41.4147366315155,2.14526908526865 41.4149200473644,2.14671459689712 41.415626659235,2.14683094096866 41.4157262973264,2.14717131418313 41.4168635801715,2.1472705396131 41.4170445635735,2.14754927324161 41.4173844797442,2.14783916419631 41.4182033688953,2.14820297771392 41.4185054061665,2.14830653509874 41.4186299528669,2.14895158174793 41.4199504883223,2.14922460565033 41.4203040674696,2.14931788269894 41.4203290317948,2.14968259971561 41.4203125489939,2.15110925316892 41.4201637612389,2.15182242639438 41.4201295193791,2.15189326299638 41.4201547846942,2.15219758302676 41.4204163959137,2.15267591791677 41.4209917560581,2.15280470234334 41.4210609623138,2.15300159751266 41.4211129788321,2.15339715328131 41.4211096368338,2.15365226996005 41.4210424611786,2.15389922855271 41.4209067232256,2.15505030344979 41.4198609692811,2.15521443284009 41.4197530931938,2.15550424436882 41.4196942926914,2.15587188165548 41.4197467458291,2.15612977357086 41.4197447179988,2.15635580564048 41.4196931132379,2.15655997899734 41.4195893387839,2.15680869960411 41.4193154508681,2.15717148247127 41.4187765689372,2.15744606818819 41.4180579448815,2.15857727417079 41.4169968229109,2.15906372644314 41.4167573461205,2.15912465062198 41.4166306415617,2.15909041333409 41.4165779409981,2.15898948656457 41.4165357334418,2.15883407376344 41.4165756272174,2.15859490642439 41.4169146774982,2.15736273629404 41.4178003428799,2.15719553663638 41.4178353111509,2.15705346908272 41.4178311185379,2.15662371148356 41.4176936610404,2.15642059780314 41.4175502964041,2.15633520209336 41.4173712236843,2.15635189147611 41.4172224884815,2.15649478258219 41.4168990952118,2.15647052800609 41.4166436187075,2.15617515924547 41.4161543572699,2.15604456306248 41.4160147660669,2.15592309794193 41.4159463466555,2.15535064608489 41.4157538474318,2.1552047940732 41.4156569288613,2.15512035893531 41.4154512451538,2.15516725925473 41.415297318264,2.15524248203054 41.4152080836643,2.155365628717 41.4151279558427,2.15556056171804 41.4150751876575,2.15589429047972 41.4151171505209,2.15602831864891 41.415179041561,2.15719203260936 41.4159584433264,2.15749736503165 41.4160204154661,2.15772283769839 41.415980468543,2.15787446156153 41.4158697317828,2.15825996224231 41.4152984231471,2.15860413048323 41.4149059338066,2.15903762185137 41.4145232924608,2.15954114603598 41.4141988535566,2.15992444577669 41.4140121964535,2.16035018086386 41.4138788295117,2.16062126214212 41.4138849494331,2.16095112470231 41.4140282306032,2.16105706857095 41.4140466932622,2.16121335524445 41.414022016448,2.16129472019181 41.4139736084595,2.16136617619924 41.4138089407679,2.16127135243033 41.4135751365176,2.16129278440332 41.4134651311551,2.1618044333889 41.4128634281188,2.16231310638088 41.4123436781665,2.16249827522349 41.4122451231698,2.16385516795037 41.4118060966986,2.16451800732381 41.4116792769411,2.16458244760738 41.4116224236675,2.16306714748566 41.4061171515844,2.16300197909118 41.4059781877106,2.16280247206551 41.4057708170535,2.16275342201126 41.4056624695918,2.16277650598174 41.4055687613517,2.16334240255032 41.4049635626913,2.16335739184762 41.4048927285838,2.1627746856778 41.4045018736058,2.162718624546 41.4044104182272,2.16274537304993 41.404311728452,2.16933121285694 41.3993191358906,2.16965092384351 41.3991220399422,2.17013007585496 41.3988915517262,2.17476175018602 41.3953963807566,2.1748302845601 41.3952683219021,2.17486466133471 41.3947813577636,2.17494353134185 41.3946001332617,2.17501971877835 41.3945175848002,2.17529836771691 41.3943946645563,2.17607208596917 41.3943399450125,2.17624236649558 41.3942806753587,2.17975016037452 41.39163246805,2.17990402167742 41.3914496826919,2.17994197687619 41.3910322985471,2.18003601979954 41.3908842413607,2.18290395233796 41.3887104965197,2.18292917401283 41.3886574111035,2.1829044266933 41.3885861272347,2.18240548995732 41.3881866811411,2.18236802331182 41.3881037314579,2.18239258083319 41.388025340382,2.1856179547032 41.3855799113394,2.18561712098634 41.385495137473,2.18363082910216 41.3831435958443,2.18328995402206 41.3826995395455,2.18327306161507 41.3825909149967,2.18338742438392 41.3824633236132,2.18665793896862 41.3809251022356,2.18692519607944 41.3807011254496,2.18705340469059 41.3804873989537,2.18875987749465 41.3761666428178,2.18885043337858 41.3756690913505,2.18881832021993 41.3752928451506,2.18868301278493 41.3748863182213,2.1881380820446 41.3738780103494,2.18760675005135 41.3706805913807,2.18759860230772 41.3703831711511,2.18776377083256 41.3700613895766,2.18770993914782 41.3697875919038,2.18772618409087 41.3697091673595,2.18767472393837 41.3696023295211,2.18751562299488 41.3687352923542,2.18755542169242 41.3686730706759,2.18764960135579 41.3686322182907,2.18775102902523 41.3686476149098,2.18781855263967 41.3686973456922,2.18789506289074 41.369152699421))


if you map above 1 and 2 points on this url

https://www.keene.edu/campus/maps/tool/

it will generate this
a)https://ibb.co/sQr3PkT
b)https://ibb.co/kQrmbjq

i want a point(x,y) by intersecting from bus stop to route line

https://ibb.co/Yj6zV8q

for clear view https://ibb.co/qFpsnF1

Bus stops should find the nearest line and intersect perpendicularly and get their intersected value in points (lat, long)



What I have tried:

created buffer class and get a point(lat,lng) from database and based on that route returned line data in multilinestring datatype and intersected but its intersected value creates wrong point(lat,LNG)
Posted
Updated 1-Dec-21 1:42am
v2

1 solution

i have done something similar in unity-3D see if you can use my code:
Matrex class if it help ;
public class Matrix {
  public float[] values {
    get;
    set;
  }
  public int raws {
    get;
    set;
  }
  public int caloms {
    get;
    set;
  }
  public Matrix(int r, int c, float[] v) {
    raws = r;
    caloms = c;
    values = new float[raws * caloms];
    Array.Copy(v, values, raws * caloms);
  }
  public override string ToString() {
    string m = "|";
    for (int i = 0; i < raws; i++) {
      for (int j = 0; j < caloms; j++) {
        m += $ "{values[( i * caloms ) + j]} ";
      }
      m += " |" + "\n" + "|";
    }
    return m;
  }
  public Matrix perp() {
    float[] _b = new float[raws * caloms];
    Matrix _V = new Matrix(caloms, raws, _b);
    for (int i = 0; i < _V.raws; i++) {
      for (int j = 0; j < _V.caloms; j++) {
        _V.values[(i * _V.caloms) + j] = values[(j * caloms) + i];
      }
    }
    return _V;
  }
  public static Matrix perp(Matrix b) {
    float[] _b = new float[b.raws * b.caloms];
    Matrix _V = new Matrix(b.caloms, b.raws, _b);
    for (int i = 0; i < _V.raws; i++) {
      for (int j = 0; j < _V.caloms; j++) {
        _V.values[(i * _V.caloms) + j] = b.values[(j * b.caloms) + i];
      }
    }
    return _V;
  }
  static public Matrix operator * (Matrix a, Matrix b) {
    if (a.caloms == b.raws) {
      float[] _b = new float[a.raws * b.caloms];
      Matrix V = new Matrix(a.raws, b.caloms, _b);
      for (int i = 0; i < a.raws; i++) {
        for (int j = 0; j < b.caloms; j++) {
          for (int k = 0; k < a.caloms; k++) {
            V.values[i * b.caloms + j] += a.values[i * a.caloms + k] * b.values[k * 
            b.caloms + j];
          }
        }
      }
      return V;
    } else return null;
  }
}


The mather Class;
using UnityEngine;

public class Mather
{
    #region Multyplay or Divide VC's
    public static Vector3 MultyPlayVCbyValue( Vector3 VC, Vector3 VC1 ) =>
           new Vector3( VC.x * VC1.x, VC.y * VC1.y, VC.z * VC1.z );

    public static Vector3 MultyPlayVCbyValue( Vector3 VC, Vector3 VC1, Vector3 VC2 ) =>
        new Vector3( VC.x * VC1.x * VC2.x
                   , VC.y * VC1.y * VC2.y
                   , VC.z * VC1.z * VC2.z );

    public static Vector3 MultyPlayVCbyValue( Vector3 VC, Vector3 VC1, Vector3 VC2, Vector3 VC3 ) =>
                 new Vector3( VC.x * VC1.x * VC2.x * VC3.x
                            , VC.y * VC1.y * VC2.y * VC3.y
                            , VC.z * VC1.z * VC2.z * VC3.z );
    public static Vector3 DivVCbyValue( Vector3 VC, Vector3 VC1 ) =>
           new Vector3( VC.x / VC1.x, VC.y / VC1.y, VC.z / VC1.z );

    public static Vector3 DivVCbyValue( Vector3 VC, Vector3 VC1, Vector3 VC2 ) =>
        new Vector3( VC.x / VC1.x / VC2.x
                   , VC.y / VC1.y / VC2.y
                   , VC.z / VC1.z / VC2.z );

    public static Vector3 DivVCbyValue( Vector3 VC, Vector3 VC1, Vector3 VC2, Vector3 VC3 ) =>
                 new Vector3( VC.x / VC1.x / VC2.x / VC3.x
                            , VC.y / VC1.y / VC2.y / VC3.y
                            , VC.z / VC1.z / VC2.z / VC3.z );
    #endregion
    #region VC Math
    /// <summary>
    /// square number
    /// </summary>
    /// <param name="value"></param>
    /// <returns></returns>
    public static float Square( float value )
    {
        return value * value;
    }
    public static Vector3 P_P_toVC( Vector3 a, Vector3 b ) => b - a;
    /// <summary>
    /// multipli normal vectors
    /// </summary>
    /// <param name="a"></param>
    /// <param name="b"></param>
    /// <returns></returns>
    public static Vector3 V_x_W( Vector3 a, Vector3 b ) => new Vector3( a.x * b.x, a.y * b.y, a.z * b.z );
    /// <summary>
    /// Distance from destination Victor - current location Victor
    /// </summary>
    /// <param name="V"></param>
    /// <param name="W"></param>
    /// <returns></returns>
    public static float Distens( Vector3 V, Vector3 W )
    {
        float diffSquared = Square(V.x - W.x) + Square(V.y - W.y) + Square(V.z - W.z);
        return Mathf.Sqrt( diffSquared );
    }
    /// <summary>
    /// Create a uniform vector length shortened in the same direction
    /// </summary>
    /// <param name="V"></param>
    /// <returns></returns>
    public static Vector3 NormalVC( Vector3 V )
    {
        float lingth = Distens(new Vector3(0, 0, 0), V);
        V.x /= lingth;
        V.y /= lingth;
        V.z /= lingth;
        return V;
    }
    /// <summary>
    /// inverted vector
    /// </summary>
    /// <param name="v"></param>
    /// <returns></returns>
    public static Vector3 Perp2D( Vector3 v ) => new Vector3( -v.y, v.x, 0f );
    #endregion
    #region Rotate VC {Dot Cross angle_R|D }
    /// <summary>
    /// Dot Product V.W
    /// </summary>
    /// <param name="V"></param>
    /// <param name="W"></param>
    /// <returns></returns>
    public static float DotProd( Vector3 V, Vector3 W )
    {
        return ( V.x * W.x + V.y * W.y + V.z * W.z );
    }
    /// <summary>
    /// Radian, The corner of the dot product
    /// </summary>
    /// <param name="V"></param>
    /// <param name="W"></param>
    /// <returns></returns>
    public static float AngleRadian( Vector3 V, Vector3 W )
    {
        float dot = DotProd(V, W) / (Distens(new Vector3(0, 0, 0), V) * Distens(new Vector3(0, 0, 0), W));

        return Mathf.Acos( dot ); //radians.  For degrees * 180/Mathf.PI;
    }
    /// <summary>
    /// Dgree, The corner of the dot product
    /// </summary>
    /// <param name="V"></param>
    /// <param name="W"></param>
    /// <returns></returns>
    public static float AngleDgree( Vector3 V, Vector3 W )
    {
        float dot = DotProd(V, W) / (Distens(new Vector3(0, 0, 0), V) * Distens(new Vector3(0, 0, 0), W));

        return Mathf.Acos( dot ) * Mathf.Rad2Deg;   // or * 180/Mathf.PI;
    }

    /// <summary>
    /// 3D perp
    /// V X W
    /// A cross product to determine the positive or negative rotation of the dot product
    /// B to find the ray perpendicular to the two rays at the point of intersection
    /// </summary>
    /// <param name="V"></param>
    /// <param name="W"></param>
    /// <returns></returns>
    public static Vector3 Cross( Vector3 V, Vector3 W )
    {
        float nx, ny, nz;
        nx = V.y * W.z - V.z * W.y;
        ny = V.z * W.x - V.x * W.z;
        nz = V.x * W.y - V.y * W.x;
        return new Vector3( nx, ny, nz );
    }
    /// <summary>
    /// Radian , The angle between two rays with radians
    /// </summary>
    /// <param name="V"></param>
    /// <param name="angle"></param>
    /// <param name="clockwise"></param>
    /// <returns></returns>
    public static Vector3 RotatRadians2D( Vector3 V, float angle, bool clockwise = false )
    {
        if ( clockwise )//If the crossproduct of the Z is negative
        { angle = 2 * Mathf.PI - angle; }
        float nx = V.x * Mathf.Cos(angle) - V.y * Mathf.Sin(angle);
        float ny = V.x * Mathf.Sin(angle) + V.y * Mathf.Cos(angle);

        return new Vector3( nx, ny, 0 );
    }
    /// <summary>
    /// Dgrees, The angle between two rays in degrees
    /// </summary>
    /// <param name="V"></param>
    /// <param name="angle"></param>
    /// <returns></returns>
    public static Vector3 RotatDgrees2D( Vector3 V, float angle )
    {
        angle = angle * Mathf.PI / 180;
        float nx = V.x * Mathf.Cos(angle) - V.y * Mathf.Sin(angle);
        float ny = V.x * Mathf.Sin(angle) + V.y * Mathf.Cos(angle);
        return new Vector3( nx, ny, 0 );
    }
    /// <summary>
    /// Rotate the beam to see a point
    /// </summary>
    /// <param name="Pos"></param>
    /// <param name="focusPoin"></param>
    /// <param name="up"></param>
    /// <returns></returns>
    public static Vector3 Lokat2D( Vector3 Pos, Vector3 focusPoin, Vector3 up )
    {
        bool clockwise = false;
        //First the distance
        Vector3 distens = focusPoin - Pos;
        //simplified vector
        Vector3 nor = NormalVC(distens);
        //Make sure the rotation is positive
        if ( Cross( up, nor ).z < 0 ) { clockwise = true; }
        //We calculate the angle
        float angle = AngleRadian(up, nor);
        //We create a new rotation vector
        Vector3 ro = RotatRadians2D(up, angle, clockwise);
        return ro;
    }
    public static bool ClockWise( Vector3 V, Vector3 W ) => Cross( V, W ).z < 0;
    /// <summary>
    /// </summary>
    /// <param name="pos">transform.position</param>
    /// <param name="facing">transform.up</param>
    /// <param name="VC">The Added Victor to the original Victor</param>
    /// <returns></returns>
    public static Vector3 Move2D( Vector3 pos, Vector3 facing, Vector3 VC )
    {
        //Vector3 W = VC;
        float angle = AngleRadian(VC, facing);
        float wordAngle = AngleRadian(VC, new Vector3(0, 1, 0)); //The original angle between the direction of the added ray and the original direction of the axis
        bool C = ClockWise(VC, facing);
        VC = RotatRadians2D( VC, angle + wordAngle, C );
        return pos + VC;
    }
    #endregion
    #region Plane
    public class Plane
    {
        public Vector3 A { get; set; }
        public Vector3 V { get; set; }
        public Vector3 U { get; set; }
        public Plane( Vector3 a, Vector3 v, Vector3 u )
        {
            A = a;
            V = v - a;
            U = u - a;
        }

        public static Vector3 Lerp( Vector3 a, Vector3 v, float s, Vector3 u, float t )
        {
            v = v - a;
            u = u - a;
            float nx= a.x +v.x*s+u.x*t;
            float ny= a.y +v.y*s+u.y*t;
            float nz= a.z +v.z*s+u.z*t;
            return new Vector3( nx, ny, nz );
        }
        public Vector3 Lerp( float s, float t )
        {

            float nx= A.x +V.x*s+U.x*t;
            float ny= A.y +V.y*s+U.y*t;
            float nz= A.z +V.z*s+U.z*t;
            return new Vector3( nx, ny, nz );
        }

    }
    #endregion
    #region Line-Line intersection
    public static float IntersectinPoint_T( Vector3 A, Vector3 B )
    {
        Vector3 C = B-A;
        Vector3 V=A,U=B;
        if ( DotProd( Perp2D( U ), V ) == 0 ) { return float.NaN; }
        float T= DotProd( Perp2D(U),C) / DotProd(Perp2D(U),V);
        return T;
    }
    public static float IntersectinPoint_S( Vector3 A, Vector3 B )
    {
        Vector3 C = B-A;
        Vector3 V=A,U=B;
        if ( DotProd( Perp2D( U ), V ) == 0 ) { return float.NaN; }
        float T= DotProd( Perp2D(V),C) / DotProd(Perp2D(U),V);
        return T;
    }
    #endregion

    #region Line-plane intersection
    public static float L_P_intersection( Vector3 sors_p_p, Vector3 D, Vector3 E, Vector3 sors_p_L, Vector3 C )
    {
        Vector3 v=P_P_toVC(sors_p_p,D),u=P_P_toVC(sors_p_p,E);
        Vector3 n = Cross(u,v);
        float t = (-DotProd(n,P_P_toVC(sors_p_L,sors_p_p)))/DotProd(n,P_P_toVC(sors_p_L,C));
        return t;
    }
    public static float L_P_intersection( Plane p, Vector3 sors_p_L, Vector3 C )
    {
        Vector3 n = Cross(p.U,p.V);
        float t = (-DotProd(n,P_P_toVC(sors_p_L,p.A)))/DotProd(n,P_P_toVC(sors_p_L,C));
        return t;
    }
    public static Vector3 L_P_intersect_Point( Plane p, Vector3 sors_p_L, Vector3 C )
    {
        Vector3 n = Cross(p.U,p.V);
        n = NormalVC( n );
        float t = DotProd(n,p.A-sors_p_L)/DotProd(n,C);
        Vector3 point = sors_p_L+C*t;
        return point;
    }
    public static Vector3 L_P_intersect_Point( Vector3 sors_p_p, Vector3 D, Vector3 E, Vector3 sors_p_L, Vector3 C )
    {
        Vector3 v=P_P_toVC(sors_p_p,D),u=P_P_toVC(sors_p_p,E);
        Vector3 n = Cross(u,v);
        float t = (-DotProd(n,P_P_toVC(sors_p_L,sors_p_p)))/DotProd(n,P_P_toVC(sors_p_L,C));
        Vector3 point = sors_p_L+ (P_P_toVC(sors_p_L,C)*t);
        return point;
    }
    public static Vector3 Reflect( Vector3 normal,Vector3 v )
    {
        var V= NormalVC( v );
        var n= NormalVC( normal );
        var r = V - 2*(Mather.DotProd(V,n))*n;
        return r;
    }
    #endregion


}


I am sure that will help you, and as I said you don't have to use unity, you can create your own state Victor3 class object
 
Share this answer
 
v2
Comments
Member 12959823 2-Dec-21 0:44am    
no sir ,couldnt understand using this method,could you give a solution using "netTopology" in c# ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900