Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (577)
games submitted by our members
Games in WIP (498)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Slope of a perpendicular line  (Read 248 times)
0 Members and 1 Guest are viewing this topic.
Offline saucymeatman
« Posted 2013-12-10 22: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 = Huh; (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!
Offline phu004

JGO Coder


Medals: 4
Projects: 9
Exp: 10 years


NoSuchPersonException


« Reply #1 - Posted 2013-12-10 23: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


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

perpLineA.slope =  -1/lineA.slope

"All science is either physics or stamp collecting." - Ernest Rutherford.
CodeGolf4k
M4nkala
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Roquen
« Reply #3 - Posted 2013-12-11 07:25:49 »

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

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (25 views)
2014-04-15 18:08:23

BurntPizza (20 views)
2014-04-15 03:46:01

UprightPath (36 views)
2014-04-14 17:39:50

UprightPath (18 views)
2014-04-14 17:35:47

Porlus (34 views)
2014-04-14 15:48:38

tom_mai78101 (60 views)
2014-04-10 04:04:31

BurntPizza (118 views)
2014-04-08 23:06:04

tom_mai78101 (218 views)
2014-04-05 13:34:39

trollwarrior1 (185 views)
2014-04-04 12:06:45

CJLetsGame (192 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!