Question

In: Computer Science

How do i make a point for line segment from p to infinite in java? in...

How do i make a point for line segment from p to infinite in java?

in C++, it's

Point p;
Point extreme = {INF, p.y};

---------------------------------------------------------------------------------------------

boolean isInside(Point polygon[], int n, Point p)
{
// There must be at least 3 vertices in polygon[]
if (n < 3) return false;
  
// Create a point for line segment from p to infinite
//Point extreme = {INF, p.y};
   p= Double.POSITIVE_INFINITY;
   Point extreme = p.y;
// Count intersections of the above line with sides of polygon
int count = 0, i = 0;
do
{
int next = (i+1)%n;
  
// Check if the line segment from 'p' to 'extreme' intersects
// with the line segment from 'polygon[i]' to 'polygon[next]'
if (doIntersect(polygon[i], polygon[next], p, extreme))
{
// If the point 'p' is colinear with line segment 'i-next',
// then check if it lies on segment. If it lies, return true,
// otherwise false
if (graph(polygon[i], p, polygon[next]) == 0)
return onSegment(polygon[i], p, polygon[next]);
  
count++;
}
i = next;
} while (i != 0);
  
// Return true if count is odd, false otherwise
return count%2==1; // Same as (count%2 == 1)
}

Solutions

Expert Solution

public class LinePlaneIntersection {
    private static class Vector3D {
        private double x, y, z;
 
        Vector3D(double x, double y, double z) {
            this.x = x;
            this.y = y;
            this.z = z;
        }
 
        Vector3D plus(Vector3D v) {
            return new Vector3D(x + v.x, y + v.y, z + v.z);
        }
 
        Vector3D minus(Vector3D v) {
            return new Vector3D(x - v.x, y - v.y, z - v.z);
        }
 
        Vector3D times(double s) {
            return new Vector3D(s * x, s * y, s * z);
        }
 
        double dot(Vector3D v) {
            return x * v.x + y * v.y + z * v.z;
        }
 
        @Override
        public String toString() {
            return String.format("(%f, %f, %f)", x, y, z);
        }
    }
 
    private static Vector3D intersectPoint(Vector3D rayVector, Vector3D rayPoint, Vector3D planeNormal, Vector3D planePoint) {
        Vector3D diff = rayPoint.minus(planePoint);
        double prod1 = diff.dot(planeNormal);
        double prod2 = rayVector.dot(planeNormal);
        double prod3 = prod1 / prod2;
        return rayPoint.minus(rayVector.times(prod3));
    }
 
    public static void main(String[] args) {
        Vector3D rv = new Vector3D(0.0, -1.0, -1.0);
        Vector3D rp = new Vector3D(0.0, 0.0, 10.0);
        Vector3D pn = new Vector3D(0.0, 0.0, 1.0);
        Vector3D pp = new Vector3D(0.0, 0.0, 5.0);
        Vector3D ip = intersectPoint(rv, rp, pn, pp);
        System.out.println("The ray intersects the plane at " + ip);
    }
}

Related Solutions

Suppose ?⃗ (?,?)=−??⃗ +??⃗ and ? is the line segment from point ?=(2,0) to ?=(0,3). (a)...
Suppose ?⃗ (?,?)=−??⃗ +??⃗ and ? is the line segment from point ?=(2,0) to ?=(0,3). (a) Find a vector parametric equation ?⃗ (?) for the line segment ? so that points ? and ? correspond to ?=0 and ?=1, respectively. ?⃗ (?)= (b) Using the parametrization in part (a), the line integral of ?⃗ along ? is ∫??⃗ ⋅??⃗ =∫???⃗ (?⃗ (?))⋅?⃗ ′(?)??=∫?? ?? with limits of integration ?= and ?= (c) Evaluate the line integral in part (b). (d)...
how do I make a histogram. I am using the example from the book Essentials of...
how do I make a histogram. I am using the example from the book Essentials of Statistics Chapter 2.2, Problem 9BSC.
"How do SMIS increase Social Capital?" I need to make power point slides on this topic...
"How do SMIS increase Social Capital?" I need to make power point slides on this topic can anyone help me?
How do I make the series graph
How do I make the series graph
How do you find the slope of the tangent line to a curve at a point?
How do you find the slope of the tangent line to a curve at a point?
Given a segment, construct its perpendicular bisector. Given a line an a point, construct the perpendicular...
Given a segment, construct its perpendicular bisector. Given a line an a point, construct the perpendicular to the line through the point. Given a line an a point not on the line, construct the parallel to the line through the point.
Prove that, in hyperbolic geometry, for each point P and a line l not containing P,...
Prove that, in hyperbolic geometry, for each point P and a line l not containing P, there are infinitely many lines through P parallel to l.
How do I find profit in a labor market with 3 firms? Assuming an infinite number...
How do I find profit in a labor market with 3 firms? Assuming an infinite number of workers Just need the equations. got confused,
If I want to make 12 g of XeO2 from the elements, how much Xe do...
If I want to make 12 g of XeO2 from the elements, how much Xe do I need, in grams
how do I find the P-value for the hypothesis test
how do I find the P-value for the hypothesis test
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT