Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (753) Games in Android Showcase (228) games submitted by our members Games in WIP (842) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Slope of a perpendicular line  (Read 1341 times) 0 Members and 1 Guest are viewing this topic.
saucymeatman
 « Posted 2013-12-10 21:25:47 »

Hello!

I need to calculate the slope of a perpendicular line, which I can do on a piece of paper :
LineA's slope = 1/3
PerpendicularToLineA's slope = -3/1
(-Run/Rise)

But how do I do this programatically?
lineA.slope = 2;
perpLineA.slope = ; (It would equal -1/2 in this case)

I cant find an actual formula anywhere and my line/linesegment classes do not contain rise's/run's only a numerical slope.

Any help is greatly appreciated!
phu004

JGO Knight

Medals: 14
Projects: 10
Exp: 10 years

NoSuchPersonException

 « Reply #1 - Posted 2013-12-10 22:08:00 »

If LineA's slope is x1/y1, and the slope for the line that is perpendicular to A is x2/y2,

Then it must satisfy the following:

x1 * x2 + y1 * y2 = 0    //the dot product of 2 vectors (in any dimensions) that are perpendicular to each other is always zero

=>

x1 * x2 = -y1*y2

=>

x2/y2 = -y1/x1

Thus if the slop for line A is  2 (i.e x1/y1 = 2),  the slop for the perpendicular line will be -1/2

kramin42
 « Reply #2 - Posted 2013-12-11 02:46:31 »

perpLineA.slope =  -1/lineA.slope

"All science is either physics or stamp collecting." - Ernest Rutherford.
CodeGolf4k
M4nkala
Roquen

JGO Kernel

Medals: 517

 « Reply #3 - Posted 2013-12-11 06:25:49 »

Don't use slope...use direction.
Pages: [1]
 ignore  |  Print

 nelsongames (17 views) 2018-04-24 18:15:36 nelsongames (13 views) 2018-04-24 18:14:32 ivj94 (587 views) 2018-03-24 14:47:39 ivj94 (49 views) 2018-03-24 14:46:31 ivj94 (400 views) 2018-03-24 14:43:53 Solater (64 views) 2018-03-17 05:04:08 nelsongames (110 views) 2018-03-05 17:56:34 Gornova (175 views) 2018-03-02 22:15:33 buddyBro (723 views) 2018-02-28 16:59:18 buddyBro (93 views) 2018-02-28 16:45:17
 KaiHH 13x ByerN 11x SHC 10x NuclearPixels 10x Zemlaynin 10x Guerra2442 10x Damocles 6x VaTTeRGeR 5x orangepascal 4x philfrei 4x Spasi 3x ndnwarrior15 3x mesterh 3x ags1 3x Phased 2x CommanderKeith 2x
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org